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

Method#owner for alias methods doesn't include prepended modules, breaking equality #5080

aburgel opened this issue Mar 4, 2018 · 2 comments


Copy link

@aburgel aburgel commented Mar 4, 2018


I've tested this on and the latest master.

# bin/jruby --version
jruby (2.4.1) 2018-03-04 b75044c Java HotSpot(TM) 64-Bit Server VM 25.31-b07 on 1.8.0_31-b13 +jit [darwin-x86_64]
# bin/jruby --version
jruby (2.3.3) 2018-03-04 8f3f95a Java HotSpot(TM) 64-Bit Server VM 25.31-b07 on 1.8.0_31-b13 +jit [darwin-x86_64]

Expected Behavior

Given the following code, I'd expect a method's owner to be equal to the class where the method is defined.

class FakeClass
  prepender =
  prepend prepender

  def fake_method
  alias_method :other_fake_method, :fake_method

Both of these lines should return true:

FakeClass.instance_method(:fake_method).owner == FakeClass
FakeClass.instance_method(:other_fake_method).owner == FakeClass

Actual Behavior

The second line returns false:

irb(main):014:0> FakeClass.instance_method(:fake_method).owner == FakeClass
=> true

irb(main):015:0> FakeClass.instance_method(:other_fake_method).owner == FakeClass
=> false

I think it's because the owner of the aliased method doesn't include the prepended module:

irb(main):012:0* FakeClass.instance_method(:fake_method).owner.ancestors
=> [#<Module:0x32464a14>, FakeClass, Object, Kernel, BasicObject]

irb(main):013:0> FakeClass.instance_method(:other_fake_method).owner.ancestors
=> [FakeClass, Object, Kernel, BasicObject]

I've also tested this on MRI 2.3.1 and 2.4.3 and they behave as expected.

Copy link

@headius headius commented Mar 15, 2018

Ahh, interesting. There have been fixes to Method ownership, but perhaps prepended cases are still not picking up the proper base. I'll have a look.

@headius headius added this to the JRuby milestone Mar 15, 2018
@headius headius closed this in 2a1313c Mar 15, 2018
Copy link

@headius headius commented Mar 15, 2018

Good find! Can you submit this as a spec to Maybe expand it to cover other cases not already tested?

Let us know if you find any related issues!

aburgel added a commit to aburgel/spec that referenced this issue Mar 16, 2018
…ect owner

We discovered an issue in jruby where a method created via `alias_method` on a class with a prepended module had an owner that was different from the class on which it was defined.

The jruby folks suggested adding a spec here to cover this case. See jruby/jruby#5080.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants