www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - fullyQualifiedName fails on template

reply =?UTF-8?B?IsOYaXZpbmQi?= <oivind.loe gmail.com> writes:
Is fullyQualifiedName supposed to work on templates? The
following fails:

struct MsgPack(T ...) {
}

struct TestPoint {
    float x, y;
}

alias TestPack = MsgPack!TestPoint;

void main() {
	
	import std.traits;
	import std.stdio;
	
	//writeln(fullyQualifiedName!TestPack);	          //Fails
	writeln(fullyQualifiedName!(MsgPack!TestPoint));  //Fails
}


with error:

/opt/compilers/dmd2/include/std/traits.d(340): Error: forward
reference of variable parentPrefix
/opt/compilers/dmd2/include/std/traits.d(501): Error: template
instance
std.traits.fullyQualifiedNameImplForSymbols!(MsgPack!(TestPoint))
error instantiating
/opt/compilers/dmd2/include/std/traits.d(292):
instantiated from here:
fullyQualifiedNameImplForTypes!(MsgPack!(TestPoint), false,
false, false, false)
/d112/f728.d(19):        instantiated from here:
fullyQualifiedName!(MsgPack!(TestPoint))
/opt/compilers/dmd2/include/std/traits.d(292): Error: template
instance
std.traits.fullyQualifiedNameImplForTypes!(MsgPack!(TestPoint),
false, false, false, false) error instantiating
/d112/f728.d(19):        instantiated from here:
fullyQualifiedName!(MsgPack!(TestPoint))
/d112/f728.d(19): Error: template instance
std.traits.fullyQualifiedName!(MsgPack!(TestPoint)) error
instantiating
Jan 23 2014
next sibling parent "Dicebot" <public dicebot.lv> writes:
https://d.puremagic.com/issues/show_bug.cgi?id=10502
Jan 24 2014
prev sibling parent reply Timon Gehr <timon.gehr gmx.ch> writes:
On 01/24/2014 03:20 AM, "Øivind" wrote:
 Is fullyQualifiedName supposed to work on templates?
Yes.
 The following fails:
Compiler bug.
Jan 24 2014
parent reply "Dicebot" <public dicebot.lv> writes:
On Friday, 24 January 2014 at 09:38:24 UTC, Timon Gehr wrote:
 The following fails:
Compiler bug.
More like "Phobos bug that is very hard to fix because of compiler bug"
Jan 24 2014
next sibling parent reply "Martin Cejp" <minexew gmail.com> writes:
On Friday, 24 January 2014 at 09:40:32 UTC, Dicebot wrote:
 On Friday, 24 January 2014 at 09:38:24 UTC, Timon Gehr wrote:
 The following fails:
Compiler bug.
More like "Phobos bug that is very hard to fix because of compiler bug"
The bug hasn't been updated in half a year. Can we help with fixing it? It's quite an issue if you want to copy a method with a mixin and you can't reliably stringify the return type.
Jan 24 2014
parent reply "David Nadlinger" <code klickverbot.at> writes:
On Friday, 24 January 2014 at 14:08:45 UTC, Martin Cejp wrote:
 It's quite an issue if you want to copy a method with a mixin 
 and you can't reliably stringify the return type.
In general, you can't reliably stringify types for use in string mixins anyway. Just insert ReturnType!(…) or whatever you need directly into your mixin string. Dvid
Jan 24 2014
parent "Martin Cejp" <minexew gmail.com> writes:
On Friday, 24 January 2014 at 14:31:01 UTC, David Nadlinger wrote:
 In general, you can't reliably stringify types for use in 
 string mixins anyway.
May I ask why? Anyway, thanks for the workaround.
Jan 24 2014
prev sibling parent reply =?UTF-8?B?IsOYaXZpbmQi?= <oivind.loe gmail.com> writes:
On Friday, 24 January 2014 at 09:40:32 UTC, Dicebot wrote:
 On Friday, 24 January 2014 at 09:38:24 UTC, Timon Gehr wrote:
 The following fails:
Compiler bug.
More like "Phobos bug that is very hard to fix because of compiler bug"
Looking at the code, it does not seem like it pays any attention to template parameters at all? I would expect that for a template instantiation A!(B, C) it would resolve parents, etc. for A, B and C in turn.. How would I do that if I were to give it a go? E.g. for a template instance A!(B, C), how do I use __traits or std.traits to get the plain type A, and B and C so I can use e.g. __traits(parent...) to figure out where they come from? That is really all I need. For me C can be defined inside a struct, so (A!(B, C)).stringof is not sufficient.. I would need a result like e.g A!(B, X.C)
Jan 24 2014
parent reply Timon Gehr <timon.gehr gmx.ch> writes:
On 01/25/2014 02:06 AM, "Øivind" wrote:
 On Friday, 24 January 2014 at 09:40:32 UTC, Dicebot wrote:
 On Friday, 24 January 2014 at 09:38:24 UTC, Timon Gehr wrote:
 The following fails:
Compiler bug.
More like "Phobos bug that is very hard to fix because of compiler bug"
Looking at the code, it does not seem like it pays any attention to template parameters at all? I would expect that for a template instantiation A!(B, C) it would resolve parents, etc. for A, B and C in turn.. How would I do that if I were to give it a go? E.g. for a template instance A!(B, C), how do I use __traits or std.traits to get the plain type A, and B and C so I can use e.g. __traits(parent...) to figure out where they come from? That is really all I need. For me C can be defined inside a struct, so (A!(B, C)).stringof is not sufficient.. I would need a result like e.g A!(B, X.C)
alias Seq(T...)=T; struct A(T...){} struct B{} struct C{} alias T=A!(B,C); static if(is(T==X!Y,alias X,Y...)){ static assert(__traits(isSame, X, A)); static assert(is(Y==Seq!(B,C))); }
Jan 25 2014
parent "Dicebot" <public dicebot.lv> writes:
On Saturday, 25 January 2014 at 08:53:19 UTC, Timon Gehr wrote:
 alias Seq(T...)=T;

 struct A(T...){}
 struct B{}
 struct C{}

 alias T=A!(B,C);


 static if(is(T==X!Y,alias X,Y...)){
     static assert(__traits(isSame, X, A));
     static assert(is(Y==Seq!(B,C)));
 }
It won't work for templated function type though and probably some other cases I have forgotten by today. That was the problem locking fullyQualifiedName update as such functionality in Phobos is suppose to be generic. That said, probably adding simple special case for aggregate types is worth it as it seems most common thing to encounter.
Jan 25 2014