[Issue 8963] New: "Forward reference" error when deriving the function name using __traits() inside an "auto"-return function
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Mon Nov 5 13:06:16 PST 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8963
Summary: "Forward reference" error when deriving the function
name using __traits() inside an "auto"-return function
Product: D
Version: D2
Platform: x86
OS/Version: Linux
Status: NEW
Severity: normal
Priority: P2
Component: DMD
AssignedTo: nobody at puremagic.com
ReportedBy: r_m_r at mailinator.com
--- Comment #0 from r_m_r <r_m_r at mailinator.com> 2012-11-05 13:06:15 PST ---
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
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list