Bug 19068 – __traits(identifier) returns the wrong string when importing a template from a module
Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2018-07-06T16:41:08Z
Last change time
2018-07-06T20:33:48Z
Assigned to
No Owner
Creator
Atila Neves
Comments
Comment #0 by atila.neves — 2018-07-06T16:41:08Z
/// mod.d
auto identity(T)(T t) { return t; }
///
/// main.d
import mod;
alias identityInt = identity!int;
enum memberName = __traits(identifier, __traits(getMember, main, "identityInt"));
static assert(memberName == "identityInt",
"Expected 'identityInt', got '" ~ memberName ~ "'");
///
The static assert fails, with __traits(identifier) returning "identity" instead of "identityInt".
Comment #1 by simen.kjaras — 2018-07-06T20:33:48Z
An alias is not a real identifier - thinks of it more as like a pointer to the real identifier. This can be verified by doing the exact same as you did in main.d, in mod.d:
auto identity(T)(T t) { return t; }
alias identityInt = identity!int;
static assert(__traits(identifier, identityInt) == "identity");