It works:
template gen_str_in_ct_0: string =
when nimvm:
"sisix dev"
else:
"monkeys"
const a = gen_str_in_ct_0()
assert a == "sisix dev"
assert gen_str_in_ct_0() == "monkeys"
But it fails:
template gen_str_in_ct_1: string =
when nimvm:
"sisix dev"
else:
{.fatal: "monkeys not allowed".}
const a = gen_str_in_ct_1() # Error: fatal error: monkeys not allowed (nimvm branch expected)
Why?The why for this bug is relatively simple. It's cause the nimVm when statement does not cull the other branches until later and as such evaluates them, so any compiler magic can run inside. Comically enough that means the following also incorrectly runs the else branch and echoes.
const a = block:
when nimVm:
"hello"
else:
static: echo "hello"
10