Comment #0 by verylonglogin.reg — 2013-11-24T01:21:29Z
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.
Comment #1 by robert.schadek — 2024-12-13T18:14:15Z