Hi,

recently I've been experimenting with the metaprogramming capabilities of the 
new dmd 2.042 compiler. I think I've found a bug, but since I'm still not 
really experienced with D, please confirm if so. I've reduced the test case to 
the following code:

import std.metastrings;

// dummy ctfe-capable function needed to reproduce the error
long parseLong(string timeStr) { return 42; }

// ctfe-capable function to demonstrate that a value is calculated in 
compile-time
string longToStr(long val)
{
    if (val < 10) { return "" ~ cast(char)(val + '0'); }
    else { return longToStr(val / 10) ~ longToStr(val % 10); }
}

void main(string[] args)
{
    const long mylong = parseLong("mystring");
    pragma(msg, "fine ", longToStr(mylong) ); // compiles and prints
    pragma(msg, "bug? ", std.metastrings.toStringNow!(mylong) ); // error
}

The compiler output is

fine 42
bug? c:\Program Files\.....\src\phobos\std\metastrings.d(97): Error: expression 
mylong < 0L is not constant or does not evaluate to a bool

Note that parseLong() is needed to reproduce the bug, if a constant is written 
instead of mylong, it works just fine. Am I missing something? 

thanks

István

Reply via email to