Bug 11588 – Inconsistent abilities to compare `const`/`immutable` classes

Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-11-23T23:50:11Z
Last change time
2024-12-13T18:14:10Z
Assigned to
No Owner
Creator
Denis Shelomovskii
Moved to GitHub: dmd#18716 →

Comments

Comment #0 by verylonglogin.reg — 2013-11-23T23:50:11Z
Currently because of Issue 1824 `opEquals` and `opCmp` aren't `const`. dmd rejects `opCmp` calls but accepts `opEquals` ones: --- class C { int i; override bool opEquals(Object o) { ++i; return true;} override int opCmp(Object c) { ++i; return 0; } } void main() { const c1 = new C, c2 = new C; assert(c1 == c2); // ok, calls `opEquals` assert(c1 <= c2); // Error: mutable method main.C.opCmp is not callable using a const object } --- Both should be either accepted or rejected. See Issue 11557 for proposal to allow `opCmp` calls too.
Comment #1 by robert.schadek — 2024-12-13T18:14:10Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/18716 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB