www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 8963] New: "Forward reference" error when deriving the function name using __traits() inside an "auto"-return function

reply d-bugmail puremagic.com writes:
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 puremagic.com
        ReportedBy: r_m_r mailinator.com



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: -------
Nov 05 2012
parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8963


r_m_r <r_m_r mailinator.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |INVALID



Please see: http://forum.dlang.org/post/k7af97$2792$1 digitalmars.com

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 06 2012