www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 2527] New: Alias Template Params Are Always Same Type As First Instantiation (according to typeof(x).stringof)

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

           Summary: Alias Template Params Are Always Same Type As First
                    Instantiation (according to typeof(x).stringof)
           Product: D
           Version: 1.038
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Keywords: wrong-code
          Severity: regression
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: business3 twistedpairgaming.com


The following works correctly on 1.029, but not on 1.033 and 1.038:

template fooMixin(alias bar)
{
        pragma(msg, "fooMixin!("~bar.stringof~"): typeof(bar).stringof: " ~
typeof(bar).stringof);
        const char[] fooMixin="";
}

template fooFunc(alias bar)
{
        pragma(msg, "fooFunc!("~bar.stringof~"): typeof(bar).stringof: " ~
typeof(bar).stringof);
        void fooFunc() {}
}

void main(char[][] args)
{
        int myInt;
        bool myBool;

        pragma(msg, "main: typeof(myInt).stringof: " ~ typeof(myInt).stringof);
        pragma(msg, "main: typeof(myBool).stringof: " ~
typeof(myBool).stringof);
        mixin(fooMixin!(myInt));
        mixin(fooMixin!(myBool));
        fooFunc!(myInt)();
        fooFunc!(myBool)();
}

Expected compiler output (and actual compiler output on 1.029):
main: typeof(myInt).stringof: int
main: typeof(myBool).stringof: bool
fooMixin!(myInt): typeof(bar).stringof: int
fooMixin!(myBool): typeof(bar).stringof: bool
fooFunc!(myInt): typeof(bar).stringof: int
fooFunc!(myBool): typeof(bar).stringof: bool

Actual compiler output on 1.033 and 1.038:
main: typeof(myInt).stringof: int
main: typeof(myBool).stringof: bool
fooMixin!(myInt): typeof(bar).stringof: int
fooMixin!(myBool): typeof(bar).stringof: int
fooFunc!(myInt): typeof(bar).stringof: int
fooFunc!(myBool): typeof(bar).stringof: int

If the last 4 lines of main are changed to this:
//mixin(fooMixin!(myInt));
mixin(fooMixin!(myBool));
//fooFunc!(myInt)();
fooFunc!(myBool)();

...then myBool is correctly evaluated as bool instead of int.


-- 
Dec 20 2008
parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2527


business3 twistedpairgaming.com changed:

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





-------
I'm closing this as it's been fixed in 1.039/2.023:
http://www.digitalmars.com/d/1.0/changelog.html#new1_039
http://www.digitalmars.com/d/2.0/changelog.html#new2_023


-- 
Jan 09 2009