From: "jeremyevans0 (Jeremy Evans)" Date: 2022-04-27T19:00:05+00:00 Subject: [ruby-core:108423] [Ruby master Bug#18729] Method#owner and UnboundMethod#owner are incorrect after using Module#public/protected/private Issue #18729 has been updated by jeremyevans0 (Jeremy Evans). Eregon (Benoit Daloze) wrote in #note-13: > @jeremyevans0 Do you agree `Method#super_method` should show the method called by `super` if there is `super` in that method, when it's possible to know? > (I think it's always possible for a method defined on a class, but not for a method defined on a module especially if the module is included multiple times in the ancestors) I think you either treat a ZSUPER method like a method in the current class (this issue), or you treat it as a method in the ancestor (Ruby 3.1 and below behavior). If you treat a ZSUPER method like a method in the current class, then `super_method` should be treated as if the ZSUPER method was defined in the current class (and not a ZSUPER method), in which case it gives the method defined in the ancestor. > `public` is not equivalent to redeclaring it like you show with `def foo; super; end`, because B#foo would call A#foo with redeclaring, but with only `public :foo in B` A#foo is *not* called for `B.new.foo`. True, that is a difference. I believe in this case that `super_method` will still give you the correct answer, the Method object for `A#foo` before `A#foo` was redeclared. If that is the case, I don't the proposed behavior as a problem. ---------------------------------------- Bug #18729: Method#owner and UnboundMethod#owner are incorrect after using Module#public/protected/private https://bugs.ruby-lang.org/issues/18729#change-97459 * Author: Eregon (Benoit Daloze) * Status: Open * Priority: Normal * ruby -v: ruby 3.1.1p18 (2022-02-18 revision 53f5fc4236) [x86_64-linux] * Backport: 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN ---------------------------------------- The #owner should be "the class or module that defines the method". Or in other words, the owner is the module which has the method table containing that method. This generally holds, and it seems very likely this assumption is relied upon (e.g., when decorating a method, undefining it, etc). But the returned value on CRuby is incorrect for this case: ```ruby class A protected def foo :A end end class B < A p [instance_method(:foo), instance_method(:foo).owner, instance_methods(false), A.instance_methods(false)] public :foo p [instance_method(:foo), instance_method(:foo).owner, instance_methods(false), A.instance_methods(false)] end ``` It gives: ``` [#, A, [], [:foo]] [#, A, [:foo], [:foo]] ``` So `UnboundMethod#owner` says `A`, but clearly there is a :foo method entry in B created by `public :foo`, and that is shown through `B.instance_methods(false)`. The expected output is: ``` [#, A, [], [:foo]] [#, B, [:foo], [:foo]] ``` -- https://bugs.ruby-lang.org/ Unsubscribe: