[Issue 16390] __traits not accepted where a type is expected
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Mon Aug 15 12:23:19 PDT 2016
https://issues.dlang.org/show_bug.cgi?id=16390
Jonathan M Davis <issues.dlang at jmdavisProg.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |issues.dlang at jmdavisProg.co
| |m
--- Comment #4 from Jonathan M Davis <issues.dlang at jmdavisProg.com> ---
Similarly,
template members(T)
{
alias members = __traits(allMembers, T);
}
doesn't work, whereas
template members(T)
{
alias members = AliasSeq!(__traits(allMembers, T));
}
does. And that's even more bizarre when you consider not only that AliasSeq is
supposed to be equivalent to the "tuple" that the compiler uses for stuff like
the result of __traits(allMembers, T), but this code
import std.meta;
template members(T)
{
alias members = AliasSeq!(__traits(allMembers, T));
}
struct S
{
int i;
string s;
}
void main()
{
pragma(msg, __traits(allMembers, S));
pragma(msg, AliasSeq!(__traits(allMembers, S)));
pragma(msg, members!S);
}
prints
tuple("i", "s")
tuple("i", "s")
tuple("i", "s")
meaning that all 3 are equivalent as far as pragma(msg, ...) is concerned. And
changing main to
pragma(msg, typeof(__traits(allMembers, S)));
pragma(msg, typeof(AliasSeq!(__traits(allMembers, S))));
pragma(msg, typeof(members!S));
results in
(string, string)
(string, string)
(string, string)
So, it really seems like the fact that the result of __traits can't be aliased
is a bug. And if it's not a bug, then it's an unnecessary (and confusing)
inconsistency, and IMHO, it really should be fixed.
--
More information about the Digitalmars-d-bugs
mailing list