ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:108659] [Ruby master Bug#18798] `UnboundMethod#==` with inherited classes
@ 2022-05-24  1:55 ko1 (Koichi Sasada)
  2022-05-24  6:40 ` [ruby-core:108662] " sawa (Tsuyoshi Sawada)
                   ` (14 more replies)
  0 siblings, 15 replies; 16+ messages in thread
From: ko1 (Koichi Sasada) @ 2022-05-24  1:55 UTC (permalink / raw)
  To: ruby-core

Issue #18798 has been reported by ko1 (Koichi Sasada).

----------------------------------------
Bug #18798: `UnboundMethod#==` with inherited classes
https://bugs.ruby-lang.org/issues/18798

* Author: ko1 (Koichi Sasada)
* Status: Open
* Priority: Normal
* ruby -v: ruby 3.2.0dev (2022-01-14T04:46:12Z gh-4636 c613d79f9b) [x64-mswin64_140]
* Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN
----------------------------------------
Now `UnboundMethod` for a same method from a superclass and an inherited class are not `==`.

```ruby
class C
  def foo = :C
  $mc = instance_method(:foo)
end

class D < C
  $md = instance_method(:foo)
end

p $mc == $md #=> false
p $mc.owner #=> C
p $mc.owner == $mc.owner #=> true
p $mc.source_location == $mc.source_location #=> true
p $mc.inspect #=> "#<UnboundMethod: C#foo() t.rb:3>"
p $md.inspect #=> "#<UnboundMethod: D(C)#foo() t.rb:3>"
```

How about to make it `UnboundMethod#==` return true for this case?
Rule: "return true if the UnboundMethod objects points same method definition" seems simple.

FYI: On aliased unbound methods point to a same method are `==`.


```ruby
class C
  def foo = :C
  alias bar foo
  $mfoo = instance_method(:foo)
  $mbar = instance_method(:bar)
end

p $mfoo, $mbar
#=> #<UnboundMethod: C#foo() t.rb:2>
#=> #<UnboundMethod: C#bar(foo)() t.rb:2>

p $mfoo == $mbar #=> true
```




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

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

* [ruby-core:108662] [Ruby master Bug#18798] `UnboundMethod#==` with inherited classes
  2022-05-24  1:55 [ruby-core:108659] [Ruby master Bug#18798] `UnboundMethod#==` with inherited classes ko1 (Koichi Sasada)
@ 2022-05-24  6:40 ` sawa (Tsuyoshi Sawada)
  2022-05-24 19:18 ` [ruby-core:108674] " jeremyevans0 (Jeremy Evans)
                   ` (13 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: sawa (Tsuyoshi Sawada) @ 2022-05-24  6:40 UTC (permalink / raw)
  To: ruby-core

Issue #18798 has been updated by sawa (Tsuyoshi Sawada).


Did you mean:

```ruby
p $mc.owner == $md.owner #=> true
p $mc.source_location == $md.source_location #=> true
```


----------------------------------------
Bug #18798: `UnboundMethod#==` with inherited classes
https://bugs.ruby-lang.org/issues/18798#change-97705

* Author: ko1 (Koichi Sasada)
* Status: Open
* Priority: Normal
* ruby -v: ruby 3.2.0dev (2022-01-14T04:46:12Z gh-4636 c613d79f9b) [x64-mswin64_140]
* Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN
----------------------------------------
Now `UnboundMethod` for a same method from a superclass and an inherited class are not `==`.

```ruby
class C
  def foo = :C
  $mc = instance_method(:foo)
end

class D < C
  $md = instance_method(:foo)
end

p $mc == $md #=> false
p $mc.owner #=> C
p $mc.owner == $mc.owner #=> true
p $mc.source_location == $mc.source_location #=> true
p $mc.inspect #=> "#<UnboundMethod: C#foo() t.rb:3>"
p $md.inspect #=> "#<UnboundMethod: D(C)#foo() t.rb:3>"
```

How about to make it `UnboundMethod#==` return true for this case?
Rule: "return true if the UnboundMethod objects point to a same method definition" seems simple.

FYI: On aliased unbound methods point to a same method are `==`.


```ruby
class C
  def foo = :C
  alias bar foo
  $mfoo = instance_method(:foo)
  $mbar = instance_method(:bar)
end

p $mfoo, $mbar
#=> #<UnboundMethod: C#foo() t.rb:2>
#=> #<UnboundMethod: C#bar(foo)() t.rb:2>

p $mfoo == $mbar #=> true
```




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

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

* [ruby-core:108674] [Ruby master Bug#18798] `UnboundMethod#==` with inherited classes
  2022-05-24  1:55 [ruby-core:108659] [Ruby master Bug#18798] `UnboundMethod#==` with inherited classes ko1 (Koichi Sasada)
  2022-05-24  6:40 ` [ruby-core:108662] " sawa (Tsuyoshi Sawada)
@ 2022-05-24 19:18 ` jeremyevans0 (Jeremy Evans)
  2022-05-24 19:49 ` [ruby-core:108676] " Eregon (Benoit Daloze)
                   ` (12 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: jeremyevans0 (Jeremy Evans) @ 2022-05-24 19:18 UTC (permalink / raw)
  To: ruby-core

Issue #18798 has been updated by jeremyevans0 (Jeremy Evans).


I'm not against this change (for UnboundMethod, I think Method should remain different), but it seems more like a feature request than a bug fix to me.

----------------------------------------
Bug #18798: `UnboundMethod#==` with inherited classes
https://bugs.ruby-lang.org/issues/18798#change-97715

* Author: ko1 (Koichi Sasada)
* Status: Open
* Priority: Normal
* ruby -v: ruby 3.2.0dev (2022-01-14T04:46:12Z gh-4636 c613d79f9b) [x64-mswin64_140]
* Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN
----------------------------------------
Now `UnboundMethod` for a same method from a superclass and an inherited class are not `==`.

```ruby
class C
  def foo = :C
  $mc = instance_method(:foo)
end

class D < C
  $md = instance_method(:foo)
end

p $mc == $md #=> false
p $mc.owner #=> C
p $mc.owner == $mc.owner #=> true
p $mc.source_location == $mc.source_location #=> true
p $mc.inspect #=> "#<UnboundMethod: C#foo() t.rb:3>"
p $md.inspect #=> "#<UnboundMethod: D(C)#foo() t.rb:3>"
```

How about to make it `UnboundMethod#==` return true for this case?
Rule: "return true if the UnboundMethod objects point to a same method definition" seems simple.

FYI: On aliased unbound methods point to a same method are `==`.


```ruby
class C
  def foo = :C
  alias bar foo
  $mfoo = instance_method(:foo)
  $mbar = instance_method(:bar)
end

p $mfoo, $mbar
#=> #<UnboundMethod: C#foo() t.rb:2>
#=> #<UnboundMethod: C#bar(foo)() t.rb:2>

p $mfoo == $mbar #=> true
```




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

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

* [ruby-core:108676] [Ruby master Bug#18798] `UnboundMethod#==` with inherited classes
  2022-05-24  1:55 [ruby-core:108659] [Ruby master Bug#18798] `UnboundMethod#==` with inherited classes ko1 (Koichi Sasada)
  2022-05-24  6:40 ` [ruby-core:108662] " sawa (Tsuyoshi Sawada)
  2022-05-24 19:18 ` [ruby-core:108674] " jeremyevans0 (Jeremy Evans)
@ 2022-05-24 19:49 ` Eregon (Benoit Daloze)
  2022-05-24 19:50 ` [ruby-core:108677] " Eregon (Benoit Daloze)
                   ` (11 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: Eregon (Benoit Daloze) @ 2022-05-24 19:49 UTC (permalink / raw)
  To: ruby-core

Issue #18798 has been updated by Eregon (Benoit Daloze).


+1. @ko1 I guess you meant this as a feature request?

----------------------------------------
Bug #18798: `UnboundMethod#==` with inherited classes
https://bugs.ruby-lang.org/issues/18798#change-97717

* Author: ko1 (Koichi Sasada)
* Status: Open
* Priority: Normal
* ruby -v: ruby 3.2.0dev (2022-01-14T04:46:12Z gh-4636 c613d79f9b) [x64-mswin64_140]
* Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN
----------------------------------------
Now `UnboundMethod` for a same method from a superclass and an inherited class are not `==`.

```ruby
class C
  def foo = :C
  $mc = instance_method(:foo)
end

class D < C
  $md = instance_method(:foo)
end

p $mc == $md #=> false
p $mc.owner #=> C
p $mc.owner == $mc.owner #=> true
p $mc.source_location == $mc.source_location #=> true
p $mc.inspect #=> "#<UnboundMethod: C#foo() t.rb:3>"
p $md.inspect #=> "#<UnboundMethod: D(C)#foo() t.rb:3>"
```

How about to make it `UnboundMethod#==` return true for this case?
Rule: "return true if the UnboundMethod objects point to a same method definition" seems simple.

FYI: On aliased unbound methods point to a same method are `==`.


```ruby
class C
  def foo = :C
  alias bar foo
  $mfoo = instance_method(:foo)
  $mbar = instance_method(:bar)
end

p $mfoo, $mbar
#=> #<UnboundMethod: C#foo() t.rb:2>
#=> #<UnboundMethod: C#bar(foo)() t.rb:2>

p $mfoo == $mbar #=> true
```




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

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

* [ruby-core:108677] [Ruby master Bug#18798] `UnboundMethod#==` with inherited classes
  2022-05-24  1:55 [ruby-core:108659] [Ruby master Bug#18798] `UnboundMethod#==` with inherited classes ko1 (Koichi Sasada)
                   ` (2 preceding siblings ...)
  2022-05-24 19:49 ` [ruby-core:108676] " Eregon (Benoit Daloze)
@ 2022-05-24 19:50 ` Eregon (Benoit Daloze)
  2022-05-25  0:28 ` [ruby-core:108688] [Ruby master Feature#18798] " ko1 (Koichi Sasada)
                   ` (10 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: Eregon (Benoit Daloze) @ 2022-05-24 19:50 UTC (permalink / raw)
  To: ruby-core

Issue #18798 has been updated by Eregon (Benoit Daloze).


Regarding Method#==, I think it should also respects the simple rule "point to a same method definition" + ensure the receiver is the same object for both Method instances.

----------------------------------------
Bug #18798: `UnboundMethod#==` with inherited classes
https://bugs.ruby-lang.org/issues/18798#change-97718

* Author: ko1 (Koichi Sasada)
* Status: Open
* Priority: Normal
* ruby -v: ruby 3.2.0dev (2022-01-14T04:46:12Z gh-4636 c613d79f9b) [x64-mswin64_140]
* Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN
----------------------------------------
Now `UnboundMethod` for a same method from a superclass and an inherited class are not `==`.

```ruby
class C
  def foo = :C
  $mc = instance_method(:foo)
end

class D < C
  $md = instance_method(:foo)
end

p $mc == $md #=> false
p $mc.owner #=> C
p $mc.owner == $mc.owner #=> true
p $mc.source_location == $mc.source_location #=> true
p $mc.inspect #=> "#<UnboundMethod: C#foo() t.rb:3>"
p $md.inspect #=> "#<UnboundMethod: D(C)#foo() t.rb:3>"
```

How about to make it `UnboundMethod#==` return true for this case?
Rule: "return true if the UnboundMethod objects point to a same method definition" seems simple.

FYI: On aliased unbound methods point to a same method are `==`.


```ruby
class C
  def foo = :C
  alias bar foo
  $mfoo = instance_method(:foo)
  $mbar = instance_method(:bar)
end

p $mfoo, $mbar
#=> #<UnboundMethod: C#foo() t.rb:2>
#=> #<UnboundMethod: C#bar(foo)() t.rb:2>

p $mfoo == $mbar #=> true
```




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

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

* [ruby-core:108688] [Ruby master Feature#18798] `UnboundMethod#==` with inherited classes
  2022-05-24  1:55 [ruby-core:108659] [Ruby master Bug#18798] `UnboundMethod#==` with inherited classes ko1 (Koichi Sasada)
                   ` (3 preceding siblings ...)
  2022-05-24 19:50 ` [ruby-core:108677] " Eregon (Benoit Daloze)
@ 2022-05-25  0:28 ` ko1 (Koichi Sasada)
  2022-05-25  0:32 ` [ruby-core:108689] " ko1 (Koichi Sasada)
                   ` (9 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: ko1 (Koichi Sasada) @ 2022-05-25  0:28 UTC (permalink / raw)
  To: ruby-core

Issue #18798 has been updated by ko1 (Koichi Sasada).

Backport deleted (2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN)
ruby -v deleted (ruby 3.2.0dev (2022-01-14T04:46:12Z gh-4636 c613d79f9b) [x64-mswin64_140])
Tracker changed from Bug to Feature

Ah, yes, it is a feature request.

----------------------------------------
Feature #18798: `UnboundMethod#==` with inherited classes
https://bugs.ruby-lang.org/issues/18798#change-97729

* Author: ko1 (Koichi Sasada)
* Status: Open
* Priority: Normal
----------------------------------------
Now `UnboundMethod` for a same method from a superclass and an inherited class are not `==`.

```ruby
class C
  def foo = :C
  $mc = instance_method(:foo)
end

class D < C
  $md = instance_method(:foo)
end

p $mc == $md #=> false
p $mc.owner #=> C
p $mc.owner == $mc.owner #=> true
p $mc.source_location == $mc.source_location #=> true
p $mc.inspect #=> "#<UnboundMethod: C#foo() t.rb:3>"
p $md.inspect #=> "#<UnboundMethod: D(C)#foo() t.rb:3>"
```

How about to make it `UnboundMethod#==` return true for this case?
Rule: "return true if the UnboundMethod objects point to a same method definition" seems simple.

FYI: On aliased unbound methods point to a same method are `==`.


```ruby
class C
  def foo = :C
  alias bar foo
  $mfoo = instance_method(:foo)
  $mbar = instance_method(:bar)
end

p $mfoo, $mbar
#=> #<UnboundMethod: C#foo() t.rb:2>
#=> #<UnboundMethod: C#bar(foo)() t.rb:2>

p $mfoo == $mbar #=> true
```




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

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

* [ruby-core:108689] [Ruby master Feature#18798] `UnboundMethod#==` with inherited classes
  2022-05-24  1:55 [ruby-core:108659] [Ruby master Bug#18798] `UnboundMethod#==` with inherited classes ko1 (Koichi Sasada)
                   ` (4 preceding siblings ...)
  2022-05-25  0:28 ` [ruby-core:108688] [Ruby master Feature#18798] " ko1 (Koichi Sasada)
@ 2022-05-25  0:32 ` ko1 (Koichi Sasada)
  2022-08-20 19:48 ` [ruby-core:109602] " Eregon (Benoit Daloze)
                   ` (8 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: ko1 (Koichi Sasada) @ 2022-05-25  0:32 UTC (permalink / raw)
  To: ruby-core

Issue #18798 has been updated by ko1 (Koichi Sasada).

Description updated

ah, mistake...

----------------------------------------
Feature #18798: `UnboundMethod#==` with inherited classes
https://bugs.ruby-lang.org/issues/18798#change-97730

* Author: ko1 (Koichi Sasada)
* Status: Open
* Priority: Normal
----------------------------------------
Now `UnboundMethod` for a same method from a superclass and an inherited class are not `==`.

```ruby
class C
  def foo = :C
  $mc = instance_method(:foo)
end

class D < C
  $md = instance_method(:foo)
end

p $mc == $md #=> false
p $mc.owner #=> C
p $mc.owner == $md.owner #=> true
p $mc.source_location == $md.source_location #=> true
p $mc.inspect #=> "#<UnboundMethod: C#foo() t.rb:3>"
p $md.inspect #=> "#<UnboundMethod: D(C)#foo() t.rb:3>"
```

How about to make it `UnboundMethod#==` return true for this case?
Rule: "return true if the UnboundMethod objects point to a same method definition" seems simple.

FYI: On aliased unbound methods point to a same method are `==`.


```ruby
class C
  def foo = :C
  alias bar foo
  $mfoo = instance_method(:foo)
  $mbar = instance_method(:bar)
end

p $mfoo, $mbar
#=> #<UnboundMethod: C#foo() t.rb:2>
#=> #<UnboundMethod: C#bar(foo)() t.rb:2>

p $mfoo == $mbar #=> true
```




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

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

* [ruby-core:109602] [Ruby master Feature#18798] `UnboundMethod#==` with inherited classes
  2022-05-24  1:55 [ruby-core:108659] [Ruby master Bug#18798] `UnboundMethod#==` with inherited classes ko1 (Koichi Sasada)
                   ` (5 preceding siblings ...)
  2022-05-25  0:32 ` [ruby-core:108689] " ko1 (Koichi Sasada)
@ 2022-08-20 19:48 ` Eregon (Benoit Daloze)
  2022-09-11 10:45 ` [ruby-core:109887] " joel@drapper.me (Joel Drapper)
                   ` (7 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: Eregon (Benoit Daloze) @ 2022-08-20 19:48 UTC (permalink / raw)
  To: ruby-core

Issue #18798 has been updated by Eregon (Benoit Daloze).


I think we should do this, because I think the main purpose of {Method,UnboundMethod}#== is to find out if two methods have the same definition (or in other words, are equivalent in behavior).

I filed #18969 which is a duplicate.
That issue also suggests that if changing {Method,UnboundMethod}#== is not acceptable, then a new method could do that e.g. `{Method,UnboundMethod}#same_definition?(other)`.

----------------------------------------
Feature #18798: `UnboundMethod#==` with inherited classes
https://bugs.ruby-lang.org/issues/18798#change-98785

* Author: ko1 (Koichi Sasada)
* Status: Open
* Priority: Normal
----------------------------------------
Now `UnboundMethod` for a same method from a superclass and an inherited class are not `==`.

```ruby
class C
  def foo = :C
  $mc = instance_method(:foo)
end

class D < C
  $md = instance_method(:foo)
end

p $mc == $md #=> false
p $mc.owner #=> C
p $mc.owner == $md.owner #=> true
p $mc.source_location == $md.source_location #=> true
p $mc.inspect #=> "#<UnboundMethod: C#foo() t.rb:3>"
p $md.inspect #=> "#<UnboundMethod: D(C)#foo() t.rb:3>"
```

How about to make it `UnboundMethod#==` return true for this case?
Rule: "return true if the UnboundMethod objects point to a same method definition" seems simple.

FYI: On aliased unbound methods point to a same method are `==`.


```ruby
class C
  def foo = :C
  alias bar foo
  $mfoo = instance_method(:foo)
  $mbar = instance_method(:bar)
end

p $mfoo, $mbar
#=> #<UnboundMethod: C#foo() t.rb:2>
#=> #<UnboundMethod: C#bar(foo)() t.rb:2>

p $mfoo == $mbar #=> true
```




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

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

* [ruby-core:109887] [Ruby master Feature#18798] `UnboundMethod#==` with inherited classes
  2022-05-24  1:55 [ruby-core:108659] [Ruby master Bug#18798] `UnboundMethod#==` with inherited classes ko1 (Koichi Sasada)
                   ` (6 preceding siblings ...)
  2022-08-20 19:48 ` [ruby-core:109602] " Eregon (Benoit Daloze)
@ 2022-09-11 10:45 ` joel@drapper.me (Joel Drapper)
  2022-10-06  6:07 ` [ruby-core:110197] " matz (Yukihiro Matsumoto)
                   ` (6 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: joel@drapper.me (Joel Drapper) @ 2022-09-11 10:45 UTC (permalink / raw)
  To: ruby-core

Issue #18798 has been updated by joel@drapper.me (Joel Drapper).


This would be really helpful for checking if a class has redefined a method inherited form a superclass.

As an example, I’m working on a compiler that replaces certain method calls with their inlined expected behaviour from an abstract superclass. Because it's possible for the subclass to override these abstract methods, the compiler should check if `instance_method(name) == AbstractClass.instance_method(name)` before folding it. While this wouldn't cover the method being overridden in the singleton class, that's a reasonable concession for my specific use case.

----------------------------------------
Feature #18798: `UnboundMethod#==` with inherited classes
https://bugs.ruby-lang.org/issues/18798#change-99128

* Author: ko1 (Koichi Sasada)
* Status: Open
* Priority: Normal
----------------------------------------
Now `UnboundMethod` for a same method from a superclass and an inherited class are not `==`.

```ruby
class C
  def foo = :C
  $mc = instance_method(:foo)
end

class D < C
  $md = instance_method(:foo)
end

p $mc == $md #=> false
p $mc.owner #=> C
p $mc.owner == $md.owner #=> true
p $mc.source_location == $md.source_location #=> true
p $mc.inspect #=> "#<UnboundMethod: C#foo() t.rb:3>"
p $md.inspect #=> "#<UnboundMethod: D(C)#foo() t.rb:3>"
```

How about to make it `UnboundMethod#==` return true for this case?
Rule: "return true if the UnboundMethod objects point to a same method definition" seems simple.

FYI: On aliased unbound methods point to a same method are `==`.


```ruby
class C
  def foo = :C
  alias bar foo
  $mfoo = instance_method(:foo)
  $mbar = instance_method(:bar)
end

p $mfoo, $mbar
#=> #<UnboundMethod: C#foo() t.rb:2>
#=> #<UnboundMethod: C#bar(foo)() t.rb:2>

p $mfoo == $mbar #=> true
```




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

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

* [ruby-core:110197] [Ruby master Feature#18798] `UnboundMethod#==` with inherited classes
  2022-05-24  1:55 [ruby-core:108659] [Ruby master Bug#18798] `UnboundMethod#==` with inherited classes ko1 (Koichi Sasada)
                   ` (7 preceding siblings ...)
  2022-09-11 10:45 ` [ruby-core:109887] " joel@drapper.me (Joel Drapper)
@ 2022-10-06  6:07 ` matz (Yukihiro Matsumoto)
  2022-10-06 12:00 ` [ruby-core:110207] " Eregon (Benoit Daloze)
                   ` (5 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: matz (Yukihiro Matsumoto) @ 2022-10-06  6:07 UTC (permalink / raw)
  To: ruby-core

Issue #18798 has been updated by matz (Yukihiro Matsumoto).


I don't think UnboundMethod needs the reference to the class that generates the object, so that `UnboundMethod#==` works.

Matz.


----------------------------------------
Feature #18798: `UnboundMethod#==` with inherited classes
https://bugs.ruby-lang.org/issues/18798#change-99479

* Author: ko1 (Koichi Sasada)
* Status: Open
* Priority: Normal
----------------------------------------
Now `UnboundMethod` for a same method from a superclass and an inherited class are not `==`.

```ruby
class C
  def foo = :C
  $mc = instance_method(:foo)
end

class D < C
  $md = instance_method(:foo)
end

p $mc == $md #=> false
p $mc.owner #=> C
p $mc.owner == $md.owner #=> true
p $mc.source_location == $md.source_location #=> true
p $mc.inspect #=> "#<UnboundMethod: C#foo() t.rb:3>"
p $md.inspect #=> "#<UnboundMethod: D(C)#foo() t.rb:3>"
```

How about to make it `UnboundMethod#==` return true for this case?
Rule: "return true if the UnboundMethod objects point to a same method definition" seems simple.

FYI: On aliased unbound methods point to a same method are `==`.


```ruby
class C
  def foo = :C
  alias bar foo
  $mfoo = instance_method(:foo)
  $mbar = instance_method(:bar)
end

p $mfoo, $mbar
#=> #<UnboundMethod: C#foo() t.rb:2>
#=> #<UnboundMethod: C#bar(foo)() t.rb:2>

p $mfoo == $mbar #=> true
```




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

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

* [ruby-core:110207] [Ruby master Feature#18798] `UnboundMethod#==` with inherited classes
  2022-05-24  1:55 [ruby-core:108659] [Ruby master Bug#18798] `UnboundMethod#==` with inherited classes ko1 (Koichi Sasada)
                   ` (8 preceding siblings ...)
  2022-10-06  6:07 ` [ruby-core:110197] " matz (Yukihiro Matsumoto)
@ 2022-10-06 12:00 ` Eregon (Benoit Daloze)
  2022-10-06 12:07 ` [ruby-core:110208] " Eregon (Benoit Daloze)
                   ` (4 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: Eregon (Benoit Daloze) @ 2022-10-06 12:00 UTC (permalink / raw)
  To: ruby-core

Issue #18798 has been updated by Eregon (Benoit Daloze).


`UnboundMethod#inspect` currently shows the class used for lookup:
```
irb(main):001:0> String.instance_method(:object_id)
=> #<UnboundMethod: String(Kernel)#object_id()>
```
Without it we can't show `String` here, it'd have to be `#<UnboundMethod: Kernel#object_id()>`.

We might also need it for `#super_method` (when the method entry is defined on a module and not a class), although in CRuby it seems the iclass field is used for that.
The iclass field can already change `super_method` but does not affect #== or #hash.

I'm not sure this incompatibility is OK, it seems easier to only change #== (UnboundMethod#hash already ignores the class).
On the upside, removing that class from #inspect and as a field means there is only one module/class shown per `UnboundMethod` (well, except there is a hidden iclass which does matter for `#super_method`).

----------------------------------------
Feature #18798: `UnboundMethod#==` with inherited classes
https://bugs.ruby-lang.org/issues/18798#change-99489

* Author: ko1 (Koichi Sasada)
* Status: Open
* Priority: Normal
----------------------------------------
Now `UnboundMethod` for a same method from a superclass and an inherited class are not `==`.

```ruby
class C
  def foo = :C
  $mc = instance_method(:foo)
end

class D < C
  $md = instance_method(:foo)
end

p $mc == $md #=> false
p $mc.owner #=> C
p $mc.owner == $md.owner #=> true
p $mc.source_location == $md.source_location #=> true
p $mc.inspect #=> "#<UnboundMethod: C#foo() t.rb:3>"
p $md.inspect #=> "#<UnboundMethod: D(C)#foo() t.rb:3>"
```

How about to make it `UnboundMethod#==` return true for this case?
Rule: "return true if the UnboundMethod objects point to a same method definition" seems simple.

FYI: On aliased unbound methods point to a same method are `==`.


```ruby
class C
  def foo = :C
  alias bar foo
  $mfoo = instance_method(:foo)
  $mbar = instance_method(:bar)
end

p $mfoo, $mbar
#=> #<UnboundMethod: C#foo() t.rb:2>
#=> #<UnboundMethod: C#bar(foo)() t.rb:2>

p $mfoo == $mbar #=> true
```




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

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

* [ruby-core:110208] [Ruby master Feature#18798] `UnboundMethod#==` with inherited classes
  2022-05-24  1:55 [ruby-core:108659] [Ruby master Bug#18798] `UnboundMethod#==` with inherited classes ko1 (Koichi Sasada)
                   ` (9 preceding siblings ...)
  2022-10-06 12:00 ` [ruby-core:110207] " Eregon (Benoit Daloze)
@ 2022-10-06 12:07 ` Eregon (Benoit Daloze)
  2022-10-06 14:29 ` [ruby-core:110209] " mame (Yusuke Endoh)
                   ` (3 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: Eregon (Benoit Daloze) @ 2022-10-06 12:07 UTC (permalink / raw)
  To: ruby-core

Issue #18798 has been updated by Eregon (Benoit Daloze).


In code terms:
```ruby
module M
  def foo
  end
end

class A
  prepend M
  def foo
  end
end

class B
  prepend M
  def foo
  end
end

a = A.instance_method(:foo)
b = B.instance_method(:foo)
p a
p b
p a == b
p [a.super_method, b.super_method]
```

Currently:
```
#<UnboundMethod: A(M)#foo() umethod_iclass.rb:2>
#<UnboundMethod: B(M)#foo() umethod_iclass.rb:2>
false
[#<UnboundMethod: A#foo() umethod_iclass.rb:8>, #<UnboundMethod: B#foo() umethod_iclass.rb:14>]
```

Proposed (just changing UnboundMethod#==):
```
#<UnboundMethod: A(M)#foo() umethod_iclass.rb:2>
#<UnboundMethod: B(M)#foo() umethod_iclass.rb:2>
true
[#<UnboundMethod: A#foo() umethod_iclass.rb:8>, #<UnboundMethod: B#foo() umethod_iclass.rb:14>]
```

No class field anymore:
```
#<UnboundMethod: M#foo() umethod_iclass.rb:2>
#<UnboundMethod: M#foo() umethod_iclass.rb:2> (no visual difference)
true
[#<UnboundMethod: A#foo() umethod_iclass.rb:8>, #<UnboundMethod: B#foo() umethod_iclass.rb:14>]
```

----------------------------------------
Feature #18798: `UnboundMethod#==` with inherited classes
https://bugs.ruby-lang.org/issues/18798#change-99490

* Author: ko1 (Koichi Sasada)
* Status: Open
* Priority: Normal
----------------------------------------
Now `UnboundMethod` for a same method from a superclass and an inherited class are not `==`.

```ruby
class C
  def foo = :C
  $mc = instance_method(:foo)
end

class D < C
  $md = instance_method(:foo)
end

p $mc == $md #=> false
p $mc.owner #=> C
p $mc.owner == $md.owner #=> true
p $mc.source_location == $md.source_location #=> true
p $mc.inspect #=> "#<UnboundMethod: C#foo() t.rb:3>"
p $md.inspect #=> "#<UnboundMethod: D(C)#foo() t.rb:3>"
```

How about to make it `UnboundMethod#==` return true for this case?
Rule: "return true if the UnboundMethod objects point to a same method definition" seems simple.

FYI: On aliased unbound methods point to a same method are `==`.


```ruby
class C
  def foo = :C
  alias bar foo
  $mfoo = instance_method(:foo)
  $mbar = instance_method(:bar)
end

p $mfoo, $mbar
#=> #<UnboundMethod: C#foo() t.rb:2>
#=> #<UnboundMethod: C#bar(foo)() t.rb:2>

p $mfoo == $mbar #=> true
```




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

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

* [ruby-core:110209] [Ruby master Feature#18798] `UnboundMethod#==` with inherited classes
  2022-05-24  1:55 [ruby-core:108659] [Ruby master Bug#18798] `UnboundMethod#==` with inherited classes ko1 (Koichi Sasada)
                   ` (10 preceding siblings ...)
  2022-10-06 12:07 ` [ruby-core:110208] " Eregon (Benoit Daloze)
@ 2022-10-06 14:29 ` mame (Yusuke Endoh)
  2022-10-06 16:20 ` [ruby-core:110215] " Eregon (Benoit Daloze)
                   ` (2 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: mame (Yusuke Endoh) @ 2022-10-06 14:29 UTC (permalink / raw)
  To: ruby-core

Issue #18798 has been updated by mame (Yusuke Endoh).


> No class field anymore:
>
> ```
> #<UnboundMethod: M#foo() umethod_iclass.rb:2>
> #<UnboundMethod: M#foo() umethod_iclass.rb:2> (no visual difference)
> true
> [#<UnboundMethod: A#foo() umethod_iclass.rb:8>, #<UnboundMethod: B#foo() umethod_iclass.rb:14>]
> ```

This understanding is correct.

Discussed at the dev meeting. To the best of our knowledge, the receiver of instance_method is now only used in `UnboundMethod#inspect` (and `#to_s`). At the dev meeting, no one saw the significance of keeping track of this receiver. So @matz wants to discard the information and to change `#==`, `#eql?`, `#hash` (if needed), `#inspect`, and `#to_s` as you said.

----------------------------------------
Feature #18798: `UnboundMethod#==` with inherited classes
https://bugs.ruby-lang.org/issues/18798#change-99492

* Author: ko1 (Koichi Sasada)
* Status: Open
* Priority: Normal
----------------------------------------
Now `UnboundMethod` for a same method from a superclass and an inherited class are not `==`.

```ruby
class C
  def foo = :C
  $mc = instance_method(:foo)
end

class D < C
  $md = instance_method(:foo)
end

p $mc == $md #=> false
p $mc.owner #=> C
p $mc.owner == $md.owner #=> true
p $mc.source_location == $md.source_location #=> true
p $mc.inspect #=> "#<UnboundMethod: C#foo() t.rb:3>"
p $md.inspect #=> "#<UnboundMethod: D(C)#foo() t.rb:3>"
```

How about to make it `UnboundMethod#==` return true for this case?
Rule: "return true if the UnboundMethod objects point to a same method definition" seems simple.

FYI: On aliased unbound methods point to a same method are `==`.


```ruby
class C
  def foo = :C
  alias bar foo
  $mfoo = instance_method(:foo)
  $mbar = instance_method(:bar)
end

p $mfoo, $mbar
#=> #<UnboundMethod: C#foo() t.rb:2>
#=> #<UnboundMethod: C#bar(foo)() t.rb:2>

p $mfoo == $mbar #=> true
```




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

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

* [ruby-core:110215] [Ruby master Feature#18798] `UnboundMethod#==` with inherited classes
  2022-05-24  1:55 [ruby-core:108659] [Ruby master Bug#18798] `UnboundMethod#==` with inherited classes ko1 (Koichi Sasada)
                   ` (11 preceding siblings ...)
  2022-10-06 14:29 ` [ruby-core:110209] " mame (Yusuke Endoh)
@ 2022-10-06 16:20 ` Eregon (Benoit Daloze)
  2022-12-01  5:48 ` [ruby-core:111106] " matz (Yukihiro Matsumoto)
  2022-12-06  9:13 ` [ruby-core:111219] " ko1 (Koichi Sasada)
  14 siblings, 0 replies; 16+ messages in thread
From: Eregon (Benoit Daloze) @ 2022-10-06 16:20 UTC (permalink / raw)
  To: ruby-core

Issue #18798 has been updated by Eregon (Benoit Daloze).


Thanks for confirming. It sounds good to me.
Does @ko1 or anyone else plan to work on this? Otherwise I can give it a try when I have some time.

----------------------------------------
Feature #18798: `UnboundMethod#==` with inherited classes
https://bugs.ruby-lang.org/issues/18798#change-99500

* Author: ko1 (Koichi Sasada)
* Status: Open
* Priority: Normal
----------------------------------------
Now `UnboundMethod` for a same method from a superclass and an inherited class are not `==`.

```ruby
class C
  def foo = :C
  $mc = instance_method(:foo)
end

class D < C
  $md = instance_method(:foo)
end

p $mc == $md #=> false
p $mc.owner #=> C
p $mc.owner == $md.owner #=> true
p $mc.source_location == $md.source_location #=> true
p $mc.inspect #=> "#<UnboundMethod: C#foo() t.rb:3>"
p $md.inspect #=> "#<UnboundMethod: D(C)#foo() t.rb:3>"
```

How about to make it `UnboundMethod#==` return true for this case?
Rule: "return true if the UnboundMethod objects point to a same method definition" seems simple.

FYI: On aliased unbound methods point to a same method are `==`.


```ruby
class C
  def foo = :C
  alias bar foo
  $mfoo = instance_method(:foo)
  $mbar = instance_method(:bar)
end

p $mfoo, $mbar
#=> #<UnboundMethod: C#foo() t.rb:2>
#=> #<UnboundMethod: C#bar(foo)() t.rb:2>

p $mfoo == $mbar #=> true
```




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

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

* [ruby-core:111106] [Ruby master Feature#18798] `UnboundMethod#==` with inherited classes
  2022-05-24  1:55 [ruby-core:108659] [Ruby master Bug#18798] `UnboundMethod#==` with inherited classes ko1 (Koichi Sasada)
                   ` (12 preceding siblings ...)
  2022-10-06 16:20 ` [ruby-core:110215] " Eregon (Benoit Daloze)
@ 2022-12-01  5:48 ` matz (Yukihiro Matsumoto)
  2022-12-06  9:13 ` [ruby-core:111219] " ko1 (Koichi Sasada)
  14 siblings, 0 replies; 16+ messages in thread
From: matz (Yukihiro Matsumoto) @ 2022-12-01  5:48 UTC (permalink / raw)
  To: ruby-core

Issue #18798 has been updated by matz (Yukihiro Matsumoto).


LGTM.

Matz.


----------------------------------------
Feature #18798: `UnboundMethod#==` with inherited classes
https://bugs.ruby-lang.org/issues/18798#change-100374

* Author: ko1 (Koichi Sasada)
* Status: Open
* Priority: Normal
----------------------------------------
Now `UnboundMethod` for a same method from a superclass and an inherited class are not `==`.

```ruby
class C
  def foo = :C
  $mc = instance_method(:foo)
end

class D < C
  $md = instance_method(:foo)
end

p $mc == $md #=> false
p $mc.owner #=> C
p $mc.owner == $md.owner #=> true
p $mc.source_location == $md.source_location #=> true
p $mc.inspect #=> "#<UnboundMethod: C#foo() t.rb:3>"
p $md.inspect #=> "#<UnboundMethod: D(C)#foo() t.rb:3>"
```

How about to make it `UnboundMethod#==` return true for this case?
Rule: "return true if the UnboundMethod objects point to a same method definition" seems simple.

FYI: On aliased unbound methods point to a same method are `==`.


```ruby
class C
  def foo = :C
  alias bar foo
  $mfoo = instance_method(:foo)
  $mbar = instance_method(:bar)
end

p $mfoo, $mbar
#=> #<UnboundMethod: C#foo() t.rb:2>
#=> #<UnboundMethod: C#bar(foo)() t.rb:2>

p $mfoo == $mbar #=> true
```




-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/

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

* [ruby-core:111219] [Ruby master Feature#18798] `UnboundMethod#==` with inherited classes
  2022-05-24  1:55 [ruby-core:108659] [Ruby master Bug#18798] `UnboundMethod#==` with inherited classes ko1 (Koichi Sasada)
                   ` (13 preceding siblings ...)
  2022-12-01  5:48 ` [ruby-core:111106] " matz (Yukihiro Matsumoto)
@ 2022-12-06  9:13 ` ko1 (Koichi Sasada)
  14 siblings, 0 replies; 16+ messages in thread
From: ko1 (Koichi Sasada) @ 2022-12-06  9:13 UTC (permalink / raw)
  To: ruby-core

Issue #18798 has been updated by ko1 (Koichi Sasada).

Status changed from Open to Closed

https://github.com/ruby/ruby/pull/6855 was merged.

`p String.instance_method(:object_id) == Array.instance_method(:object_id) #=> true`


----------------------------------------
Feature #18798: `UnboundMethod#==` with inherited classes
https://bugs.ruby-lang.org/issues/18798#change-100509

* Author: ko1 (Koichi Sasada)
* Status: Closed
* Priority: Normal
----------------------------------------
Now `UnboundMethod` for a same method from a superclass and an inherited class are not `==`.

```ruby
class C
  def foo = :C
  $mc = instance_method(:foo)
end

class D < C
  $md = instance_method(:foo)
end

p $mc == $md #=> false
p $mc.owner #=> C
p $mc.owner == $md.owner #=> true
p $mc.source_location == $md.source_location #=> true
p $mc.inspect #=> "#<UnboundMethod: C#foo() t.rb:3>"
p $md.inspect #=> "#<UnboundMethod: D(C)#foo() t.rb:3>"
```

How about to make it `UnboundMethod#==` return true for this case?
Rule: "return true if the UnboundMethod objects point to a same method definition" seems simple.

FYI: On aliased unbound methods point to a same method are `==`.


```ruby
class C
  def foo = :C
  alias bar foo
  $mfoo = instance_method(:foo)
  $mbar = instance_method(:bar)
end

p $mfoo, $mbar
#=> #<UnboundMethod: C#foo() t.rb:2>
#=> #<UnboundMethod: C#bar(foo)() t.rb:2>

p $mfoo == $mbar #=> true
```




-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/

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

end of thread, other threads:[~2022-12-06  9:13 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-24  1:55 [ruby-core:108659] [Ruby master Bug#18798] `UnboundMethod#==` with inherited classes ko1 (Koichi Sasada)
2022-05-24  6:40 ` [ruby-core:108662] " sawa (Tsuyoshi Sawada)
2022-05-24 19:18 ` [ruby-core:108674] " jeremyevans0 (Jeremy Evans)
2022-05-24 19:49 ` [ruby-core:108676] " Eregon (Benoit Daloze)
2022-05-24 19:50 ` [ruby-core:108677] " Eregon (Benoit Daloze)
2022-05-25  0:28 ` [ruby-core:108688] [Ruby master Feature#18798] " ko1 (Koichi Sasada)
2022-05-25  0:32 ` [ruby-core:108689] " ko1 (Koichi Sasada)
2022-08-20 19:48 ` [ruby-core:109602] " Eregon (Benoit Daloze)
2022-09-11 10:45 ` [ruby-core:109887] " joel@drapper.me (Joel Drapper)
2022-10-06  6:07 ` [ruby-core:110197] " matz (Yukihiro Matsumoto)
2022-10-06 12:00 ` [ruby-core:110207] " Eregon (Benoit Daloze)
2022-10-06 12:07 ` [ruby-core:110208] " Eregon (Benoit Daloze)
2022-10-06 14:29 ` [ruby-core:110209] " mame (Yusuke Endoh)
2022-10-06 16:20 ` [ruby-core:110215] " Eregon (Benoit Daloze)
2022-12-01  5:48 ` [ruby-core:111106] " matz (Yukihiro Matsumoto)
2022-12-06  9:13 ` [ruby-core:111219] " ko1 (Koichi Sasada)

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).