Skip to content

Add specs for Method#original_name and #inspect with Kernel methods#1356

Open
sampokuokkanen wants to merge 1 commit into
ruby:masterfrom
sampokuokkanen:original-name-and-inspect
Open

Add specs for Method#original_name and #inspect with Kernel methods#1356
sampokuokkanen wants to merge 1 commit into
ruby:masterfrom
sampokuokkanen:original-name-and-inspect

Conversation

@sampokuokkanen
Copy link
Copy Markdown
Contributor

Adds specs for Method#original_name and #inspect when define_method or alias is used with Kernel#is_a? / Kernel#kind_of? methods that can share an internal implementation in some Ruby implementations. Existing specs didn't catch when introspection leaked the shared internal name.

Also documents inspect's behavior on aliased methods, which wasn't previously covered.

Continuing the work started in #1353 and adding specs that fail at least on JRuby. (the specs added in that PR now pass on JRuby master though!)

Adds specs for Method#original_name and #inspect when define_method
or alias is used with Kernel#is_a? / Kernel#kind_of? methods that
can share an internal implementation in some Ruby implementations.
Existing specs didn't catch when introspection leaked the shared
internal name.
sampokuokkanen added a commit to sampokuokkanen/jruby that referenced this pull request May 12, 2026
Fix Method#original_name and #inspect when two methods share a wrapper (like is_a?/kind_of?)

Introduce sourceName on DynamicMethod to preserve a method's source name when methods share a single underlying wrapper. Set it in RubyModule when binding, walk the alias chain in AliasMethod#getOldName to reach it, and consult it from Method#original_name and #inspect so both report the correct source name instead of whichever name happened to live on the wrapper.

Covered by new specs in ruby/spec#1356 (ruby/spec#1356).
sampokuokkanen added a commit to sampokuokkanen/jruby that referenced this pull request May 12, 2026
Fix Method#original_name and #inspect when two methods share a wrapper (like is_a?/kind_of?)

Introduce sourceName on DynamicMethod to preserve a method's source name when methods share a single underlying wrapper. Set it in RubyModule when binding, walk the alias chain in AliasMethod#getOldName to reach it, and consult it from Method#original_name and #inspect so both report the correct source name instead of whichever name happened to live on the wrapper.

Covered by new specs in ruby/spec#1356 (ruby/spec#1356).
Copy link
Copy Markdown
Contributor

@headius headius left a comment

Choose a reason for hiding this comment

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

This looks fine to me and fills a gap in specs.

Copy link
Copy Markdown
Contributor

@headius headius left a comment

Choose a reason for hiding this comment

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

Actually, two small changes here would clean this up and we can merge.

it "shows the original name in parentheses for an aliased method" do
klass = Class.new do
def original_method; end
alias_method :renamed_is_a?, :original_method
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Seems like "is_a?" is irrelevant and confusing here.

it "shows the original name in parentheses for an aliased method" do
klass = Class.new do
def original_method; end
alias_method :renamed_is_a?, :original_method
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Also here: is_a? is not relevant for this particular case, probably copied from other cases that actually do alias is_a?.

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