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

#original_name overwrite on second alias_mathod #5800

Closed
lloeki opened this issue Jul 25, 2019 · 4 comments
Closed

#original_name overwrite on second alias_mathod #5800

lloeki opened this issue Jul 25, 2019 · 4 comments
Milestone

Comments

@lloeki
Copy link

@lloeki lloeki commented Jul 25, 2019

Environment

$ jruby -v
jruby 9.2.7.0 (2.5.3) 2019-04-09 8a269e3 Java HotSpot(TM) 64-Bit Server VM 25.201-b09 on 1.8.0_201-b09 +jit [darwin-x86_64]
$ uname -a
Darwin Hamilton.local 19.0.0 Darwin Kernel Version 19.0.0: Thu Jul 11 18:37:36 PDT 2019; root:xnu-6153.0.59.141.4~1/RELEASE_X86_64 x86_64

Expected Behavior

Ruby 2.6.3: original_name is unchanged after second alias_method.

$ ruby -v
ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-darwin19]
$ pry
[1] pry(main)> class Foo; def foo; end; alias_method :bar, :foo; alias_method :baz, :bar; end
=> Foo
[2] pry(main)> Foo.instance_method(:foo).original_name
=> :foo
[3] pry(main)> Foo.instance_method(:bar).original_name
=> :foo
[4] pry(main)> Foo.instance_method(:baz).original_name
=> :foo
[5] pry(main)> Foo.new.method(:foo).original_name
=> :foo
[6] pry(main)> Foo.new.method(:bar).original_name
=> :foo
[7] pry(main)> Foo.new.method(:baz).original_name
=> :foo

Actual Behavior

JRuby 9.1.17.0: NoMethodError for one, and overwrites original_name on second alias_method for the other.

$ ruby -v
jruby 9.1.17.0 (2.3.3) 2018-04-20 d8b1ff9 Java HotSpot(TM) 64-Bit Server VM 25.201-b09 on 1.8.0_201-b09 +jit [darwin-x86_64]
$ pry
[1] pry(main)> class Foo; def foo; end; alias_method :bar, :foo; alias_method :baz, :bar; end
=> Foo
[2] pry(main)> Foo.instance_method(:foo).original_name
NoMethodError: undefined method `original_name' for #<UnboundMethod: Foo#foo>
from (pry):2:in `<eval>'
[3] pry(main)> Foo.new.method(:foo).original_name
=> :foo
[4] pry(main)> Foo.new.method(:bar).original_name
=> :foo
[5] pry(main)> Foo.new.method(:baz).original_name
=> :bar

JRuby 9.2.7.0: overwrites original_name on second alias_method.

$ ruby -v
jruby 9.2.7.0 (2.5.3) 2019-04-09 8a269e3 Java HotSpot(TM) 64-Bit Server VM 25.201-b09 on 1.8.0_201-b09 +jit [darwin-x86_64]
$ pry
[1] pry(main)> class Foo; def foo; end; alias_method :bar, :foo; alias_method :baz, :bar; end
=> Foo
[2] pry(main)> Foo.instance_method(:foo).original_name
=> :foo
[3] pry(main)> Foo.instance_method(:bar).original_name
=> :foo
[4] pry(main)> Foo.instance_method(:baz).original_name
=> :bar
[5] pry(main)> Foo.new.method(:foo).original_name
=> :foo
[6] pry(main)> Foo.new.method(:bar).original_name
=> :foo
[7] pry(main)> Foo.new.method(:baz).original_name
=> :bar
@lloeki lloeki changed the title Method#original_name and UnboundMethod#original_name overwrite the #original_name overwrite on second alias_mathod Jul 27, 2019
@headius headius closed this in b786d69 Jul 29, 2019
headius added a commit that referenced this issue Jul 29, 2019
@headius
Copy link
Member

@headius headius commented Jul 29, 2019

This is fixed on master, but I did not see any specs testing this behavior. In fact, I found no specs at all for Method#original_name or UnboundMethod#original_name. Perhaps you could write some for https://github.com/jruby/jruby/tree/master/spec/ruby/core/unboundmethod and https://github.com/jruby/jruby/tree/master/spec/ruby/core/method and submit a PR?

Thanks for the report!

Loading

headius added a commit that referenced this issue Jul 29, 2019
Digging out the original method appears to have been incorrect.
Instead this modifies AliasMethod to dig out the old name.
@lloeki
Copy link
Author

@lloeki lloeki commented Jul 29, 2019

I found no specs at all for Method#original_name or UnboundMethod#original_name. Perhaps you could write some and submit a PR?

Good find, I can do that.

Loading

@lloeki
Copy link
Author

@lloeki lloeki commented Jul 29, 2019

PR here: ruby/spec#675

Loading

@lloeki
Copy link
Author

@lloeki lloeki commented Jul 29, 2019

@headius, will this fix be included on an upcoming 9.2 release?

Also, will it be backported on 9.1, and the missing UnboundMethod#original_method added?

Anyway, thanks a lot!

Loading

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

Successfully merging a pull request may close this issue.

None yet
3 participants