www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 11557] New: Can't compare `const`/`immutable` classes

reply d-bugmail puremagic.com writes:
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 puremagic.com
        ReportedBy: verylonglogin.reg gmail.com



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: -------
Nov 19 2013
next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11557




01:14:09 MSK ---
A workaround for `std.typecons.Tuple` regression:
https://github.com/D-Programming-Language/phobos/pull/1707

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 19 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11557





 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. -- Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Nov 20 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11557




19:31:13 MSK ---

 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. -- Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Nov 20 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11557






 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 -- Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Nov 21 2013
prev sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11557


Denis Shelomovskij <verylonglogin.reg gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|rejects-valid, wrong-code   |
            Summary|Can't compare               |Add ability to compare
                   |`const`/`immutable` classes |`const`/`immutable` classes
           Severity|regression                  |enhancement



12:56:24 MSK ---
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.

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