[Issue 12424] Cannot do qualifier-overload with mixin template.

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Jun 29 10:10:53 UTC 2023


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

RazvanN <razvan.nitu1305 at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |razvan.nitu1305 at gmail.com
         Resolution|---                         |INVALID

--- Comment #1 from RazvanN <razvan.nitu1305 at gmail.com> ---
This is not a bug, but specified behavior. The mixins do insert the functions
correctly, however, each function has it's own nested scope. Those scopes are
actually "imported" in the scope of S, so it's the same as using imports, the
functions are not in the same overload set. The standard look rules are applied
and the for the mutable version of S, both functions match, that's why you get
an ambiguity error (for more info see:
https://dlang.org/spec/template-mixin.html#mixin_scope). To workaround this,
you just need to put the functions in the same overload set:

```
mixin template fooMixin(T)
{
    void foo() //L.3
    {}; 
}

struct S
{
    //insert "void foo()"
    mixin fooMixin!int t;

    //insert "void foo() const"
    const mixin fooMixin!int t2; 

    // create the overload set
    alias foo = t.foo;
    alias foo = t2.foo;                                                         
}

void main()
{
    const(S) sc; 
    S s;
    sc.foo(); //OK
    s.foo(); //OK
}
```

--


More information about the Digitalmars-d-bugs mailing list