[Issue 18944] Mixing in new overloads of a function in an object won't resolve the overloads correctly

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Jun 5 09:32:52 UTC 2018


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

Simen Kjaeraas <simen.kjaras at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |simen.kjaras at gmail.com
         Resolution|---                         |INVALID

--- Comment #1 from Simen Kjaeraas <simen.kjaras at gmail.com> ---
Here's a reduced example showing the same issue:

mixin template FooOne() {
    void foo(ref int val) {}
}

mixin FooOne!();

void foo(ref float val) {}

unittest {
    int n;
// Error: function foo.foo(ref float val) is not callable using argument types
(int)
    foo(n);
}

This issue is covered in the documentation of the template mixin feature
(https://dlang.org/spec/template-mixin.html#mixin_scope):

"1. If the name of a declaration in a mixin is the same as a declaration in the
surrounding scope, the surrounding declaration overrides the mixin one"

It also explains how to fix the problem:

"5. Alias declarations can be used to overload together functions declared in
different mixins"

In your example that fix would be:

    mixin FooOne!() f1;
    mixin FooTwo!() f2;

    alias foo = f1.foo;
    alias foo = f2.foo;

--


More information about the Digitalmars-d-bugs mailing list