Version 1 of the program: --------------------------------------- pure string wham(string str) { return str; } template ouch(string val) { mixin(`const bool ouch = `~wham(val)~`;`); } static assert( ouch!("true") ); static assert( !ouch!("false") ); void main(){} --------------------------------------- This will compile just fine. I'm actually not sure if it should or not. By moving the wham function into the ouch template, the code will no longer compile; complaining about not being able to evaluate ouch at compile time. The changes make it look like so: --------------------------------------- template ouch(string val) { pure string wham(string str) { return str; } mixin(`const bool ouch = `~wham(val)~`;`); } static assert( ouch!("true") ); static assert( !ouch!("false") ); void main(){} --------------------------------------- main2.d(11): Error: static assert (ouch!("true")) is not evaluatable at compile time Another way to get the error is to store the result of wham into a constant and try to use it: --------------------------------------- pure string wham(string str) { return str; } template ouch(string val) { const string str = wham(val); mixin(`const bool ouch = `~str~`;`); // Same goes for `enum str = wham(val);` } static assert( ouch!("true") ); static assert( !ouch!("false") ); void main(){} --------------------------------------- main3.d(13): Error: static assert (ouch!("true")) is not evaluatable at compile time Again, I'm not actually sure whether these examples should compile or not. However, they should all be equivalent, yet one case will compile and the other ones will not.
The syntax in cases 2 and 3 is wrong. It should be ouch!(true).ouch because there is more than one member in the template. When this is done, everything works correctly.