Project

General

Profile

Actions

Bug #22505

closed

UnboundMethod#{bind,bind_call} results in incorrect behavior when method owner is at multiple places in ancestry

Bug #22505: UnboundMethod#{bind,bind_call} results in incorrect behavior when method owner is at multiple places in ancestry

Added by jeremyevans0 (Jeremy Evans) 29 days ago. Updated 20 days ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:127326]

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 Actions #1 [ruby-core:127448]

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 Actions #2 [ruby-core:127458]

  • Status changed from Open to Closed
Actions

Also available in: PDF Atom