Open
Description
When an untyped macro is nested in a template, the identifiers are transformed into nnkSym instead of being left as raw nnkIdent. We also get the OpenSymChoice instead of nnkBracketExpr.
Test case:
import macros
macro foo(body: untyped): untyped =
echo body.treerepr
body.expectKind nnkStmtList
body[0].expectKind nnkProcDef
body[0][3].expectKind nnkFormalParams
body[0][3][1].expectKind nnkIdentDefs
assert body[0][3][1][0].eqIdent "a"
body[0][3][1][0].expectKind nnkIdent
echo "Success!\n##############\n"
result = newStmtList()
foo:
proc bar[T](a, b: seq[T]): seq[T]
####################################
template baz(): untyped =
foo:
proc bar[T](a, b: seq[T]): seq[T]
baz()
First parsing output:
StmtList
ProcDef
Ident "bar"
Empty
GenericParams
IdentDefs
Ident "T"
Empty
Empty
FormalParams
BracketExpr
Ident "seq"
Ident "T"
IdentDefs
Ident "a"
Ident "b"
BracketExpr
Ident "seq"
Ident "T"
Empty
Empty
Empty
Empty
Second:
StmtList
ProcDef
Ident "bar"
Empty
GenericParams
IdentDefs
Ident "T"
Empty
Empty
FormalParams
Call
OpenSymChoice
Sym "[]"
Sym "[]"
Sym "[]"
Sym "[]"
Sym "[]"
Sym "[]"
Sym "[]"
Sym "[]"
Sym "[]"
Sym "[]"
Sym "[]"
Sym "[]"
Sym "[]"
Sym "seq"
Ident "T"
IdentDefs
Sym "a"
Sym "b"
Call
OpenSymChoice
Sym "[]"
Sym "[]"
Sym "[]"
Sym "[]"
Sym "[]"
Sym "[]"
Sym "[]"
Sym "[]"
Sym "[]"
Sym "[]"
Sym "[]"
Sym "[]"
Sym "[]"
Sym "seq"
Ident "T"
Empty
Empty
Empty
Empty