diff options
Diffstat (limited to 'tests/template/ttempl3.nim')
-rw-r--r-- | tests/template/ttempl3.nim | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/tests/template/ttempl3.nim b/tests/template/ttempl3.nim index 943cdae05..17421cd87 100644 --- a/tests/template/ttempl3.nim +++ b/tests/template/ttempl3.nim @@ -37,7 +37,7 @@ var `hu "XYZ"` = "yay" echo prefix(XYZ) -template typedef(name: untyped, typ: typeDesc) {.immediate, dirty.} = +template typedef(name: untyped, typ: typeDesc) {.dirty.} = type `T name`* = typ `P name`* = ref `T name` @@ -60,3 +60,24 @@ template create(typ: typeDesc, arg: untyped): untyped = `init typ`(arg) var ff = Foo.create(12) echo ff.arg + + +import macros + +# bug #11494 +macro staticForEach(arr: untyped, body: untyped): untyped = + result = newNimNode(nnkStmtList) + arr.expectKind(nnkBracket) + for n in arr: + let b = copyNimTree(body) + result.add quote do: + block: + type it {.inject.} = `n` + `b` + +template forEveryMatchingEntity*() = + staticForEach([int, string, float]): + var a {.inject.}: it + echo a + +forEveryMatchingEntity() |