July 05, 2013 [Issue 10549] New: Default object equality test not properly implemented | ||||
---|---|---|---|---|
| ||||
http://d.puremagic.com/issues/show_bug.cgi?id=10549 Summary: Default object equality test not properly implemented Product: D Version: D2 Platform: All OS/Version: All Status: NEW Severity: normal Priority: P2 Component: druntime AssignedTo: nobody@puremagic.com ReportedBy: anoneuron@gmail.com --- Comment #0 from anoneuron@gmail.com 2013-07-05 04:46:49 PDT --- 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? -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
Copyright © 1999-2021 by the D Language Foundation