[Issue 11557] New: Can't compare `const`/`immutable` classes

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Nov 19 13:09:00 PST 2013


https://d.puremagic.com/issues/show_bug.cgi?id=11557

           Summary: Can't compare `const`/`immutable` classes
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: rejects-valid, wrong-code
          Severity: regression
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: verylonglogin.reg at gmail.com


--- Comment #0 from Denis Shelomovskij <verylonglogin.reg at gmail.com> 2013-11-20 01:08:50 MSK ---
Currently because of Issue 1824 `opEquals` and `opCmp` aren't `const`. It's bad
but works if these functions are implemented carefully.

Current dmd rejects `opCmp` call:
---
const Object o1, o2;
assert(o1 == o2); // ok, calls `opEquals`
assert(o1 <= o2); // Error: mutable method object.Object.opCmp is not callable
using a const object
---

As a result e.g. `std.typecons.Tuple`-s with classes don't have `opCmp` and
fails with "TypeInfo.compare is not implemented" `Error` if used as an
associative array key. Error at runtime is really nasty.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list