Skip to content

Fix Method/UnboundMethod#original_name deep alias chains#9420

Merged
headius merged 1 commit into
jruby:masterfrom
sampokuokkanen:recursive-alias-method
May 8, 2026
Merged

Fix Method/UnboundMethod#original_name deep alias chains#9420
headius merged 1 commit into
jruby:masterfrom
sampokuokkanen:recursive-alias-method

Conversation

@sampokuokkanen

@sampokuokkanen sampokuokkanen commented May 7, 2026

Copy link
Copy Markdown
Contributor

Use getRealMethod() instead of entry.method, which only unwrapped one level. Fixes Method#/UnboundMethod#original_name for chains 3+ deep. Also drops the stale RubyMethod#original_name override left over from when the implementation moved to AbstractRubyMethod.

Fixes the first part of #9257. (except for the usage of is_a?)

I added tests here: ruby/spec#1353 and here: ruby/spec#1354.

With this the sample from the example in the issue becomes the same as MRI. I'm not sure about the breaking up of kind_of? and is_a? to different Java methods, but this seems to be the way things are done for methods like map/collect.

Sample code:

class Test
  def hello = "hello"
  alias hallo hello
  alias moi hallo
  alias tere moi
  alias hej tere
end

Test.new.method(:hej).original_name
=> :hello # MRI
=> :moi # JRuby 10.1.0.0
=> :hello # JRuby on this branch

@headius headius left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's put is_a? back the way it was. The rest is good. 👍

Comment thread core/src/main/java/org/jruby/RubyKernel.java
@sampokuokkanen
sampokuokkanen force-pushed the recursive-alias-method branch from 7bc879a to d4b2b47 Compare May 8, 2026 01:52
Use getRealMethod() instead of entry.method, which only unwrapped
one level. Fixes Method#/UnboundMethod#original_name for chains 3+
deep. Also drops the stale RubyMethod#original_name override left
over from when the implementation moved to AbstractRubyMethod in 2017.
@sampokuokkanen
sampokuokkanen force-pushed the recursive-alias-method branch from d4b2b47 to 05b9ce2 Compare May 8, 2026 03:10
@sampokuokkanen
sampokuokkanen requested a review from headius May 8, 2026 03:10
@sampokuokkanen

Copy link
Copy Markdown
Contributor Author

Thank you for the review. Removed the change from RubyKernel.java.

@headius
headius merged commit a11ec09 into jruby:master May 8, 2026
108 of 109 checks passed
@headius headius added this to the JRuby 10.1.1.0 milestone May 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants