typeof.stringof wrong type
Jonathan M Davis via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Fri Aug 19 11:52:02 PDT 2016
On Friday, August 19, 2016 15:36:02 David Nadlinger via Digitalmars-d-learn
wrote:
> On Friday, 19 August 2016 at 15:15:55 UTC, ag0aep6g wrote:
> > I think that qualifies as a bug, because fullyQualifiedName is
> > supposed to be usable in code generation.
>
> This is a misconception. Neither .stringof nor fullyQualifiedName
> should *ever* be used in code generation. There is a myriad of
> things that make strings unsuitable in the general case. The most
> obvious reason are imports: think a type coming via an alias
> parameter from a second module, which is not even important at
> the point of the mixin.
>
> Instead of trying to make .stringof work do things it will never
> be able to, you need to use the type just as you would at the
> point of the mixin. In this example, you would write
> `mixin("typeof(a) d");`.
Unfortunately, once you start doing stuff with things like
__traits(allMembers, ...), you're dealing with strings, and you're pretty
much forced to use stringof or fullyQualified name on the type that they go
with if you then want to actually do much of anything with those members.
So, while your advice is good in general, as far as I can tell, there are
cases where it just doesn't work to avoid stringof or fullyQualifiedName.
- Jonathan M Davis
More information about the Digitalmars-d-learn
mailing list