Bug 7804 – Cannot alias __traits directly

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-03-31T06:03:57Z
Last change time
2018-11-11T06:38:36Z
Keywords
pull
Assigned to
No Owner
Creator
simendsjo

Comments

Comment #0 by simendsjo — 2012-03-31T06:03:57Z
/* 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.
Comment #11 by b2.temp — 2018-03-14T17:50:07Z
Comment #12 by b2.temp — 2018-04-30T22:07:42Z
I opted out. Maybe something that can be finished during your next week's hackatlon.
Comment #13 by github-bugzilla — 2018-11-11T06:38:35Z
Commits pushed to master at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/70964b03e2e3e975c76ed26fd293777071ec854e fix issue 7804 - Allow __traits(getMember) as a BasicType https://github.com/dlang/dmd/commit/0427b5724d0e58cae966fd14d23f30758b626d31 Merge pull request #8938 from BBasile/alias-equal-traits fix issue 7804 - Allow __traits(getMember) as a BasicType