From: "Eregon (Benoit Daloze)" Date: 2022-06-16T10:06:25+00:00 Subject: [ruby-core:108958] [Ruby master Bug#18729] Method#owner and UnboundMethod#owner are incorrect after using Module#public/protected/private Issue #18729 has been updated by Eregon (Benoit Daloze). @matz Right, this is the something you intended initially for public/protected/private. I think most Rubyists do not understand this detail and the real practical issue is the inconsistencies shown by Method/UnboundMethod objects (e.g., not possible to have a correct/consistent Method object of a zsuper method currently). One way to address that is https://bugs.ruby-lang.org/issues/18751#note-11 (no longer hide ZSUPER method entry from users). That will also fix this issue, and the owner will be as it is expected. Can we do that, as it was agreed in a previous meeting? Then what public/protected/private do is mostly an implementation detail, and probably no or very little real code relies on `public` being symbolic or copying. ---------------------------------------- Bug #18729: Method#owner and UnboundMethod#owner are incorrect after using Module#public/protected/private https://bugs.ruby-lang.org/issues/18729#change-98054 * Author: Eregon (Benoit Daloze) * Status: Rejected * 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: