/*
basic type expected, not __traits
no identifier for declarator int
semicolon expected to close alias declaration
Declaration expected, not '__traits'
*/
template f(T) {
alias __traits(allMembers, T) f;
}
// ok
template g(T) {
enum members = __traits(allMembers, T);
alias members g;
}
Tested on 2.059 trunk.
Comment #1 by andrej.mitrovich — 2012-12-10T15:42:43Z
*** Issue 5877 has been marked as a duplicate of this issue. ***
Comment #2 by andrej.mitrovich — 2013-02-21T15:08:20Z
This bug is extremely annoying in metaprogramming. I can't fix it, the parser in DMD is implemented in a bizarre way. Anyone know what it would take to make this work?
Comment #3 by andrej.mitrovich — 2013-05-02T03:31:07Z
*** Issue 10014 has been marked as a duplicate of this issue. ***
Comment #4 by andrej.mitrovich — 2013-05-02T03:31:49Z
Test-case from Issue 10014:
----
class C { int i; }
static assert(is(__traits(parent, C.i) == C)); // Error
----
Comment #5 by simen.kjaras — 2018-03-13T07:28:11Z
*** Issue 17571 has been marked as a duplicate of this issue. ***
Comment #6 by simen.kjaras — 2018-03-13T07:28:12Z
*** Issue 18601 has been marked as a duplicate of this issue. ***
Comment #7 by turkeyman — 2018-03-13T08:02:41Z
Plz can has fix?
This is so old!
Comment #8 by uplink.coder — 2018-03-13T09:09:33Z
The issue with this one is that __traits are not considered as types by the parser as they mostly are not.
one approach could be to have an opinion about which __traits can evaluate to types and allow those at parser level.
I may give this a shot but my time is currently limited.
Comment #9 by b2.temp — 2018-03-13T13:47:06Z
I've managed to get it working for types. It has to because the grammar has to changed so that __trait(getMember,...) becomes a BasicType.
To be clear my hacked DMD for
struct Foo{struct A{}}
alias FooA = __traits(getMember, Foo, "A");
pragma(msg, FooA.stringof);
says: "A". Or even
struct Foo{alias MyInt = int;}
alias FooInt = __traits(getMember, Foo, "MyInt");
static immutable FooInt fi = 42;
pragma(msg, fi);
says "42"
Next step is for variables and other symbols.
WIP here: https://github.com/BBasile/dmd/pull/1/files
Comment #10 by b2.temp — 2018-03-14T11:59:32Z
Considering the grammar changes required this is clearly an enhancement.