Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MRI 2.2.2 / JRuby 9.0.4.0 difference given explicit self receiver for private method call. #3573

Closed
arronmabrey opened this issue Dec 30, 2015 · 3 comments
Labels
Milestone

Comments

@arronmabrey
Copy link

Given the following example:
class Foo
  def a
    self.b += 1
  end

  private

  def b=(v)
    @b = v
  end

  def b
    @b || 10
  end
end

Foo.new.a == 11
Under MRI ruby 2.2.2p95:
  • This works as expected and outputs true
Under JRuby 9.0.4.0 (2.2.2):
  • This raises an exception NoMethodError: private method b' called for #Foo:0x543788f3`

I'm not sure if this is a know issue or not, I'm very new to JRuby and this was a surprise I stumbled across.

@enebo enebo added the ir label Dec 31, 2015
@enebo enebo added this to the JRuby 9.0.5.0 milestone Dec 31, 2015
@enebo
Copy link
Member

enebo commented Dec 31, 2015

Just an oversight. We try and be compatible as we can but some times things get missed. In this case, MRI is being inconsistent but I sort of remember this change (and I am surprised we did not impl it). Consider a version of a:

def a
  self.b
end

Boom private method. For the sake of += it reasons you are using self so it has access to call both b and b=. I am ok with this but then why does my self.b fail? In any case, we will fix it...

@enebo
Copy link
Member

enebo commented Dec 31, 2015

Another thing which bugs me about this behavior and I am only documenting this for fun...It is great this is static analysis feature of the language because:

def a
  o = self
  o.b += 1
end

Will not work. It still bugs me because we are calling be against self. If static form of self is ok then why not dynamic one. Perhaps the obvious answer is it would penalize all callsites since you would need to check against self receiver per call...

@enebo
Copy link
Member

enebo commented Dec 31, 2015

test_assign_private_self in MRI tests test part of the cases I fixed but I had to open #3575 because there is an unrelated set of failures in that same test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants