import std.stdio;
mixin template R() {
~this() { write(1); }
}
struct S {
mixin R;
~this() { write(2); }
}
void main() {
S s;
}
This code compiles OK and prints 21 when it should NOT.
import std.stdio;
mixin template R() {
int a = 1;
void foo() { write(a); }
}
struct S {
mixin R;
void bar() { write(a); }
int a = 2;
}
void main() {
S s;
s.foo();
s.bar();
}
This code also compiles OK and prints 12 when it's strange and bug-prone.
Comment #1 by temtaime — 2014-09-01T11:50:45Z
There's one another issue.
mixin template R() {
void foo() { writeln(1); }
void foo() { writeln(2); }
}
struct S {
mixin R;
}
void main() {
S s;
}
This code compiles OK, but linker error.
Comment #2 by robert.schadek — 2024-12-13T18:25:23Z