Issue #17130 has been updated by nagachika (Tomoyuki Chikanaga).

Backport changed from 2.5: UNKNOWN, 2.6: REQUIRED, 2.7: REQUIRED to 2.5: UNKNOWN, 2.6: REQUIRED, 2.7: DONE

ruby_2_7 c98aa2db60f43e839d7a82897c22b5ceecbed417 merged revision(s) c60aaed1856b2b6f90de0992c34771830019e021.

----------------------------------------
Bug #17130: Method#super_method is broken for aliased methods
https://bugs.ruby-lang.org/issues/17130#change-91009

* Author: jeremyevans0 (Jeremy Evans)
* Status: Closed
* Priority: Normal
* ruby -v: ruby 2.8.0dev (2020-08-25T21:09:31Z master a84a2e872f) [x86_64-openbsd6.7]
* Backport: 2.5: UNKNOWN, 2.6: REQUIRED, 2.7: DONE
----------------------------------------
Method#super_method currently does not work correctly for aliased methods.  Here's a simple example:

```ruby
class A
  def m1; p :A_m1 end
  def m2; p :A_m2 end
end
class B < A
  def m1; p :B_m1; super end
  alias m2 m1
end

B.new.m2
puts

m = B.new.method(:m2)
m.call

puts
m.super_method.call
```

Current Output:

```
:B_m1
:A_m1

:B_m1
:A_m1

:A_m2
```

You can see from this example that normal super lookup for B#m2 is A#m1, as B#m2 is an alias of B#m1 and super lookup follows the original method name, not the aliased name. However, the `super_method` call returns a Method instance for A#m2 instead of A#m1.

There is another issue with aliases and that is when the method being aliased is from another module or class.  In this case, super lookup needs to start at the super class of the defined class of the method being aliased.  See https://bugs.ruby-lang.org/issues/11189#note-3 for an example of that issue.

I have a fix that handles both of these cases that I'll submit shortly via a pull request.



-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>