Project

General

Profile

Actions

Bug #7045

closed

DelegateClass array subtraction

Added by Anonymous over 11 years ago. Updated over 11 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 2.0.0dev (2012-09-21) [x86_64-darwin11.4.0]
Backport:
[ruby-core:47633]

Description

When I have an array that contains an array that contains a single instance of a class that inherits from DelegateClass, and I subtract from that array another array containing another array containing the same nested object, Ruby does not return an empty array. I've attached a test file that should replicate the one failing scenario, as well as some complimentary scenarios that do work as I had expected.


Files

delegate_class_test.rb (555 Bytes) delegate_class_test.rb Anonymous, 09/22/2012 02:56 AM

Related issues 1 (0 open1 closed)

Is duplicate of Ruby master - Bug #6408: DelegateClass#eql? and <=> don't work as expectedClosedtenderlovemaking (Aaron Patterson)Actions

Updated by Anonymous over 11 years ago

The failing test is "test_nested_array_subtraction"

Updated by marcandre (Marc-Andre Lafortune) over 11 years ago

The issue is that most classes' method eql? return false unless the object has the same class

require 'delegate'
o = SimpleDelegator.new(42)
o.eql?(o) # => false
# because the eql? is delegated, and
42.eql?(o) # => false

Updated by Anonymous over 11 years ago

I'm not sure that explains it. The first and third tests pass, and all of them used to pass in 1.8.

Updated by Anonymous over 11 years ago

This seems like a duplicate of http://bugs.ruby-lang.org/issues/6408. Not sure how to close this, but it can be closed.

Updated by marcandre (Marc-Andre Lafortune) over 11 years ago

  • Status changed from Open to Closed

I'm not sure that explains it. The first and third tests pass

Sorry, I didn't focus on the other tests. So the reason the first and third test pass is that Hash lookup uses hash and eql?, except that if the objects are the same (same object_id), it assumes they are eql?. I'm assuming this is for performance reasons, since it should be true for almost all objects. It isn't for NaN, though, so this can give strange results:

n = 0.0/0
n.eql?(n) # => false
h = {n => :nan}
h[n] # => :nan (exact same object)
h[0.0/0] # => nil (since another float was constructed)

The first test passes because a hash is built with obj as the key, and afterwards lookup succeeds for obj as it is the exact same object.
The last test passes for the same reason, because the key and the lookup are done on the exact same array [obj].
The second test fails because the key and the lookup are not the same object (different object_id), so eql? is called and [obj].eql? [obj] returns false.

and all of them used to pass in 1.8.

In 1.8, eql? was not delegated at all. So you had obj.eql?(obj) # => true, but on the other hand SimpleDelegator.new(42).eql?(42) # => false.

This seems like a duplicate of http://bugs.ruby-lang.org/issues/6408. Not sure how to close this, but it can be closed.

Indeed, if 6408 was fixed, we'd have obj.eql? obj return true and all your tests would pass. I'll close this then.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0