import macros
template test(a: bool) =
if a:
echo "true seen"
else:
echo "false seen"
macro joe(body: untyped): untyped =
result = newStmtList()
let temp = getAst test(true)
result.add(temp)
joe:
echo "never seen"
I've been able to narrow down my problem scenario. A template with a bool parameter works normally except when pulled through getAst inside a macro. In that scenario, it seems to "become" an integer.
I get the error:
/home/johnad/test.nim(14, 1) template/generic instantiation of `joe` from here
/home/johnad/test.nim(11, 25) Error: type mismatch: got <int literal(1)> but expected 'bool'
Am I misusing something? Or is this a bug?
It's a known bug, https://github.com/nim-lang/Nim/issues/7375.
Not optimal, but you can do bool(a) in template test