With DMD 2.065, the following code fails to compile:
import std.stdio;
mixin template Foo(T){
T foo(T a){ return a; }
}
mixin Foo!int g;
mixin Foo!string g;
void main(){
writeln(foo(2));
writeln(foo("a"));
writeln(g.foo(2));
writeln(g.foo("a"));
}
Error: mixin tt.Foo!(string) conflicts with mixin tt.Foo!(int) at tt.d(6)
Similarly if two named mixins occur in different files:
module b;
mixin template Foo(T){
T foo(T a){ return a; }
}
mixin Foo!string g;
// ---
module c;
mixin template Foo(T){
T foo(T a){ return a; }
}
mixin Foo!int g;
// ---
import std.stdio;
import b,c;
void main(){
writeln(foo(2));
writeln(foo("a"));
writeln(g.foo(2));
writeln(g.foo("a"));
}
Error: b.Foo!(string) at b.d(5) conflicts with c.Foo!(int) at c.d(5)
Error: function b.Foo!(string).foo (string a) is not callable using argument types (int)
Error: cannot implicitly convert expression (2) of type int to string
Error: b.Foo!(string) at b.d(5) conflicts with c.Foo!(int) at c.d(5)
Both examples should compile.
Comment #1 by Marco.Leise — 2016-09-17T13:57:34Z
Generally, symbols mixed in at module level conflict. E.g.:
mixin template Preparer()
{
bool isPrepared;
}
when mixed into multiple modules causes conflicts when accessing `isPrepared`. In particular `fully.qualified.module.name.isPrepared` does not help the compiler distinguish the symbols either.
Comment #2 by robert.schadek — 2024-12-13T18:20:10Z