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?
Comment #1 by cauterite — 2016-08-19T22:11:39Z
this is really a documentation issue; pull request: https://github.com/dlang/dlang.org/pull/1441
Comment #2 by github-bugzilla — 2016-08-28T14:36:59Z
Commit pushed to master at https://github.com/dlang/dlang.org https://github.com/dlang/dlang.org/commit/cbd6d46b0034eb0b4757c693a71566d64d19a850 default opEquals does not compare object contents this documents the behaviour more clearly, addressing issue 10549
Comment #3 by github-bugzilla — 2016-10-01T11:45:47Z
Commit pushed to stable at https://github.com/dlang/dlang.org https://github.com/dlang/dlang.org/commit/cbd6d46b0034eb0b4757c693a71566d64d19a850 default opEquals does not compare object contents