Bug 6776 – attributes injected via pure template mixin but not class mixin
Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
Linux
Creation time
2011-10-06T04:01:00Z
Last change time
2012-02-12T15:52:33Z
Assigned to
nobody
Creator
dlang
Comments
Comment #0 by dlang — 2011-10-06T04:01:43Z
import std.stdio;
class C(T) {
T val;
}
class D {
mixin C!bool;
}
int main() {
auto d = new D;
writeln(d.val);
return 0;
}
This fails to compile (no val in D), yet if defining C as:
template C(T) {
T val;
}
It works.
This is rather silly as it forces me to write wrapper classes that forward to a template.
Comment #1 by smjg — 2012-02-12T15:52:33Z
There's no such thing as a class mixin. One mixes in template instances, not classes. Since a class template is just syntactic sugar for a template with an eponymous class as its only member, the compiler expands it to:
class D {
class C {
bool val;
}
}
So of course there's no such thing as d.val.