diff options
author | Benoit Daloze <eregontp@gmail.com> | 2022-08-15 16:01:33 +0200 |
---|---|---|
committer | Benoit Daloze <eregontp@gmail.com> | 2022-08-20 13:44:00 +0200 |
commit | 209631a45f9682dedf718f4b4a140efe7d21a6fc (patch) | |
tree | 4fe16e820f45b927f6d5b11637d9dff79ab53e4a /spec/ruby/core/unboundmethod | |
parent | 8212aab81a77a2a91fb7c1681b4968171193b48f (diff) |
Consider resolved-through-zsuper methods equal for compatibility
* Fixes https://bugs.ruby-lang.org/issues/18751
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/6242
Diffstat (limited to 'spec/ruby/core/unboundmethod')
-rw-r--r-- | spec/ruby/core/unboundmethod/equal_value_spec.rb | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/spec/ruby/core/unboundmethod/equal_value_spec.rb b/spec/ruby/core/unboundmethod/equal_value_spec.rb index 6242b04884..b21677687e 100644 --- a/spec/ruby/core/unboundmethod/equal_value_spec.rb +++ b/spec/ruby/core/unboundmethod/equal_value_spec.rb @@ -98,4 +98,41 @@ describe "UnboundMethod#==" do (@discard_1 == UnboundMethodSpecs::Methods.instance_method(:discard_1)).should == false end + + it "considers methods through aliasing equal" do + c = Class.new do + class << self + alias_method :n, :new + end + end + + c.method(:new).should == c.method(:n) + c.method(:n).should == Class.instance_method(:new).bind(c) + end + + # On CRuby < 3.2, the 2 specs below pass due to method/instance_method skipping zsuper methods. + # We are interested in the general pattern working, i.e. the combination of method/instance_method + # and #== exposes the wanted behavior. + it "considers methods through visibility change equal" do + c = Class.new do + class << self + private :new + end + end + + c.method(:new).should == Class.instance_method(:new).bind(c) + end + + it "considers methods through aliasing and visibility change equal" do + c = Class.new do + class << self + alias_method :n, :new + private :new + end + end + + c.method(:new).should == c.method(:n) + c.method(:n).should == Class.instance_method(:new).bind(c) + c.method(:new).should == Class.instance_method(:new).bind(c) + end end |