ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: merch-redmine@jeremyevans.net
To: ruby-core@ruby-lang.org
Subject: [ruby-core:99709] [Ruby master Bug#17130] Method#super_method is broken for aliased methods
Date: Wed, 26 Aug 2020 17:36:41 +0000 (UTC)	[thread overview]
Message-ID: <redmine.issue-17130.20200826173640.1604@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-17130.20200826173640.1604@ruby-lang.org

Issue #17130 has been reported by jeremyevans0 (Jeremy Evans).

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

* Author: jeremyevans0 (Jeremy Evans)
* Status: Open
* 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: UNKNOWN, 2.7: UNKNOWN
----------------------------------------
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/

       reply	other threads:[~2020-08-26 17:36 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-26 17:36 merch-redmine [this message]
2020-08-26 17:39 ` [ruby-core:99710] [Ruby master Bug#17130] Method#super_method is broken for aliased methods merch-redmine
2021-03-20  4:57 ` [ruby-core:102943] " nagachika00
2021-04-05  0:12 ` [ruby-core:103229] " usa
2022-06-16 18:57 ` [ruby-core:108966] " Dan0042 (Daniel DeLorme)
2022-06-17 13:52 ` [ruby-core:108986] " Eregon (Benoit Daloze)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.ruby-lang.org/en/community/mailing-lists/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=redmine.issue-17130.20200826173640.1604@ruby-lang.org \
    --to=ruby-core@ruby-lang.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).