Bug 7809 – __traits(getMember can be used with a type although the spec says it cannot
Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P2
Component
dlang.org
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-04-02T03:07:00Z
Last change time
2013-01-08T12:52:23Z
Assigned to
nobody
Creator
simendsjo
Comments
Comment #0 by simendsjo — 2012-04-02T03:07:54Z
struct S {
int i;
}
is( typeof(__traits(getMember, S, "i")) == int ) // works
The spec, on the other hand, says it cannot be used on non-static fields. That's my interpretation.
http://dlang.org/traits.html#getMember
Comment #1 by andrej.mitrovich — 2013-01-08T12:52:23Z
No, the error is in the assignment:
struct S
{
int i;
}
void main()
{
__traits(getMember, S, "i") = 1;
}
Error: need 'this' to access member i
The trait docs specifically state that all the trait does is forms an expression.
But I don't think we even need it anymore since we can use string mixins, although it has to be around for backwards-compatibility.