[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 04:33:52 PDT 2014


https://issues.dlang.org/show_bug.cgi?id=12571

--- Comment #5 from Kenji Hara <k.hara.pg at gmail.com> ---
(In reply to Andrej Mitrovic from comment #3)
> That doesn't work. It will return 'test' which is the module name rather
> than 'main'.

Oh, sorry. I didn't see the local execution result carefully.

----

I confirmed root problem. The opening code must not work. But, if the type of
scopeName is explicitly specified, it should work.

mixin template getScopeName()
{
// NG, circular reference to scopeName
//  enum        scopeName = __traits(identifier, __traits(parent, scopeName));

// should be OK
    enum string scopeName = __traits(identifier, __traits(parent, scopeName));
}

In original case, the type of scopeName is inferred from its initializer.
Therefore on the evaluation of __traits(parent, scopeName), it will recursively
invoke semantic analysis of the initialize, then it will cause forward
reference.

By adding variable type, the declaration and definition of scopeName variable
will be properly separated. Therefore on __traits(parent, scopeName), it should
not cause recursive semantic analysis of the initializer. Finally it should
work as expected.

----

But, currently the code will cause ICE. It is definitely a compiler bug. I'll
open a pull request to fix it.

--


More information about the Digitalmars-d-bugs mailing list