Bug 18601 – alias m = __traits(getMember, ...) doesn't work
Status
RESOLVED
Resolution
DUPLICATE
Severity
enhancement
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2018-03-12T19:10:14Z
Last change time
2018-03-13T07:28:12Z
Assigned to
No Owner
Creator
Manu
Comments
Comment #0 by turkeyman — 2018-03-12T19:10:14Z
It's annoying that this doesn't work:
```
struct S
{
int x;
}
void f()
{
S s;
alias m = __traits(getMember, s, "x");
}
```
> Error: basic type expected, not `__traits`
> Error: semicolon expected to close `alias` declaration
I'm pretty sure this could be trivially supported...?
I feel like that __traits statement should be semantically identical to:
alias m = s.x;
The __traits(getMember) docs make you feel like that's true...
Comment #1 by issues.dlang — 2018-03-13T00:44:25Z
It can be trivially worked around by wrapping the __traits expression in a std.meta.Alias, but I don't understand why that should be necessary. Certainly, it seems like it shouldn't be necessary.
Comment #2 by turkeyman — 2018-03-13T00:56:35Z
Indeed, I am aware of the workaround, but that doesn't make the problem any better.
People don't expect to have to wrap a thing in an Alias!() statement for no logical reason... so it's just a gotcha that looks bad to new users (case in question).
Comment #3 by turkeyman — 2018-03-13T01:16:35Z
I'm trolling my Blizzard colleagues by trying to get them interested in D... but the quality bar needs to be a LOT higher here to be convincing compared to my former workplaces.
Comment #4 by simen.kjaras — 2018-03-13T07:28:12Z
*** This issue has been marked as a duplicate of issue 7804 ***