---- import std.stdio; mixin template foo() { this() { writefln("a"); } } class A { mixin foo!(); this() { writefln("b"); } version(ErrorsAsExpected) { this() { writefln("c"); } } } void main() { A a = new A; } ---- When the above is compiled, no error is given, however when -version=ErrorsAsExpected is given an error occurs. Tested with dmd 2.057.
I forgot to mention, when ErrorsAsExpected is not defined, this prints b, the constructor from the mixin is disregarded.
This is by design: Spec: Mixin Scope The declarations in a mixin are 'imported' into the surrounding scope. 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.
Imho it isn't right though to silently accept this. There should at least be a warning that the code doesn't work as the general programmer would expect and maybe give a hint that you can achieve overload resolution with an additional alias. Otherwise it heavily depends on your code if you are lucky and get an error message like in http://d.puremagic.com/issues/show_bug.cgi?id=3332 or unexpected behavior. This is not limited to constructors. Overload resolution in general isn't easily possible. I have to resort to ugly string mixins just because of this.
PS E:\DigitalMars\dmd2\samples> rdmd bug.d b PS E:\DigitalMars\dmd2\samples> rdmd -version=ErrorsAsExpected bug.d bug.d(22): Error: constructor bug.A.this called with argument types: (()) matches both: bug.A.this() and: bug.A.this() PS E:\DigitalMars\dmd2\samples>
*** This issue has been marked as a duplicate of issue 3332 ***