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