www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 8512] New: Nasty bug about template

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8512

           Summary: Nasty bug about template
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: youxkei gmail.com



---
I'm really sorry about this ambiguous summary, but I cannot come up with a
suitable summary.
If you come up with a suitable summary of this bug, please change the summary.


struct Tuple(T...){ alias T Types; }

template TempType(T, alias temp){
    pragma(msg, temp.temp!T.Type); // [1]
    static assert(__traits(compiles, temp.temp!T.Type));
    static if(is(temp.temp!T.Type Unused == Result!U, U)){
        alias U TempType;
    }else{
        static assert(false);
    }
}

struct Result(T){}

template seq(T, temps...){
    static if(temps.length == 1){
        alias Tuple!(TempType!(T, temps[0]).Types) seq; // [2]
    }else{
        alias Tuple!(TempType!(T, temps[0]).Types, seq!(T, temps[1..$]).Types)
seq; // [3]
    }
}

template temp1(){
    template temp(T){
        alias Result!(Tuple!()) Type;
        pragma(msg, seq!(T, temp2!(), temp2!()));
    }
}

template temp2(){
    template temp(T){
        alias Result!(Tuple!()) Type;
        pragma(msg, seq!(T, temp1!(), temp2!()));
    }
}

pragma(msg, temp1!().temp!int);


This code doesn't work with dmd 2.060.
And the error messages changes depending on whether line [1] is comment-outed
or not.
If you remove all ".Types" from the lines [2] and [3], the code works well.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 05 2012
parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8512




I think this code has a forward reference error, so cannot compile.

The starting of forward reference is here.
template temp1(){
    template temp(T){
        alias Result!(Tuple!()) Type;
        pragma(msg, seq!(T, temp2!(), temp2!()));  // bad
    }
}

And the dependencies direction is:
1. temp1!().temp!int             instantiates temp2!()
2. temp2!()                      instantiates seq!(int, temp1!(), temp2!()))
3. seq!(int, temp1!(), temp2!()) instantiates TempType!(int, temp1!())  (at
[2])
4. TempType!(int, temp1!())      instantiates temp1!().temp!int

1 to 4 makes forward reference.

In current dmd implementation, pragma(msg) requires *complete entities* for its
arguments. It means that all semantic analysis for them are already done.

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