[Issue 18118] New: Operator overloading fails to follow aliasing rules of mixin templates
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sun Dec 24 12:13:04 UTC 2017
https://issues.dlang.org/show_bug.cgi?id=18118
Issue ID: 18118
Summary: Operator overloading fails to follow aliasing rules of
mixin templates
Product: D
Version: D2
Hardware: x86_64
OS: Linux
Status: NEW
Severity: normal
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: ben.schaaf at gmail.com
When you have 2 mixin templates that both overload the same operator, you can't
use alias declarations to combine overloads.
Tested on dmd-2.076.1 and dmd-2.073.2
```
mixin template A() {
auto opBinary(string op, T)(T other) if (op == "in") {
return other;
}
}
mixin template B() {
auto opBinary(string op, T)(T other) if (op == "&") {
return other;
}
}
mixin template C() {
mixin A a;
mixin B b;
alias opBinary = a.opBinary;
alias opBinary = b.opBinary;
}
struct Foo {
mixin A a;
mixin B b;
alias opBinary = a.opBinary;
alias opBinary = b.opBinary;
}
struct Bar {
mixin C;
}
struct TestA {
mixin A;
}
struct TestB {
mixin B;
}
void main() {
// These examples work
auto test1 = Foo().opBinary!"in"("foo");
auto test2 = Foo().opBinary!"&"("foo");
auto testa = TestA() in "foo";
auto testb = TestB() & "foo";
// These fail to compile
auto test4 = Foo() in "foo";
auto test5 = Foo() & "foo";
auto test6 = Bar() in "bar";
auto test7 = Bar() & "bar";
}
```
--
More information about the Digitalmars-d-bugs
mailing list