Bug 18118 – Operator overloading fails to follow aliasing rules of mixin templates

Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2017-12-24T12:13:04Z
Last change time
2024-12-13T18:55:43Z
Assigned to
No Owner
Creator
Benjamin Schaaf
Moved to GitHub: dmd#19353 →

Comments

Comment #0 by ben.schaaf — 2017-12-24T12:13:04Z
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"; } ```
Comment #1 by robert.schadek — 2024-12-13T18:55:43Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/19353 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB