A problem found by Peter Lundgren and David Nadlinger. Reduced D2 code: import std.conv: to; string foo() { // return to!string(10); // OK return to!string(10) ~ ""; } string s = foo(); void main() {} DMD 2.052 gives the errors: test.d(4): Error: to(10) ~ "" cannot be interpreted at compile time test.d(6): Error: cannot evaluate foo() at compile time test.d(6): Error: cannot evaluate foo() at compile time I think it's not a problem of to!() because this alternative version works correctly: import std.conv: to; string foo() { return to!string(10); } string s = foo(); void main() {}
Reduced test case shows it is a constant folding problem. ['a', 'b'] ~ "c" doesn't get constant folded. string foo5671() { return ['a', 'b']; } string bug5671() { return foo5671() ~ "c"; } static assert(bug5671() == "abc");
Can be reduced even further, showing CTFE isn't involved at all: static assert( ['a', 'b'] ~ "c" == "abc" );
https://github.com/D-Programming-Language/dmd/commit/316ba0a77e3934bfc8091940444f706e82aecc72 https://github.com/D-Programming-Language/dmd/commit/5c7c6b51e27d9cd394ddda4f7940cdf9c1610953