[Issue 16657] New: [The D Bug Tracker]

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Wed Nov 2 08:22:15 PDT 2016


https://issues.dlang.org/show_bug.cgi?id=16657

          Issue ID: 16657
           Summary: [The D Bug Tracker]
           Product: D
           Version: D2
          Hardware: All
               URL: http://dlang.org/
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P3
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: eyal at weka.io

When adding an "alias this" to a type, the automatic opEquals and opCmp that
compare the object lexicographically are removed and instead only the alias
this portion of the type is compared via its opEquals/opCmp.

struct A {
    int x;
}

struct B {
    A a, b;
}
static assert(B(A(1), A(1)) != B(A(1), A(2))); // Works

struct C {
    A a, b;
    alias a this;
}
static assert(C(A(1), A(1)) != C(A(1), A(2))); // Fails!

Adding alias this should NOT cause a preference for the base type's
comparators.

--


More information about the Digitalmars-d-bugs mailing list