Bug 11592 – Inconsistent comparisons of classes between `opCmp` and `opEquals` calls

Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-11-24T01:21:29Z
Last change time
2024-12-13T18:14:15Z
Assigned to
No Owner
Creator
Denis Shelomovskii
Moved to GitHub: dmd#18718 →

Comments

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
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/18718 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB