April 13, 2014 [Issue 12571] New: Regression (2.063): Can no longer use static introspection on circular references | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=12571 Issue ID: 12571 Summary: Regression (2.063): Can no longer use static introspection on circular references Product: D Version: D2 Hardware: All OS: All Status: NEW Severity: regression Priority: P1 Component: DMD Assignee: nobody@puremagic.com Reporter: andrej.mitrovich@gmail.com This may or may not be a bug. But there was a nice trick from the D Templates Book[1] which allowed a simple way to extract the symbol name of the current scope: ----- mixin template getScopeName() { enum scopeName = __traits(identifier, __traits(parent, scopeName)); } void main() { mixin getScopeName; pragma(msg, scopeName); } ----- 2.062: $ dmd test.d > main 2.063+: > test.d(3): Error: circular reference to 'test.main.getScopeName!().scopeName' > test.d(3): Error: argument __error has no parent > test.d(3): Error: argument false has no identifier > test.d(8): Error: mixin test.main.getScopeName!() error instantiating If this is working as expected I suggest we introduce a new trait "scopeName". I'll file a separate report if this is closed. I've seen enough people try to hack their way around with using .stringof, __FUNCTION__, and other tricks just to get the name of the current scope. There is also a library workaround but it introduces symbol bloat: ----- mixin template getScopeName() { private enum __unused = 0; enum getScopeName = __traits(identifier, __traits(parent, __unused)); } void main() { mixin getScopeName; pragma(msg, getScopeName); // main } ----- [1] : https://github.com/PhilippeSigaud/D-templates-tutorial -- |
Copyright © 1999-2021 by the D Language Foundation