typeof.stringof wrong type
Eugene Wissner via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Aug 17 05:52:19 PDT 2016
On Wednesday, 17 August 2016 at 12:39:18 UTC, ag0aep6g wrote:
> On 08/17/2016 02:08 PM, Eugene Wissner wrote:
>> I have a problem, that .stringof doesn't return what I'm
>> expecting.
>> Consider the following:
>>
>> template A(string T)
>> {
>> enum A : bool
>> {
>> yes = true,
>> }
>> }
>>
>> void main()
>> {
>> A!"asdf" a1;
>> typeof(a1) a2;
>> mixin(typeof(a1).stringof ~ " a3;");
>> }
>>
>> I get an error: some.d-mixin-13|13 error| Error: template
>> some.A(string
>> T) is used as a type
>>
>> Why the second line in main() works but the third one not?
>> typeof(a1).stringof seems to ignore the string template
>> parameter T.
>> pragma(msg, typeof(a1).stringof) would return just "A".
>>
>> Is it a bug?
>
> Not exactly a bug. .stringof gives you a simple, readable name.
> It's not meant to be used in code generation. You can use
> std.traits.fullyQualifiedName instead:
>
> import std.traits: fullyQualifiedName;
> mixin(fullyQualifiedName!(typeof(a1)) ~ " a3;");
What I find strange is that if A isn't a enum, but a class the
.stringof returns the full type name, therefore I would expect it
behave the same in the code above.
I will test later fullyQualifiedName, the example above is very
simplified version of the code I had problem with. Thanks anyway
More information about the Digitalmars-d-learn
mailing list