https://issues.dlang.org/show_bug.cgi?id=12571
--- Comment #3 from Andrej Mitrovic <[email protected]> --- (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'. --
