Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Operator overloading fails to follow aliasing rules of mixin templates #19353

Open
dlangBugzillaToGithub opened this issue Dec 24, 2017 · 0 comments
Labels

Comments

@dlangBugzillaToGithub
Copy link

Benjamin Schaaf reported this on 2017-12-24T12:13:04Z

Transferred from https://issues.dlang.org/show_bug.cgi?id=18118

Description

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";
}

```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant