Jump to page: 1 2
Thread overview
[Issue 13372] traits parent does not work on eponymous templates
[Issue 13372] traits parent shows template function as its own parent
Aug 24, 2014
Ellery Newcomer
Jan 25, 2015
Mike
Nov 05, 2016
b2.temp@gmx.com
Nov 05, 2016
b2.temp@gmx.com
Nov 05, 2016
b2.temp@gmx.com
Aug 23, 2017
Mike
Jan 29, 2018
Mike Franklin
Mar 21, 2020
Basile-z
May 24, 2020
Adam D. Ruppe
Dec 17, 2022
Iain Buclaw
August 24, 2014
https://issues.dlang.org/show_bug.cgi?id=13372

Ellery Newcomer <ellery-newcomer@utulsa.edu> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|enhancement                 |normal

--
January 25, 2015
https://issues.dlang.org/show_bug.cgi?id=13372

Mike <slavo5150@yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |slavo5150@yahoo.com

--- Comment #1 from Mike <slavo5150@yahoo.com> ---
Looks like this might be the same as Issue 12496

--
February 16, 2015
https://issues.dlang.org/show_bug.cgi?id=13372

sinkuupump@gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Blocks|                            |14149

--
November 05, 2016
https://issues.dlang.org/show_bug.cgi?id=13372

b2.temp@gmx.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |b2.temp@gmx.com
            Summary|traits parent shows         |traits parent does not work
                   |template function as its    |on eponymous templates
                   |own parent                  |
           Severity|normal                      |major

--- Comment #2 from b2.temp@gmx.com ---
=========
import std.meta;

template Parent(T)
{
    alias Parent = AliasSeq!(__traits(parent, T))[0];
}

unittest
{
    class A(T){}
    static assert(A!int.stringof != Parent!(A!int).stringof);
November 05, 2016
https://issues.dlang.org/show_bug.cgi?id=13372

b2.temp@gmx.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Hardware|x86_64                      |All
                 OS|Linux                       |All

--
November 05, 2016
https://issues.dlang.org/show_bug.cgi?id=13372

--- Comment #3 from b2.temp@gmx.com ---
Strangely enough this bug can lead to think that we can detect an eponymous template:

==========
template isTemplateInstance(alias T : Base!Args, alias Base, Args...)
{
    enum isTemplateInstance = is(typeof(T));
}

template isTemplateInstance(T : Base!Args, alias Base, Args...)
{
    enum isTemplateInstance = is(T);
}

template isTemplateInstance(T)
{
    enum isTemplateInstance = false;
}

template isTemplateInstance(alias T)
{
    enum isTemplateInstance = isTemplateInstance!(typeof(T));
}

template isEponymousTemplate(T)
{
    static if (is(T == class) || is(T == interface) || is(T == struct) || is(T
== union))
    {
        enum p = __traits(parent, T).stringof == T.stringof;
        enum isEponymousTemplate = p && isTemplateInstance!T;
    }
    else
        enum isEponymousTemplate = false;
}

unittest
{
    class A(T){}
    struct B(T){}
    static assert(isEponymousTemplate!(A!int));
    static assert(isEponymousTemplate!(B!int));
    static assert(!isEponymousTemplate!int);
    template C(T)
    {
        class C{}
    }
    static assert(isEponymousTemplate!(C!int));
}

unittest
{
    template A(T)
    {
        class A{}
    }
    static assert(isEponymousTemplate!(A!int));

    template B(T)
    {
        class A{}
    }
    static assert(!isEponymousTemplate!(B!int.A));

    class C(T){}
    static assert(!isEponymousTemplate!int);

    A!int a;
    static assert(isEponymousTemplate!a);
}
==========

Indeed we can detect it but we can't get the parent !
What's happen is that "isEponymousTemplate" yield true for an eponymous
template because the template itself points to its argument !

--
August 23, 2017
https://issues.dlang.org/show_bug.cgi?id=13372

Mike <slavo5150@yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://issues.dlang.org/sh
                   |                            |ow_bug.cgi?id=12496

--
January 29, 2018
https://issues.dlang.org/show_bug.cgi?id=13372

--- Comment #4 from Mike Franklin <slavo5150@yahoo.com> ---
(In reply to Basile B. from comment #2)
> =========
> import std.meta;
> 
> template Parent(T)
> {
>     alias Parent = AliasSeq!(__traits(parent, T))[0];
> }
> 
> unittest
> {
>     class A(T){}
>     static assert(A!int.stringof != Parent!(A!int).stringof);
> }
> =========
> 
> yields: Error: static assert  ("A!int" != "A!int") is false
> 
> 
> the longer form
> 
> =========
> import std.meta;
> 
> template Parent(T)
> {
>     alias Parent = AliasSeq!(__traits(parent, T))[0];
> }
> 
> unittest
> {
>     template B(T){class B{}}
>     alias T = B!int;
>     static assert(is(T));
>     static assert(T.stringof != Parent!T.stringof);
> }
> =========
> 
> yields: Error: static assert  ("B!int" != "B!int") is false

These two tests now pass in v2.078.1

--
March 21, 2020
https://issues.dlang.org/show_bug.cgi?id=13372

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

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

--
May 24, 2020
https://issues.dlang.org/show_bug.cgi?id=13372

Adam D. Ruppe <destructionator@gmail.com> changed:

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

--- Comment #5 from Adam D. Ruppe <destructionator@gmail.com> ---
Here's something related I just came upon:

template wrap(string foo) {
        enum wrap = foo;
}
pragma(msg, __traits(parent, wrap!"lol")); // says lol
pragma(msg, __traits(parent, __traits(parent, wrap!"lol"))); // says argument
"lol" has no parent


So in the first one, it appears it evaluates to the outer template which is then instantly evaluated back to the enum literal. Then the second one sees the literal and says literals have no parents.

Quite bizarre indeed.

--
« First   ‹ Prev
1 2