Bug 10549 – Default object equality test not properly implemented
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P3
Component
druntime
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-07-05T04:46:49Z
Last change time
2023-12-29T03:08:53Z
Assigned to
No Owner
Creator
Cauterite
Comments
Comment #0 by cauterite — 2013-07-05T04:46:49Z
In the base object class ("Object") the opEquals overload (which is inherited as the default EqualExpression operation for objects) does not appear to be implemented the way it is described.
The function is defined in object_.d (http://github.com/D-Programming-Language/druntime/blob/master/src/object_.d) as this:
/**
* Returns !=0 if this object does have the same contents as obj.
*/
bool opEquals(Object o)
{
return this is o;
}
(I'm not exactly sure what "!=0" is supposed to mean there, but I'll take it to mean "true").
As I understand it, the "is" operator tests whether two object references refer to the same instance, not whether "this object does have the same contents as obj".
This also contradicts the official description of EqualExpression (http://dlang.org/expression.html#EqualExpression):
"For class objects, the == and != operators compare the contents of the objects."
Clearly, this functionality is not satisfied by an IdentityExpression.
Perhaps something like "this.tupleof == o.tupleof" would be more appropriate?