Bug 19708 – Can't use __traits(getAttributes, ...)[...] as a type

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2019-02-28T14:56:20Z
Last change time
2020-03-21T03:56:36Z
Keywords
pull, rejects-valid
Assigned to
No Owner
Creator
moonlightsentinel

Comments

Comment #0 by moonlightsentinel — 2019-02-28T14:56:20Z
The result of __traits(getAttributes, ...)[..] can't be used as a type. Instead dmd produces some misleading error messages depending on the context. Consider the following example: --------------- module test; struct Foo {} @Foo int bar; alias TR = __traits(getAttributes, bar); /* Error: TR[0] is not a type TR[0] a; */ /* Error: type Foo is not an expression typeof(TR[0]) b; */ /* alias `test.c` cannot alias an expression Foo alias c = TR[0]; */ /* __traits(getAttributes, bar) does not give a valid type alias d = __traits(getAttributes, bar)[0]; */ // Possible workaround using a tuple alias Tuple(T...) = T; alias TP = Tuple!(__traits(getAttributes, bar)); TP[0] e; --------------- Probably related to issue 16390
Comment #1 by b2.temp — 2019-07-05T17:14:39Z
It was a dup of 7804, which is implemented now.
Comment #2 by b2.temp — 2019-07-05T17:39:19Z
sorry i missed that most failing code is commented. There's indeed a problem with direct __trait aliasing. Tuples processing (as obtained by __trait(getAttributes) is incomplete.
Comment #3 by b2.temp — 2019-07-06T10:42:43Z
Most of the fix is easy but the part involving an index is more complicated because there's a kind of precedence problem: alias d = __traits(getAttributes, bar)[0]; is more like (using parens to explain even if not valid) alias d = IndexedBy(__traits(getAttributes, bar), 0); The internal wrapper is itself wrapped in the type that stores the index so a flag indicating if symbols are allowed when processing the trait is never set. That's why there's the spurious error message about giving a type.
Comment #4 by dlang-bot — 2019-07-06T11:30:53Z
@Basile-z created dlang/dmd pull request #10143 "fix issue 19708 - Can't use __traits(getAttributes, ...)[...] as a type" fixing this issue: - fix issue 19708 - Can't use __traits(getAttributes, ...)[...] as a type https://github.com/dlang/dmd/pull/10143
Comment #5 by dlang-bot — 2019-07-06T11:39:41Z
@Basile-z created dlang/dmd pull request #10144 "fix issue 19708 - Can't use __traits(getAttributes, ...)[...] as a type" fixing this issue: - fix issue 19708 - Can't use __traits(getAttributes, ...)[...] as a type https://github.com/dlang/dmd/pull/10144
Comment #6 by dlang-bot — 2019-07-06T14:29:33Z
dlang/dmd pull request #10144 "fix issue 19708 - Can't use __traits(getAttributes, ...)[...] as a type" was merged into stable: - caf888bd949a119c2136be6ee7011eedbf3f5f0b by Basile Burg: fix issue 19708 - Can't use __traits(getAttributes, ...)[...] as a type https://github.com/dlang/dmd/pull/10144