Bug 11557 – Add ability to compare `const`/`immutable` classes

Status
NEW
Severity
enhancement
Priority
P4
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-11-19T13:08:50Z
Last change time
2024-12-13T18:14:06Z
Assigned to
No Owner
Creator
Denis Shelomovskii
Moved to GitHub: dmd#17627 →

Comments

Comment #0 by verylonglogin.reg — 2013-11-19T13:08:50Z
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.
Comment #1 by verylonglogin.reg — 2013-11-19T13:14:09Z
A workaround for `std.typecons.Tuple` regression: https://github.com/D-Programming-Language/phobos/pull/1707
Comment #2 by k.hara.pg — 2013-11-20T01:26:06Z
(In reply to comment #0) > 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. Why this issue is marked as "regression"? As far as I know, the code you shown had never worked correctly.
Comment #3 by verylonglogin.reg — 2013-11-20T07:31:13Z
(In reply to comment #2) > Why this issue is marked as "regression"? As far as I know, the code you shown > had never worked correctly. Associative arrays use `TypeInfo.compare` and `std.typecons.Tuple` has its `opCmp` with by element comparison for a long time. As `Tuple`-s stopped working as AA keys (it worked at least a year ago) I decided it was a compiler change. If it's not please remove the REGRESSION status.
Comment #4 by k.hara.pg — 2013-11-21T07:30:09Z
(In reply to comment #3) > (In reply to comment #2) > > Why this issue is marked as "regression"? As far as I know, the code you shown > > had never worked correctly. > > Associative arrays use `TypeInfo.compare` and `std.typecons.Tuple` has its > `opCmp` with by element comparison for a long time. As `Tuple`-s stopped > working as AA keys (it worked at least a year ago) I decided it was a compiler > change. If it's not please remove the REGRESSION status. See my comment in your PR. To me the old worked behavior was essentially wrong, and I think it should be kept broken until class const correctness will be fixed. https://github.com/D-Programming-Language/phobos/pull/1707#issuecomment-28992632
Comment #5 by verylonglogin.reg — 2013-11-24T00:56:24Z
Filed Issue 11588 for inconsistency in abilities to compare `const`/`immutable` classes and Issue 11591 for Phobos regression. This issue is a request to add ability to compare `const`/`immutable` classes just like currently allowed testing for equality. It will fix Issue 11588 if accepted.
Comment #6 by robert.schadek — 2024-12-13T18:14:06Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/17627 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB