ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:108235] [Ruby master Bug#18729] Method#owner and UnboundMethod#owner are incorrect after using Module#public/protected/private
@ 2022-04-14 14:38 Eregon (Benoit Daloze)
  2022-04-14 14:44 ` [ruby-core:108236] " Eregon (Benoit Daloze)
                   ` (32 more replies)
  0 siblings, 33 replies; 34+ messages in thread
From: Eregon (Benoit Daloze) @ 2022-04-14 14:38 UTC (permalink / raw)
  To: ruby-core

Issue #18729 has been reported by Eregon (Benoit Daloze).

----------------------------------------
Bug #18729: Method#owner and UnboundMethod#owner are incorrect after using Module#public/protected/private
https://bugs.ruby-lang.org/issues/18729

* 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:
```
[#<UnboundMethod: B(A)#foo() owner.rb:2>, A, [], [:foo]]
[#<UnboundMethod: B(A)#foo() owner.rb:2>, 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:

```
[#<UnboundMethod: B(A)#foo() owner.rb:2>, A, [], [:foo]]
[#<UnboundMethod: B#foo() owner.rb:2>, B, [:foo], [:foo]]
```



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 34+ messages in thread

end of thread, other threads:[~2022-09-28 19:08 UTC | newest]

Thread overview: 34+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-14 14:38 [ruby-core:108235] [Ruby master Bug#18729] Method#owner and UnboundMethod#owner are incorrect after using Module#public/protected/private Eregon (Benoit Daloze)
2022-04-14 14:44 ` [ruby-core:108236] " Eregon (Benoit Daloze)
2022-04-14 23:00 ` [ruby-core:108244] " jeremyevans0 (Jeremy Evans)
2022-04-15 10:37 ` [ruby-core:108260] " Eregon (Benoit Daloze)
2022-04-15 14:51 ` [ruby-core:108265] " jeremyevans0 (Jeremy Evans)
2022-04-19 18:30 ` [ruby-core:108297] " Eregon (Benoit Daloze)
2022-04-22  2:36 ` [ruby-core:108363] " mame (Yusuke Endoh)
2022-04-22  9:56 ` [ruby-core:108369] " Eregon (Benoit Daloze)
2022-04-22 16:11 ` [ruby-core:108374] " jeremyevans0 (Jeremy Evans)
2022-04-23 11:34 ` [ruby-core:108377] " Eregon (Benoit Daloze)
2022-04-23 13:09 ` [ruby-core:108382] " Eregon (Benoit Daloze)
2022-04-25 19:45 ` [ruby-core:108401] " jeremyevans0 (Jeremy Evans)
2022-04-27 18:22 ` [ruby-core:108422] " Eregon (Benoit Daloze)
2022-04-27 19:00 ` [ruby-core:108423] " jeremyevans0 (Jeremy Evans)
2022-05-17 10:09 ` [ruby-core:108582] " Eregon (Benoit Daloze)
2022-06-09  9:35 ` [ruby-core:108828] " mame (Yusuke Endoh)
2022-06-09 10:33 ` [ruby-core:108834] " Eregon (Benoit Daloze)
2022-06-16  9:11 ` [ruby-core:108956] " matz (Yukihiro Matsumoto)
2022-06-16  9:16 ` [ruby-core:108957] " matz (Yukihiro Matsumoto)
2022-06-16 10:06 ` [ruby-core:108958] " Eregon (Benoit Daloze)
2022-06-16 10:09 ` [ruby-core:108959] " Eregon (Benoit Daloze)
2022-06-16 14:15 ` [ruby-core:108960] " matz (Yukihiro Matsumoto)
2022-06-16 14:21 ` [ruby-core:108961] " matz (Yukihiro Matsumoto)
2022-06-16 16:56 ` [ruby-core:108962] " Eregon (Benoit Daloze)
2022-08-15 11:01 ` [ruby-core:109480] " Eregon (Benoit Daloze)
2022-08-15 11:03 ` [ruby-core:109481] " Eregon (Benoit Daloze)
2022-08-15 13:08 ` [ruby-core:109485] " Eregon (Benoit Daloze)
2022-08-18  9:23 ` [ruby-core:109537] " Eregon (Benoit Daloze)
2022-08-18  9:35 ` [ruby-core:109541] " Eregon (Benoit Daloze)
2022-08-18 11:40 ` [ruby-core:109548] " Eregon (Benoit Daloze)
2022-09-22  3:46 ` [ruby-core:109987] " matz (Yukihiro Matsumoto)
2022-09-28 16:26 ` [ruby-core:110132] " Eregon (Benoit Daloze)
2022-09-28 17:26 ` [ruby-core:110134] " Eregon (Benoit Daloze)
2022-09-28 19:08 ` [ruby-core:110138] " Eregon (Benoit Daloze)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).