[#109095] [Ruby master Misc#18888] Migrate ruby-lang.org mail services to Google Domains and Google Workspace — "shugo (Shugo Maeda)" <noreply@...>
Issue #18888 has been reported by shugo (Shugo Maeda).
16 messages
2022/06/30
[ruby-core:108828] [Ruby master Bug#18729] Method#owner and UnboundMethod#owner are incorrect after using Module#public/protected/private
From:
"mame (Yusuke Endoh)" <noreply@...>
Date:
2022-06-09 09:35:57 UTC
List:
ruby-core #108828
Issue #18729 has been updated by mame (Yusuke Endoh).
Status changed from Open to Rejected
mame (Yusuke Endoh) wrote in #note-6:
> @ko1 proposed the following, and @matz approved this at the dev meeting.
>
> ```
> class A
> private def foo
> end
> end
>
> class B < A
> public :foo
> end
>
> m = B.instance_method(:foo)
>
> p m.owner #=> B (changed)
> p m.public? #=> true (changed)
> p m.source_location #=> location of `def foo` in class A (no change)
> p m.super_method #=> UnboundMethod: A#foo() ...> (changed)
> p B.instance_methods(false) #=> [:foo] (no change)
> ```
@matz changed his mind: https://bugs.ruby-lang.org/issues/18435#note-11
Now he thinks the behavior of Ruby 3.1 is good, so everything above should be "no change". `B.instance_methods(false)` should include `:foo`, but `B.instance_method(:foo)` should return a method object that wraps A's `foo` method. So the original problem in this ticket ("Method#owner and UnboundMethod#owner are incorrect") is considered a spec.
----------------------------------------
Bug #18729: Method#owner and UnboundMethod#owner are incorrect after using Module#public/protected/private
https://bugs.ruby-lang.org/issues/18729#change-97904
* 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:
```
[#<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/
Unsubscribe: <mailto:[email protected]?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>