[ruby-core:109487] [Ruby master Bug#18751] Regression on master for Method#== when comparing public with private method
From:
"Eregon (Benoit Daloze)" <noreply@...>
Date:
2022-08-15 14:24:11 UTC
List:
ruby-core #109487
Issue #18751 has been updated by Eregon (Benoit Daloze).
https://github.com/ruby/ruby/pull/6242 now makes resolved-through-zsuper methods equal for compatibility.
That means this issue is fixed by that PR too.
It's maybe a little bit strange that they are equal, but until we have a new method such as `{Method,UnboundMethod}#same_definition?(other)` this seems best for compatibility and generally honors the same behavior as previous versions which resolved ZSUPER methods in `Kernel#method`/`Module#instance_method` and now in `==`.
In fact the docs of Method#== do hint at definition equality:
```
Two method objects are equal if they are bound to the same object and
refer to the same method definition and the classes defining the methods
are the same class or module.
```
If ZSUPER methods are ever removed, this can all be simplified quite significantly.
----------------------------------------
Bug #18751: Regression on master for Method#== when comparing public with private method
https://bugs.ruby-lang.org/issues/18751#change-98655
* Author: Eregon (Benoit Daloze)
* Status: Open
* Priority: Normal
* ruby -v: ruby 3.2.0dev (2022-04-23T02:59:20Z master e142bea799) [x86_64-linux]
* Backport: 2.7: DONTNEED, 3.0: DONTNEED, 3.1: DONTNEED
----------------------------------------
This script repros:
```ruby
class C
class << self
alias_method :n, :new
private :new
end
end
p C.method(:n) == C.method(:new) # => true
puts
p C.method(:n) == Class.method(:new) # => false
p C.method(:n) == Class.method(:new).unbind.bind(C) # => true
puts
p C.method(:new) == Class.method(:new) # => false
p C.method(:new) == Class.method(:new).unbind.bind(C) # => true, BUT false on master
p C.method(:new) == Class.instance_method(:new).bind(C) # => true, BUT false on master
p [C.method(:new), Class.instance_method(:new).bind(C)] # => [#<Method: #<Class:C>(Class)#new(*)>, #<Method: #<Class:C>(Class)#new(*)>]
```
So this prints the expected results on 2.7.5, 3.0.3, 3.1.1 but not on master, which seems a regression.
Notably this breaks the pattern discussed in https://bugs.ruby-lang.org/issues/18729#note-5, and it means there is no way to find out if two methods share the same "definition/logic/def", which is a big limitation.
--
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:[email protected]?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>