www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 21094] New: [REG2.078] Array equality for struct with class

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

          Issue ID: 21094
           Summary: [REG2.078] Array equality for struct with class member
                    and opCast and alias this
           Product: D
           Version: D2
          Hardware: x86
                OS: Mac OS X
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: druntime
          Assignee: nobody puremagic.com
          Reporter: johanengelen weka.io

This testcase does not compile since 2.078:
```
class C {
    int a;
}
struct S {
    bool isValid;
    C fib;

    inout(C) get() pure  safe  nogc nothrow inout {
        return isValid ? fib : C.init;
    }
    T opCast(T : C)() const { return null; }

    alias get this;
}

auto foo(S[] lhs, S[] rhs) {
    return lhs == rhs;
}
```

The error:
/druntime/src/core/internal/array/equality.d(101): Error: template instance
`opCast!(Object)` does not match template declaration `opCast(T : C)()`
/druntime/src/core/internal/array/equality.d(101): Error: template instance
`opCast!(Object)` does not match template declaration `opCast(T : C)()`
/druntime/src/core/internal/array/equality.d(102): Error: template instance
`opCast!bool` does not match template declaration `opCast(T : C)()`
/druntime/src/core/internal/array/equality.d(102): Error: template instance
`opCast!(Object)` does not match template declaration `opCast(T : C)()`
weka/lib/comparison.d(38): Error: template instance
`core.internal.array.equality.__equals!(S, S)` error instantiating

It appears to be fixed by https://github.com/dlang/druntime/pull/3142 , but
please add this extra testcase. Thanks.

--
Jul 30 2020