The following code results in an Internal error in DMD 2.012: //////// struct Foo { } struct Bar { public Foo opSub(Bar other) { return Foo(); } } void main() { // Removing the following const eliminates the error const Foo test = Foo(); // Causes the error as (Foo + Foo) is undefined auto result = test + (Bar() - Bar()); auto ok1 = test + test; // No error auto ok2 = test + Foo(); // No error } ////////
Simplified test case struct Bar{ } const(Bar) baz() { return Bar(); } void foo() { Bar result = Bar() + baz(); }
/* Root cause: BinExp::typeCombine() is checking for an _exact_ match, but typeMerge() will return success. PATCH: cast.c BinExp::typeCombine(). Compare the immutable versions of the types, instead of the types themselves. if (op == TOKmin || op == TOKadd) { if (t1->ito == t2->ito && (t1->ty == Tstruct || t1->ty == Tclass)) goto Lerror; } */
Fixed dmd 2.032