* [ruby-core:91570] [Ruby trunk Bug#15608] What should be the correct output for Method#inspect with singleton methods?
[not found] <redmine.issue-15608.20190215164233@ruby-lang.org>
@ 2019-02-15 16:42 ` eregontp
2019-02-15 16:50 ` [ruby-core:91571] " eregontp
` (4 subsequent siblings)
5 siblings, 0 replies; 6+ messages in thread
From: eregontp @ 2019-02-15 16:42 UTC (permalink / raw)
To: ruby-core
Issue #15608 has been reported by Eregon (Benoit Daloze).
----------------------------------------
Bug #15608: What should be the correct output for Method#inspect with singleton methods?
https://bugs.ruby-lang.org/issues/15608
* Author: Eregon (Benoit Daloze)
* Status: Open
* Priority: Normal
* Assignee:
* Target version:
* ruby -v: ruby 2.6.1p33 (2019-01-30 revision 66950) [x86_64-linux]
* Backport: 2.4: UNKNOWN, 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
bug.rb:
```ruby
class C
def foo
end
end
obj = C.new
class << obj
alias bar foo
end
p obj.method(:foo).owner
p obj.method(:foo)
raise unless obj.method(:foo).owner == C
p obj.method(:bar).owner
p obj.method(:bar)
raise unless obj.method(:bar).owner == obj.singleton_class
```
```
$ chruby 2.0.0
$ ruby -v bug.rb
ruby 2.0.0p648 (2015-12-16) [x86_64-linux]
C
#<Method: C#foo>
#<Class:#<C:0x0055b39fcd2c30>>
#<Method: C(C)#foo>
$ chruby 2.3.8
$ ruby -v bug.rb
ruby 2.3.8p459 (2018-10-18 revision 65136) [x86_64-linux]
C
#<Method: C#foo>
#<Class:#<C:0x000055668ebef268>>
#<Method: #<C:0x000055668ebef268>.bar(foo)>
$ chruby 2.4.5
$ ruby -v bug.rb
ruby 2.4.5p335 (2018-10-18 revision 65137) [x86_64-linux]
C
#<Method: #<C:0x000055fdc99dc908>.foo>
#<Class:#<C:0x000055fdc99dc908>>
#<Method: #<C:0x000055fdc99dc908>.bar(foo)>
Same for 2.5.3 and 2.6.1
```
I think Method#inspect should show on which Module the method is defined, and only singleton methods should be shown as `receiver.method`, so:
```
C
#<Method: C#foo>
#<Class:#<C:0x000055668ebef268>>
#<Method: #<C:0x000055668ebef268>.bar(foo)>
```
Which only Ruby 2.3 does interestingly.
---
What's the meaning of the `C1(C2)` notation?
It seems to show `"#{receiver.class}(#{owner})` or `"#{receiver.singleton_class if receiver has a sclass}(#{owner})` depending on the version:
```ruby
class D < C
end
d = D.new
p d.method(:foo)
d.singleton_class
p d.method(:foo)
```
```
2.0-2.3:
#<Method: D(C)#foo>
#<Method: D(C)#foo>
2.4-2.6:
#<Method: D(C)#foo>
#<Method: #<D:0x000055c12b45e218>.foo>
```
I think the Ruby 2.4+ it's confusing and incorrect here, the object shouldn't be shown if it's not a singleton method, and Method#inspect shouldn't change for a given method.
Do you agree what I describe should be the correct behavior?
Can we fix it then?
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 6+ messages in thread
* [ruby-core:91571] [Ruby trunk Bug#15608] What should be the correct output for Method#inspect with singleton methods?
[not found] <redmine.issue-15608.20190215164233@ruby-lang.org>
2019-02-15 16:42 ` [ruby-core:91570] [Ruby trunk Bug#15608] What should be the correct output for Method#inspect with singleton methods? eregontp
@ 2019-02-15 16:50 ` eregontp
2019-02-28 23:49 ` [ruby-core:91648] " s.wanabe
` (3 subsequent siblings)
5 siblings, 0 replies; 6+ messages in thread
From: eregontp @ 2019-02-15 16:50 UTC (permalink / raw)
To: ruby-core
Issue #15608 has been updated by Eregon (Benoit Daloze).
It would be great to have specs under `spec/ruby` for this, and that could explain the rationale behind each decision for each case.
Unit tests do not achieve that.
----------------------------------------
Bug #15608: What should be the correct output for Method#inspect with singleton methods?
https://bugs.ruby-lang.org/issues/15608#change-76835
* Author: Eregon (Benoit Daloze)
* Status: Open
* Priority: Normal
* Assignee:
* Target version:
* ruby -v: ruby 2.6.1p33 (2019-01-30 revision 66950) [x86_64-linux]
* Backport: 2.4: UNKNOWN, 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
bug.rb:
```ruby
class C
def foo
end
end
obj = C.new
class << obj
alias bar foo
end
p obj.method(:foo).owner
p obj.method(:foo)
raise unless obj.method(:foo).owner == C
p obj.method(:bar).owner
p obj.method(:bar)
raise unless obj.method(:bar).owner == obj.singleton_class
```
```
$ chruby 2.0.0
$ ruby -v bug.rb
ruby 2.0.0p648 (2015-12-16) [x86_64-linux]
C
#<Method: C#foo>
#<Class:#<C:0x0055b39fcd2c30>>
#<Method: C(C)#foo>
$ chruby 2.3.8
$ ruby -v bug.rb
ruby 2.3.8p459 (2018-10-18 revision 65136) [x86_64-linux]
C
#<Method: C#foo>
#<Class:#<C:0x000055668ebef268>>
#<Method: #<C:0x000055668ebef268>.bar(foo)>
$ chruby 2.4.5
$ ruby -v bug.rb
ruby 2.4.5p335 (2018-10-18 revision 65137) [x86_64-linux]
C
#<Method: #<C:0x000055fdc99dc908>.foo>
#<Class:#<C:0x000055fdc99dc908>>
#<Method: #<C:0x000055fdc99dc908>.bar(foo)>
Same for 2.5.3 and 2.6.1
```
I think Method#inspect should show on which Module the method is defined (`Method#owner`), and only singleton methods should be shown as `receiver.method`, so:
```
C
#<Method: C#foo>
#<Class:#<C:0x000055668ebef268>>
#<Method: #<C:0x000055668ebef268>.bar(foo)>
```
Which only Ruby 2.3 does interestingly.
---
What's the meaning of the `C1(C2)` notation?
It seems to show `"#{receiver.class}(#{owner})` or `"#{receiver.singleton_class if receiver has a sclass}` depending on the version:
```ruby
class D < C
end
d = D.new
p d.method(:foo)
d.singleton_class
p d.method(:foo)
```
```
2.0-2.3:
#<Method: D(C)#foo>
#<Method: D(C)#foo>
2.4-2.6:
#<Method: D(C)#foo>
#<Method: #<D:0x000055c12b45e218>.foo>
```
I think the Ruby 2.4+ behavior is confusing and incorrect here, the object shouldn't be shown if it's not a singleton method, and Method#inspect shouldn't change for a given method.
Do you agree what I describe should be the correct behavior?
Can we fix it then?
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 6+ messages in thread
* [ruby-core:91648] [Ruby trunk Bug#15608] What should be the correct output for Method#inspect with singleton methods?
[not found] <redmine.issue-15608.20190215164233@ruby-lang.org>
2019-02-15 16:42 ` [ruby-core:91570] [Ruby trunk Bug#15608] What should be the correct output for Method#inspect with singleton methods? eregontp
2019-02-15 16:50 ` [ruby-core:91571] " eregontp
@ 2019-02-28 23:49 ` s.wanabe
2019-10-15 2:45 ` [ruby-core:95323] [Ruby master " merch-redmine
` (2 subsequent siblings)
5 siblings, 0 replies; 6+ messages in thread
From: s.wanabe @ 2019-02-28 23:49 UTC (permalink / raw)
To: ruby-core
Issue #15608 has been updated by wanabe (_ wanabe).
Current behavior is from r60127.
I guess it will come to the same to replace `data->klass` of `method_inspect()` to `data->iclass`.
----------------------------------------
Bug #15608: What should be the correct output for Method#inspect with singleton methods?
https://bugs.ruby-lang.org/issues/15608#change-76912
* Author: Eregon (Benoit Daloze)
* Status: Open
* Priority: Normal
* Assignee:
* Target version:
* ruby -v: ruby 2.6.1p33 (2019-01-30 revision 66950) [x86_64-linux]
* Backport: 2.4: UNKNOWN, 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
bug.rb:
```ruby
class C
def foo
end
end
obj = C.new
class << obj
alias bar foo
end
p obj.method(:foo).owner
p obj.method(:foo)
raise unless obj.method(:foo).owner == C
p obj.method(:bar).owner
p obj.method(:bar)
raise unless obj.method(:bar).owner == obj.singleton_class
```
```
$ chruby 2.0.0
$ ruby -v bug.rb
ruby 2.0.0p648 (2015-12-16) [x86_64-linux]
C
#<Method: C#foo>
#<Class:#<C:0x0055b39fcd2c30>>
#<Method: C(C)#foo>
$ chruby 2.3.8
$ ruby -v bug.rb
ruby 2.3.8p459 (2018-10-18 revision 65136) [x86_64-linux]
C
#<Method: C#foo>
#<Class:#<C:0x000055668ebef268>>
#<Method: #<C:0x000055668ebef268>.bar(foo)>
$ chruby 2.4.5
$ ruby -v bug.rb
ruby 2.4.5p335 (2018-10-18 revision 65137) [x86_64-linux]
C
#<Method: #<C:0x000055fdc99dc908>.foo>
#<Class:#<C:0x000055fdc99dc908>>
#<Method: #<C:0x000055fdc99dc908>.bar(foo)>
Same for 2.5.3 and 2.6.1
```
I think Method#inspect should show on which Module the method is defined (`Method#owner`), and only singleton methods should be shown as `receiver.method`, so:
```
C
#<Method: C#foo>
#<Class:#<C:0x000055668ebef268>>
#<Method: #<C:0x000055668ebef268>.bar(foo)>
```
Which only Ruby 2.3 does interestingly.
---
What's the meaning of the `C1(C2)` notation?
It seems to show `"#{receiver.class}(#{owner})` or `"#{receiver.singleton_class if receiver has a sclass}` depending on the version:
```ruby
class D < C
end
d = D.new
p d.method(:foo)
d.singleton_class
p d.method(:foo)
```
```
2.0-2.3:
#<Method: D(C)#foo>
#<Method: D(C)#foo>
2.4-2.6:
#<Method: D(C)#foo>
#<Method: #<D:0x000055c12b45e218>.foo>
```
I think the Ruby 2.4+ behavior is confusing and incorrect here, the object shouldn't be shown if it's not a singleton method, and Method#inspect shouldn't change for a given method.
Do you agree what I describe should be the correct behavior?
Can we fix it then?
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 6+ messages in thread
* [ruby-core:95323] [Ruby master Bug#15608] What should be the correct output for Method#inspect with singleton methods?
[not found] <redmine.issue-15608.20190215164233@ruby-lang.org>
` (2 preceding siblings ...)
2019-02-28 23:49 ` [ruby-core:91648] " s.wanabe
@ 2019-10-15 2:45 ` merch-redmine
2019-10-15 5:21 ` [ruby-core:95325] " eregontp
2019-10-15 14:34 ` [ruby-core:95334] " merch-redmine
5 siblings, 0 replies; 6+ messages in thread
From: merch-redmine @ 2019-10-15 2:45 UTC (permalink / raw)
To: ruby-core
Issue #15608 has been updated by jeremyevans0 (Jeremy Evans).
File method-inspect-15608.patch added
Attached is a patch that fixes this issue. @wanabe was correct that we need to use `data->iclass` if available. However, changing just that breaks some existing tests. To keep existing tests working but also fix this issue, if the object has a singleton class, but the method was not defined on the singleton class, continue to use `data->klass`, but skip the singleton class and included modules.
Example:
```ruby
class C
def foo
end
end
class D < C
end
d = D.new
p d.method(:foo)
d.singleton_class
p d.method(:foo)
```
Result after patch:
```
#<Method: D(C)#foo t/t7.rb:2>
#<Method: D(C)#foo t/t7.rb:2>
```
----------------------------------------
Bug #15608: What should be the correct output for Method#inspect with singleton methods?
https://bugs.ruby-lang.org/issues/15608#change-82030
* Author: Eregon (Benoit Daloze)
* Status: Open
* Priority: Normal
* Assignee:
* Target version:
* ruby -v: ruby 2.6.1p33 (2019-01-30 revision 66950) [x86_64-linux]
* Backport: 2.4: UNKNOWN, 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
bug.rb:
```ruby
class C
def foo
end
end
obj = C.new
class << obj
alias bar foo
end
p obj.method(:foo).owner
p obj.method(:foo)
raise unless obj.method(:foo).owner == C
p obj.method(:bar).owner
p obj.method(:bar)
raise unless obj.method(:bar).owner == obj.singleton_class
```
```
$ chruby 2.0.0
$ ruby -v bug.rb
ruby 2.0.0p648 (2015-12-16) [x86_64-linux]
C
#<Method: C#foo>
#<Class:#<C:0x0055b39fcd2c30>>
#<Method: C(C)#foo>
$ chruby 2.3.8
$ ruby -v bug.rb
ruby 2.3.8p459 (2018-10-18 revision 65136) [x86_64-linux]
C
#<Method: C#foo>
#<Class:#<C:0x000055668ebef268>>
#<Method: #<C:0x000055668ebef268>.bar(foo)>
$ chruby 2.4.5
$ ruby -v bug.rb
ruby 2.4.5p335 (2018-10-18 revision 65137) [x86_64-linux]
C
#<Method: #<C:0x000055fdc99dc908>.foo>
#<Class:#<C:0x000055fdc99dc908>>
#<Method: #<C:0x000055fdc99dc908>.bar(foo)>
Same for 2.5.3 and 2.6.1
```
I think Method#inspect should show on which Module the method is defined (`Method#owner`), and only singleton methods should be shown as `receiver.method`, so:
```
C
#<Method: C#foo>
#<Class:#<C:0x000055668ebef268>>
#<Method: #<C:0x000055668ebef268>.bar(foo)>
```
Which only Ruby 2.3 does interestingly.
---
What's the meaning of the `C1(C2)` notation?
It seems to show `"#{receiver.class}(#{owner})` or `"#{receiver.singleton_class if receiver has a sclass}` depending on the version:
```ruby
class D < C
end
d = D.new
p d.method(:foo)
d.singleton_class
p d.method(:foo)
```
```
2.0-2.3:
#<Method: D(C)#foo>
#<Method: D(C)#foo>
2.4-2.6:
#<Method: D(C)#foo>
#<Method: #<D:0x000055c12b45e218>.foo>
```
I think the Ruby 2.4+ behavior is confusing and incorrect here, the object shouldn't be shown if it's not a singleton method, and Method#inspect shouldn't change for a given method.
Do you agree what I describe should be the correct behavior?
Can we fix it then?
---Files--------------------------------
method-inspect-15608.patch (2.31 KB)
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 6+ messages in thread
* [ruby-core:95325] [Ruby master Bug#15608] What should be the correct output for Method#inspect with singleton methods?
[not found] <redmine.issue-15608.20190215164233@ruby-lang.org>
` (3 preceding siblings ...)
2019-10-15 2:45 ` [ruby-core:95323] [Ruby master " merch-redmine
@ 2019-10-15 5:21 ` eregontp
2019-10-15 14:34 ` [ruby-core:95334] " merch-redmine
5 siblings, 0 replies; 6+ messages in thread
From: eregontp @ 2019-10-15 5:21 UTC (permalink / raw)
To: ruby-core
Issue #15608 has been updated by Eregon (Benoit Daloze).
Thanks for the patch.
What tests does it break, could you copy the output?
The tests might be wrong too.
----------------------------------------
Bug #15608: What should be the correct output for Method#inspect with singleton methods?
https://bugs.ruby-lang.org/issues/15608#change-82033
* Author: Eregon (Benoit Daloze)
* Status: Open
* Priority: Normal
* Assignee:
* Target version:
* ruby -v: ruby 2.6.1p33 (2019-01-30 revision 66950) [x86_64-linux]
* Backport: 2.4: UNKNOWN, 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
bug.rb:
```ruby
class C
def foo
end
end
obj = C.new
class << obj
alias bar foo
end
p obj.method(:foo).owner
p obj.method(:foo)
raise unless obj.method(:foo).owner == C
p obj.method(:bar).owner
p obj.method(:bar)
raise unless obj.method(:bar).owner == obj.singleton_class
```
```
$ chruby 2.0.0
$ ruby -v bug.rb
ruby 2.0.0p648 (2015-12-16) [x86_64-linux]
C
#<Method: C#foo>
#<Class:#<C:0x0055b39fcd2c30>>
#<Method: C(C)#foo>
$ chruby 2.3.8
$ ruby -v bug.rb
ruby 2.3.8p459 (2018-10-18 revision 65136) [x86_64-linux]
C
#<Method: C#foo>
#<Class:#<C:0x000055668ebef268>>
#<Method: #<C:0x000055668ebef268>.bar(foo)>
$ chruby 2.4.5
$ ruby -v bug.rb
ruby 2.4.5p335 (2018-10-18 revision 65137) [x86_64-linux]
C
#<Method: #<C:0x000055fdc99dc908>.foo>
#<Class:#<C:0x000055fdc99dc908>>
#<Method: #<C:0x000055fdc99dc908>.bar(foo)>
Same for 2.5.3 and 2.6.1
```
I think Method#inspect should show on which Module the method is defined (`Method#owner`), and only singleton methods should be shown as `receiver.method`, so:
```
C
#<Method: C#foo>
#<Class:#<C:0x000055668ebef268>>
#<Method: #<C:0x000055668ebef268>.bar(foo)>
```
Which only Ruby 2.3 does interestingly.
---
What's the meaning of the `C1(C2)` notation?
It seems to show `"#{receiver.class}(#{owner})` or `"#{receiver.singleton_class if receiver has a sclass}` depending on the version:
```ruby
class D < C
end
d = D.new
p d.method(:foo)
d.singleton_class
p d.method(:foo)
```
```
2.0-2.3:
#<Method: D(C)#foo>
#<Method: D(C)#foo>
2.4-2.6:
#<Method: D(C)#foo>
#<Method: #<D:0x000055c12b45e218>.foo>
```
I think the Ruby 2.4+ behavior is confusing and incorrect here, the object shouldn't be shown if it's not a singleton method, and Method#inspect shouldn't change for a given method.
Do you agree what I describe should be the correct behavior?
Can we fix it then?
---Files--------------------------------
method-inspect-15608.patch (2.31 KB)
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 6+ messages in thread
* [ruby-core:95334] [Ruby master Bug#15608] What should be the correct output for Method#inspect with singleton methods?
[not found] <redmine.issue-15608.20190215164233@ruby-lang.org>
` (4 preceding siblings ...)
2019-10-15 5:21 ` [ruby-core:95325] " eregontp
@ 2019-10-15 14:34 ` merch-redmine
5 siblings, 0 replies; 6+ messages in thread
From: merch-redmine @ 2019-10-15 14:34 UTC (permalink / raw)
To: ruby-core
Issue #15608 has been updated by jeremyevans0 (Jeremy Evans).
Eregon (Benoit Daloze) wrote:
> What tests does it break, could you copy the output?
I didn't keep the output. From a brief analysis, it appeared to be to be tests that you wouldn't want to break. Using `data->iclass` instead of `data->klass` results in `C#foo` instead of `D(C)#foo` for `D.new.method(:foo)`.
----------------------------------------
Bug #15608: What should be the correct output for Method#inspect with singleton methods?
https://bugs.ruby-lang.org/issues/15608#change-82042
* Author: Eregon (Benoit Daloze)
* Status: Open
* Priority: Normal
* Assignee:
* Target version:
* ruby -v: ruby 2.6.1p33 (2019-01-30 revision 66950) [x86_64-linux]
* Backport: 2.4: UNKNOWN, 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
bug.rb:
```ruby
class C
def foo
end
end
obj = C.new
class << obj
alias bar foo
end
p obj.method(:foo).owner
p obj.method(:foo)
raise unless obj.method(:foo).owner == C
p obj.method(:bar).owner
p obj.method(:bar)
raise unless obj.method(:bar).owner == obj.singleton_class
```
```
$ chruby 2.0.0
$ ruby -v bug.rb
ruby 2.0.0p648 (2015-12-16) [x86_64-linux]
C
#<Method: C#foo>
#<Class:#<C:0x0055b39fcd2c30>>
#<Method: C(C)#foo>
$ chruby 2.3.8
$ ruby -v bug.rb
ruby 2.3.8p459 (2018-10-18 revision 65136) [x86_64-linux]
C
#<Method: C#foo>
#<Class:#<C:0x000055668ebef268>>
#<Method: #<C:0x000055668ebef268>.bar(foo)>
$ chruby 2.4.5
$ ruby -v bug.rb
ruby 2.4.5p335 (2018-10-18 revision 65137) [x86_64-linux]
C
#<Method: #<C:0x000055fdc99dc908>.foo>
#<Class:#<C:0x000055fdc99dc908>>
#<Method: #<C:0x000055fdc99dc908>.bar(foo)>
Same for 2.5.3 and 2.6.1
```
I think Method#inspect should show on which Module the method is defined (`Method#owner`), and only singleton methods should be shown as `receiver.method`, so:
```
C
#<Method: C#foo>
#<Class:#<C:0x000055668ebef268>>
#<Method: #<C:0x000055668ebef268>.bar(foo)>
```
Which only Ruby 2.3 does interestingly.
---
What's the meaning of the `C1(C2)` notation?
It seems to show `"#{receiver.class}(#{owner})` or `"#{receiver.singleton_class if receiver has a sclass}` depending on the version:
```ruby
class D < C
end
d = D.new
p d.method(:foo)
d.singleton_class
p d.method(:foo)
```
```
2.0-2.3:
#<Method: D(C)#foo>
#<Method: D(C)#foo>
2.4-2.6:
#<Method: D(C)#foo>
#<Method: #<D:0x000055c12b45e218>.foo>
```
I think the Ruby 2.4+ behavior is confusing and incorrect here, the object shouldn't be shown if it's not a singleton method, and Method#inspect shouldn't change for a given method.
Do you agree what I describe should be the correct behavior?
Can we fix it then?
---Files--------------------------------
method-inspect-15608.patch (2.31 KB)
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2019-10-15 14:34 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <redmine.issue-15608.20190215164233@ruby-lang.org>
2019-02-15 16:42 ` [ruby-core:91570] [Ruby trunk Bug#15608] What should be the correct output for Method#inspect with singleton methods? eregontp
2019-02-15 16:50 ` [ruby-core:91571] " eregontp
2019-02-28 23:49 ` [ruby-core:91648] " s.wanabe
2019-10-15 2:45 ` [ruby-core:95323] [Ruby master " merch-redmine
2019-10-15 5:21 ` [ruby-core:95325] " eregontp
2019-10-15 14:34 ` [ruby-core:95334] " merch-redmine
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).