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

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Dec 20 17:42:13 PST 2008


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 at digitalmars.com
        ReportedBy: business3 at 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.


-- 



More information about the Digitalmars-d-bugs mailing list