Bug 2527 – Alias Template Params Are Always Same Type As First Instantiation (according to typeof(x).stringof)
Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
Windows
Creation time
2008-12-20T19:42:00Z
Last change time
2014-03-01T00:35:54Z
Keywords
wrong-code
Assigned to
bugzilla
Creator
bus_dbugzilla
Comments
Comment #0 by bus_dbugzilla — 2008-12-20T19:42:11Z
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.
Comment #1 by bus_dbugzilla — 2009-01-10T01:53:45Z