www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 11592] New: Inconsistent comparisons of classes between `opCmp` and `opEquals` calls


           Summary: Inconsistent comparisons of classes between `opCmp`
                    and `opEquals` calls
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: verylonglogin.reg gmail.com

--- Comment #0 from Denis Shelomovskij <verylonglogin.reg gmail.com> 2013-11-24
13:21:29 MSK ---
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.

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