summary refs log tree commit diff stats
path: root/tests
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2019-07-06 23:59:23 +0200
committerAndreas Rumpf <rumpf_a@web.de>2019-07-06 23:59:23 +0200
commit465815e8945ec7619ba7c8ec494a8f8064a0aae2 (patch)
tree9f99c794446b75dd4070b4bc64e2e84f9467da03 /tests
parent6ce6bce12ecef07595f04f76ab5c33e393535d8b (diff)
downloadNim-465815e8945ec7619ba7c8ec494a8f8064a0aae2.tar.gz
improved the error message for #11494; closes #11494
Diffstat (limited to 'tests')
-rw-r--r--tests/template/ttempl3.nim21
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/template/ttempl3.nim b/tests/template/ttempl3.nim
index 9feaa0b7b..17421cd87 100644
--- a/tests/template/ttempl3.nim
+++ b/tests/template/ttempl3.nim
@@ -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()