[ruby-core:127326] [Ruby Bug#22505] UnboundMethod#{bind,bind_call} results in incorrect behavior when method owner is at multiple places in ancestry
Issue #22505 has been reported by jeremyevans0 (Jeremy Evans). ---------------------------------------- Bug #22505: UnboundMethod#{bind,bind_call} results in incorrect behavior when method owner is at multiple places in ancestry https://bugs.ruby-lang.org/issues/22505 * Author: jeremyevans0 (Jeremy Evans) * Status: Open * Backport: 3.3: UNKNOWN, 3.4: UNKNOWN, 4.0: UNKNOWN ---------------------------------------- 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: ```ruby 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 -- https://bugs.ruby-lang.org/
Issue #22505 has been updated by matz (Yukihiro Matsumoto). 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. ---------------------------------------- Bug #22505: UnboundMethod#{bind,bind_call} results in incorrect behavior when method owner is at multiple places in ancestry https://bugs.ruby-lang.org/issues/22505#change-119900 * Author: jeremyevans0 (Jeremy Evans) * Status: Open * Backport: 3.3: UNKNOWN, 3.4: UNKNOWN, 4.0: UNKNOWN ---------------------------------------- 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: ```ruby 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 -- https://bugs.ruby-lang.org/
Issue #22505 has been updated by jeremyevans0 (Jeremy Evans). Status changed from Open to Closed Fixed by commit:5b62da01099e458a346b2771b5d726a8a8ea8c0d ---------------------------------------- Bug #22505: UnboundMethod#{bind,bind_call} results in incorrect behavior when method owner is at multiple places in ancestry https://bugs.ruby-lang.org/issues/22505#change-119919 * Author: jeremyevans0 (Jeremy Evans) * Status: Closed * Backport: 3.3: UNKNOWN, 3.4: UNKNOWN, 4.0: UNKNOWN ---------------------------------------- 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: ```ruby 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 -- https://bugs.ruby-lang.org/
participants (2)
-
jeremyevans0 (Jeremy Evans) -
matz (Yukihiro Matsumoto)