[Issue 19084] Symbol not resolved in string mixin in template struct

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Aug 24 03:45:43 UTC 2018


https://issues.dlang.org/show_bug.cgi?id=19084

Jonathan Marler <johnnymarler at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |johnnymarler at gmail.com

--- Comment #1 from Jonathan Marler <johnnymarler at gmail.com> ---
This is not supposed to compile.  I've actually run into this before, but using
T.stringof to mixin code for a type name is not supported. When I've asked
about adding support for this, no one was interested.  I tried to find my forum
posts on this but the post is so old I couldn't find it in search.

What happens is you mixin the string "Foo", but that type doesn't mean anyting
in the scope of Bar.  The actual type name is something like
"__unittest__20.Foo", however, even if you got the fully qualified type name it
won't work because the type is private and can't be accessed outside of the
unittest using the symbol name.  You have to access the type by "alias".

The `bitfields` function in phobos suffers from this same problem and I created
a PR in phobos to add bitfields2 to workaround this issue by using a "mixin
template" instead of a normal "mixin":

https://github.com/dlang/phobos/pull/5490

> [QUOTE FROM THE PR]
> The main advantage of bitfields2 is that it is able to reference the field types by alias, whereas the current implementation converts each field type alias to a string and then mixes in the type name. 

I know the example you've provided is contrived so I'm not sure how to help you
with your exact situation.  Maybe I can help you find a solution with a bit
more detail?

--


More information about the Digitalmars-d-bugs mailing list