This commit is contained in:
Andreas Rumpf 2019-09-16 15:38:07 +02:00 • committed by GitHub
commit 059a16b34d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 2 deletions

View file

@ -70,3 +70,21 @@ macro makeProc(): typed =
makeProc()
someProc()
# bug #12193
import macros, strutils
macro gen(T: typedesc): untyped =
let typeSym = getTypeImpl(T)[1]
let param = genSym(nskParam, "s")
let value = nnkBracketExpr.newTree(param, newIntLitNode(0))
result = newProc(
name = ident"pack",
params = [typeSym,
newIdentDefs(param, nnkBracketExpr.newTree(ident"seq", ident"string"))],
body = newStmtList(newCall(typeSym, newCall(bindSym"parseInt", value))),
procType = nnkTemplateDef)
echo repr result
gen(int)
let i = pack(@["2"])