ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:99709] [Ruby master Bug#17130] Method#super_method is broken for aliased methods
@ 2020-08-26 17:36 merch-redmine
  2020-08-26 17:39 ` [ruby-core:99710] " merch-redmine
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: merch-redmine @ 2020-08-26 17:36 UTC (permalink / raw)
  To: ruby-core

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/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [ruby-core:99710] [Ruby master Bug#17130] Method#super_method is broken for aliased methods
  2020-08-26 17:36 [ruby-core:99709] [Ruby master Bug#17130] Method#super_method is broken for aliased methods merch-redmine
@ 2020-08-26 17:39 ` merch-redmine
  2021-03-20  4:57 ` [ruby-core:102943] " nagachika00
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: merch-redmine @ 2020-08-26 17:39 UTC (permalink / raw)
  To: ruby-core

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


Pull request submitted: https://github.com/ruby/ruby/pull/3458

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

* 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/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [ruby-core:102943] [Ruby master Bug#17130] Method#super_method is broken for aliased methods
  2020-08-26 17:36 [ruby-core:99709] [Ruby master Bug#17130] Method#super_method is broken for aliased methods merch-redmine
  2020-08-26 17:39 ` [ruby-core:99710] " merch-redmine
@ 2021-03-20  4:57 ` nagachika00
  2021-04-05  0:12 ` [ruby-core:103229] " usa
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: nagachika00 @ 2021-03-20  4:57 UTC (permalink / raw)
  To: ruby-core

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/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [ruby-core:103229] [Ruby master Bug#17130] Method#super_method is broken for aliased methods
  2020-08-26 17:36 [ruby-core:99709] [Ruby master Bug#17130] Method#super_method is broken for aliased methods merch-redmine
  2020-08-26 17:39 ` [ruby-core:99710] " merch-redmine
  2021-03-20  4:57 ` [ruby-core:102943] " nagachika00
@ 2021-04-05  0:12 ` usa
  2022-06-16 18:57 ` [ruby-core:108966] " Dan0042 (Daniel DeLorme)
  2022-06-17 13:52 ` [ruby-core:108986] " Eregon (Benoit Daloze)
  4 siblings, 0 replies; 6+ messages in thread
From: usa @ 2021-04-05  0:12 UTC (permalink / raw)
  To: ruby-core

Issue #17130 has been updated by usa (Usaku NAKAMURA).

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

backported into ruby_2_6 at r67933

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

* 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: DONE, 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/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [ruby-core:108966] [Ruby master Bug#17130] Method#super_method is broken for aliased methods
  2020-08-26 17:36 [ruby-core:99709] [Ruby master Bug#17130] Method#super_method is broken for aliased methods merch-redmine
                   ` (2 preceding siblings ...)
  2021-04-05  0:12 ` [ruby-core:103229] " usa
@ 2022-06-16 18:57 ` Dan0042 (Daniel DeLorme)
  2022-06-17 13:52 ` [ruby-core:108986] " Eregon (Benoit Daloze)
  4 siblings, 0 replies; 6+ messages in thread
From: Dan0042 (Daniel DeLorme) @ 2022-06-16 18:57 UTC (permalink / raw)
  To: ruby-core

Issue #17130 has been updated by Dan0042 (Daniel DeLorme).


It looks to me like super_method is still broken for aliased methods.

```
class A
  def foo; end
end
class B < A
  alias foo2 foo
end
p B.instance_method(:foo2).super_method #=> #<UnboundMethod: A#foo>
```

I believe that here `B.instance_method(:foo2).super_method` should be nil, as it was in ruby <= 2.5

I'm not sure if this is a different bug, or a side effect of the above patch.


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

* 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: DONE, 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/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [ruby-core:108986] [Ruby master Bug#17130] Method#super_method is broken for aliased methods
  2020-08-26 17:36 [ruby-core:99709] [Ruby master Bug#17130] Method#super_method is broken for aliased methods merch-redmine
                   ` (3 preceding siblings ...)
  2022-06-16 18:57 ` [ruby-core:108966] " Dan0042 (Daniel DeLorme)
@ 2022-06-17 13:52 ` Eregon (Benoit Daloze)
  4 siblings, 0 replies; 6+ messages in thread
From: Eregon (Benoit Daloze) @ 2022-06-17 13:52 UTC (permalink / raw)
  To: ruby-core

Issue #17130 has been updated by Eregon (Benoit Daloze).


@Dan0042 Indeed, here is another example, with an actual `super` call to prove what it calls:
```ruby
class P
  def foo; :P; end
end
class A < P
  def foo; super; end
end
class B < A
  alias foo2 foo
end

p B.new.foo2 # :P

p A.instance_method(:foo).super_method # #<UnboundMethod: P#foo() sup.rb:2>
p B.instance_method(:foo2).super_method # #<UnboundMethod: A#foo() sup.rb:5>
```
It should be `P#foo()` for both `.super_method`.
TruffleRuby already behaves correctly here:
```
:P
#<UnboundMethod: P#foo() sup.rb:2>
#<UnboundMethod: P#foo() sup.rb:2>
```

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

* 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: DONE, 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/

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-06-17 13:52 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-26 17:36 [ruby-core:99709] [Ruby master Bug#17130] Method#super_method is broken for aliased methods merch-redmine
2020-08-26 17:39 ` [ruby-core:99710] " 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)

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).