www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 24501] New: [REG2.107] imported mixin opCmp member function

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

          Issue ID: 24501
           Summary: [REG2.107] imported mixin opCmp member function not
                    found for a < b
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: critical
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: johanengelen weka.io

Testcase requires two files:
```
-- opcmp.d
int opCmp(T, U)(T t, U u);  // When this line is removed the error disappears

mixin template DefineOpCmp() {
    int opCmp(ref const typeof(this) rhs) const {
        return 0;
    }
}

-- testcase.d
//version = NO_IMPORT; // Error disappears when NO_IMPORT is set.

version (NO_IMPORT)
{
    mixin template DefineOpCmp() {
        int opCmp()(auto ref const typeof(this) rhs) const {
            return 0;
        }
    }
    struct A {
        mixin DefineOpCmp;
    }
}
else
{
    struct A {
        import opcmp;
        mixin DefineOpCmp;
    }
}

void foo(const(A) a, const(A) b) {
    auto d = a.opCmp(b); // Works
    pragma(msg, __traits(allMembers, A)); // AliasSeq!("opCmp")
    auto c = a < b; // Error: need member function `opCmp()` for struct
`const(A)` to compare
}
```

 dmd-2.107.1/osx/bin/dmd -c -o- testcase.d opcmp.d
AliasSeq!("opCmp") testcase.d(25): Error: need member function `opCmp()` for struct `const(A)` to compare Compilation succeeds with DMD <= 2.106. --
Apr 14