December 17, 2022 [Issue 12424] Cannot do qualifier-overload with mixin template. | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=12424 Iain Buclaw <ibuclaw@gdcproject.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Priority|P2 |P3 -- |
June 29, 2023 [Issue 12424] Cannot do qualifier-overload with mixin template. | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=12424 RazvanN <razvan.nitu1305@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED CC| |razvan.nitu1305@gmail.com Resolution|--- |INVALID --- Comment #1 from RazvanN <razvan.nitu1305@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 } ``` -- |
Copyright © 1999-2021 by the D Language Foundation