From: "jeremyevans0 (Jeremy Evans) via ruby-core" Date: 2026-11-04T04:44:07+00:00 Subject: [ruby-core:127327] [Ruby Bug#22462] For UnboundMethod, super_method.bind and bind.super_method should return an equal Method Issue #22462 has been updated by jeremyevans0 (Jeremy Evans). Subject changed from Method#== can return false for methods that should be considered equal to For UnboundMethod, super_method.bind and bind.super_method should return an equal Method shugo (Shugo Maeda) wrote in #note-3: > jeremyevans0 (Jeremy Evans) wrote in #note-2: > > Since the behavior for the two UnboundMethods is different, I think it makes sense that they are considered unequal. > > I agree that `ua` and `ub` in my example behave differently. > However, the current behavior of `UnboundMethod#==` was introduced by [Feature #18798], and it only checks whether the method definitions are the same, so `ua == ub` is still true. > > If we accept that `UnboundMethod#==` and `Method#==` are inconsistent in this respect, I think the change in the PR is fine. Note that my proposal does not change `Method#==` behavior. It only changes `super_method` behavior. The issue here is that the `super_method` and `bind` combination currently returns a `Method` that may be unequal if the order of `super_method` and `bind` is reversed, when it should return a `Method` that is equal regardless of the order. I'm changing the subject to reflect that. I split out the `bind` issue into a separate bug report (#22505), so that it can be considered separately. Note that the fix for this issue requires the fix for that issue. ---------------------------------------- Bug #22462: For UnboundMethod, super_method.bind and bind.super_method should return an equal Method https://bugs.ruby-lang.org/issues/22462#change-119757 * Author: jeremyevans0 (Jeremy Evans) * Status: Open * Backport: 3.3: UNKNOWN, 3.4: UNKNOWN, 4.0: UNKNOWN ---------------------------------------- When a `Method` is created using `UnboundMethod#bind` and `#super_method`, the order in which the `#bind` and `#super_method` were applied could result in `Method` objects that were considered unequal. I believe we should have the invariant: for any `UnboundMethod` `um` where `super_method` is not `nil` and `o` is a valid object to bind to `um`, the following code should be true: ```ruby um.bind(o).super_method == um.super_method.bind(o) ``` However, that didn't work correctly in some cases: ```ruby module M; def m = [:M, *super]; end module N; include M; end class C; def m = :C; end class SC < C include N prepend M def m = [:SC, *super] end o = SC.new um = SC.instance_method(:m).super_method.super_method # M#m below SC (included via N) um.bind(o).super_method == um.super_method.bind(o) # => false # should be true ``` There is a similar invariant for Method: for any `Method` `m` where `super_method` is not `nil`, the following code should be true: ```ruby m.unbind.super_method == m.super_method.unbind ``` This appears to already hold, as the existing refinement tests already checked for this behavior. I've submitted a PR to fix this issue: https://github.com/ruby/ruby/pull/19474 -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/