https://d.puremagic.com/issues/show_bug.cgi?id=11592
Summary: Inconsistent comparisons of classes between `opCmp`
and `opEquals` calls
Product: D
Version: D2
Platform: All
OS/Version: All
Status: NEW
Severity: normal
Priority: P2
Component: DMD
AssignedTo: [email protected]
ReportedBy: [email protected]
--- Comment #0 from Denis Shelomovskij <[email protected]> 2013-11-24
13:21:29 MSK ---
Currently `opCmp` is called from current class but `opEquals` is called from
class instance upcasted to `Object`:
---
class C
{
int opCmp(in C) const { return 0; }
bool opEquals(in C) const { return 0; }
}
void main()
{
C c1 = new C, c2 = new C;
assert(c1 <= c2); // ok, calls `C.opCmp`
assert(c1 == c2); // fails, calls `object.opEquals`
}
---
This is because `==` and `!=` are rewritten as call to `object.opEquals` which
calls `Object.opEquals`.
As we are going to remove such functions from `Object` a solution is to make
`object.opEquals` templated by current class types.
--
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------