Bug 8963 – "Forward reference" error when deriving the function name using __traits() inside an "auto"-return function

Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Linux
Creation time
2012-11-05T13:06:00Z
Last change time
2012-11-06T07:37:11Z
Assigned to
nobody
Creator
r_m_r

Comments

Comment #0 by r_m_r — 2012-11-05T13:06:15Z
As shown below, when I try to derive a function's name using __traits(identifier,__traits(parent,{})) inside an "auto" return function, the compiler generates a Forward reference error. Code here: http://dpaste.dzfl.pl/c8ac3b9d //---------------------------------------------------------------------------- import std.stdio : writeln; enum A { Val } enum B { Val } enum C { Val } void set(T,V)(T t, V data) if( (is(T==A) && is(V==int)) || (is(T==B) && is(V==double))|| (is(T==C) && is(V==string)) ) { writeln("DBG: Running ", __traits(identifier,__traits(parent,{})) ); //Works static if (is(T==A)) writeln("setting A; data =", data); else static if(is(T==B)) writeln("setting B; data =", data); else static if(is(T==C)) writeln("setting C; data =", data); else static assert(false, "Invalid type+data combo"); } auto get(T)(T t) if( is(T==A) || is(T==B) || is(T==C) ) { writeln("DBG: Running ", __traits(identifier,__traits(parent,{})) ); //Doesn't Work static if (is(T==A)) return 1; else static if(is(T==B)) return 1.0; else static if(is(T==C)) return "1.000"; else static assert(false, "Invalid type"); } void main() { set(A.Val, 1); set(B.Val, 1.0); set(C.Val, "1.000"); assert(get(A.Val) == 1); assert(get(B.Val) == 1.0); assert(get(C.Val) == "1.000"); } //-------------------------------------------------------------- Compilation output: /home/c10/c901.d(29): Error: forward reference to get /home/c10/c901.d(29): Error: argument __error has no identifier /home/c10/c901.d(47): Error: template instance c901.get!(A) error instantiating /home/c10/c901.d(29): Error: forward reference to get /home/c10/c901.d(29): Error: argument __error has no identifier /home/c10/c901.d(48): Error: template instance c901.get!(B) error instantiating /home/c10/c901.d(29): Error: forward reference to get /home/c10/c901.d(29): Error: argument __error has no identifier /home/c10/c901.d(49): Error: template instance c901.get!(C) error instantiating
Comment #1 by r_m_r — 2012-11-06T07:37:11Z