Bug #12684
closedDelegator#eql? missing
Description
There is some strange behavior because Delegator is missing an alias of #eql? to #==
2.3.1 :001 > s = 'test'
=> "test"
2.3.1 :002 > d = SimpleDelegator.new(s)
=> "test"
2.3.1 :003 > d.eql?(d)
=> false
2.3.1 :004 > d == d
=> true
2.3.1 :005 > d.hash == d.hash
=> true
I understand that Delegator
is a BasicObject
and that does not define #eql? method, but this method is being used by Array
r.
For example,
2.3.1 :001 > s = 'test'
=> "test"
2.3.1 :002 > a = [SimpleDelegator.new(s), SimpleDelegator.new(s)]
=> ["test", "test"]
2.3.1 :003 > a[0] == a[1]
=> true
2.3.1 :004 > a.uniq()
=> ["test", "test"]
2.3.1 :005 > a[0].hash == a[1].hash
=> true
Kind of strange behavior, especially reading the documentation.
Now maybe, Array#uniq
should be changed to use #==
instead of #eql?
Updated by giginet (Kohki Miki) almost 8 years ago
I fixed this issue and I added the specs.
Could you check it?
https://github.com/ruby/ruby/pull/1564
https://github.com/ruby/spec/pull/399
Updated by nobu (Nobuyoshi Nakada) almost 8 years ago
- Description updated (diff)
- Backport changed from 2.1: UNKNOWN, 2.2: UNKNOWN, 2.3: UNKNOWN to 2.2: REQUIRED, 2.3: REQUIRED, 2.4: REQUIRED
Seems fine.
Updated by ko1 (Koichi Sasada) over 7 years ago
- Assignee set to nobu (Nobuyoshi Nakada)
Updated by Eregon (Benoit Daloze) over 7 years ago
@nobu (Nobuyoshi Nakada) Any update on this? I think your patch is OK.
Updated by nobu (Nobuyoshi Nakada) over 7 years ago
- Status changed from Open to Closed
Applied in changeset trunk|r59167.
Delegate to eql?
[Fix GH-1564]
- lib/delegate.rb (eql?): Delegate to
eql?
of the inner object.
based on the patch by giginet giginet.net@gmail.com.
[ruby-core:76950] [Bug #12684]
Updated by nagachika (Tomoyuki Chikanaga) about 7 years ago
- Backport changed from 2.2: REQUIRED, 2.3: REQUIRED, 2.4: REQUIRED to 2.2: REQUIRED, 2.3: REQUIRED, 2.4: WONTFIX
I think this is a spec change because of existence of the test in rubyspec about this behavior.
I will change WONTFIX for 2.4. Please tell us if there are any real world application suffered with this issue.