Skip to content

UnboundMethod#bind should use virtual include class for module methods#7551

Merged
headius merged 2 commits intojruby:masterfrom
headius:unboundmethod_bind_to_includeclass
Jan 5, 2023
Merged

UnboundMethod#bind should use virtual include class for module methods#7551
headius merged 2 commits intojruby:masterfrom
headius:unboundmethod_bind_to_includeclass

Conversation

@headius
Copy link
Member

@headius headius commented Jan 4, 2023

When binding a module method to a receiver that does not already include that module, the bound method (and the call entry used for bind_call) should act as though that method were included into a virtual module below the receiver class. This allows bound module methods to super into the receiver class.

This behavior was introduced when bind_call was added, but affects both bind and bind_call and does not appear to have been documented or tested. It went on to be used in Sorbet, which resulted in a bug report on JRuby in sorbet/sorbet#1188.

This should fix that issue and the JRuby bug reported recently as #7548.

This issue does not affect JRuby 9.3 because bind_call was introduced in 2.7.

Additional change for bind_call to allow supering out of rebound
methods. See jruby#7555.

Fixes jruby#7548 for 9.4.
UnboundMethod#bind and #bind_call should bind to a virtual include
class below the receiver class when the method is from a module
that does not exist in the receiver's hierarchy. This allows the
rebound method to call `super` to delegate to the receiver's
class and ancestors.

This behavioral change was introduced when `bind_call` was added
but I have not found any tests, specs or documentation about the
behavior change.

See jruby#7548 and sorbet/sorbet#1188.
@headius headius force-pushed the unboundmethod_bind_to_includeclass branch from 7c9d63e to 867aa9f Compare January 5, 2023 22:09
@headius headius merged commit 2fef18a into jruby:master Jan 5, 2023
@headius headius deleted the unboundmethod_bind_to_includeclass branch January 5, 2023 22:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants