[Issue 12571] Regression (2.063): Can no longer use static introspection on circular references

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Apr 15 03:47:33 PDT 2014


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

--- Comment #2 from Kenji Hara <k.hara.pg at gmail.com> ---
(In reply to Andrej Mitrovic from comment #0)
> -----
> mixin template getScopeName()
> {
>     enum scopeName = __traits(identifier, __traits(parent, scopeName));
> }
> 
> void main()
> {
>     mixin getScopeName;
>     pragma(msg, scopeName);
> }
> -----

I don't think the code should work. When declaring scopeName variable,
referring it in its initializer should cause forward reference error.

> There is also a library workaround but it introduces symbol bloat:
[snip]

More simple another way exists.

mixin template getScopeName()
{
//  enum scopeName = __traits(identifier, __traits(parent, scopeName));
    enum scopeName = __traits(identifier, __traits(parent, getScopeName));
}

void main()
{
    mixin getScopeName;
    pragma(msg, scopeName);
}

Mixed-in template also have parent, so __traits(parent, getScopeName) will
return the mixed in scope.

--


More information about the Digitalmars-d-bugs mailing list