Bug #22505
closedUnboundMethod#{bind,bind_call} results in incorrect behavior when method owner is at multiple places in ancestry
Description
If a method owner is at multiple places in the ancestry, UnboundMethod#bind can result in incorrect behavior, making an UnboundMethod from a superclass method bind to a method defined in a subclass:
module M
def m = [:m, *super]
end
class C
prepend M
def m = [:c]
end
class SC < C
prepend M
def m = [:sc, *super]
end
C.instance_method(:m).bind_call(SC.new)
# => [:m, :sc, :m, :c]
# Should be: [:m, :c]
This was originally discovered while working on #22462, but it's unrelated to method equality.
The incorrect behavior appears to have started in Ruby 2.3, as Ruby 2.0-2.2 give the expected result.
I've submitted a PR to fix this issue: https://github.com/ruby/ruby/pull/19695
Updated by matz (Yukihiro Matsumoto) 20 days ago
I agree this is a bug. An UnboundMethod taken from C should start method lookup from the position of C in the ancestry, so [:m, :c] is the expected result. Please go ahead with the fix.
Since the current behavior dates back to 2.3, I leave the backport decision to the branch maintainers.
Matz.
Updated by jeremyevans0 (Jeremy Evans) 20 days ago
- Status changed from Open to Closed