Thread overview
[Issue 16390] __traits not accepted where a type is expected
Aug 15, 2016
b2.temp@gmx.com
Aug 15, 2016
Lodovico Giaretta
Aug 15, 2016
b2.temp@gmx.com
Aug 15, 2016
Jonathan M Davis
Aug 17, 2016
Ketmar Dark
Aug 17, 2016
Cauterite
Aug 17, 2016
b2.temp@gmx.com
Jul 05
Basile-z
August 15, 2016
https://issues.dlang.org/show_bug.cgi?id=16390

b2.temp@gmx.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |b2.temp@gmx.com

--- Comment #1 from b2.temp@gmx.com ---
This is really common to use typeof() on the result of a __traits()

template ParentType(T)
{
    alias ParentType = typeof(__traits(parent, T));
}

--
August 15, 2016
https://issues.dlang.org/show_bug.cgi?id=16390

--- Comment #2 from Lodovico Giaretta <lodovico@giaretart.net> ---
(In reply to b2.temp from comment #1)
> This is really common to use typeof() on the result of a __traits()
> 
> template ParentType(T)
> {
>     alias ParentType = typeof(__traits(parent, T));
> }

If this was meant to be a workaround, it doesn't seem to work for me (the trait returns a type, while typeof expects an expression).

If it was meant to be another situation where __traits should be allowed but are not, it looks like they are currently allowed inside typeof.

--
August 15, 2016
https://issues.dlang.org/show_bug.cgi?id=16390

--- Comment #3 from b2.temp@gmx.com ---
(In reply to Lodovico Giaretta from comment #2)
> (In reply to b2.temp from comment #1)
> If this was meant to be a workaround, it doesn't seem to work for me (the
> trait returns a type, while typeof expects an expression).
> 
> If it was meant to be another situation where __traits should be allowed but are not, it looks like they are currently allowed inside typeof.

Yes, second case, sorry. It clearly doesn't work with the parent __traits.

--
August 15, 2016
https://issues.dlang.org/show_bug.cgi?id=16390

Jonathan M Davis <issues.dlang@jmdavisProg.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |issues.dlang@jmdavisProg.co
                   |                            |m

--- Comment #4 from Jonathan M Davis <issues.dlang@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.

--
August 17, 2016
https://issues.dlang.org/show_bug.cgi?id=16390

Ketmar Dark <ketmar@ketmar.no-ip.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ketmar@ketmar.no-ip.org

--
August 17, 2016
https://issues.dlang.org/show_bug.cgi?id=16390

Cauterite <cauterite@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |cauterite@gmail.com

--- Comment #5 from Cauterite <cauterite@gmail.com> ---
related: https://issues.dlang.org/show_bug.cgi?id=7804

--
August 17, 2016
https://issues.dlang.org/show_bug.cgi?id=16390

b2.temp@gmx.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|b2.temp@gmx.com             |

--
February 28
https://issues.dlang.org/show_bug.cgi?id=16390

moonlightsentinel@disroot.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |moonlightsentinel@disroot.o
                   |                            |rg

--
February 28
https://issues.dlang.org/show_bug.cgi?id=16390

moonlightsentinel@disroot.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|enhancement                 |minor

--
July 05
https://issues.dlang.org/show_bug.cgi?id=16390

Basile-z <b2.temp@gmx.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |b2.temp@gmx.com
         Resolution|---                         |FIXED

--- Comment #6 from Basile-z <b2.temp@gmx.com> ---
This syntax works nowadays. it was the same as issue 7804 btw

--