[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:49:58 PDT 2014
https://issues.dlang.org/show_bug.cgi?id=12571
--- Comment #3 from Andrej Mitrovic <andrej.mitrovich at gmail.com> ---
(In reply to Kenji Hara from comment #2)
> (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.
That doesn't work. It will return 'test' which is the module name rather than
'main'.
--
More information about the Digitalmars-d-bugs
mailing list