[Issue 12571] New: Regression (2.063): Can no longer use static introspection on circular references
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sun Apr 13 01:51:58 PDT 2014
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 at puremagic.com
Reporter: andrej.mitrovich at 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
--
More information about the Digitalmars-d-bugs
mailing list