summary refs log tree commit diff stats
path: root/tests/template/tmore_regressions.nim
diff options
context:
space:
mode:
Diffstat (limited to 'tests/template/tmore_regressions.nim')
-rw-r--r--tests/template/tmore_regressions.nim44
1 files changed, 44 insertions, 0 deletions
diff --git a/tests/template/tmore_regressions.nim b/tests/template/tmore_regressions.nim
new file mode 100644
index 000000000..8b4b5fa4c
--- /dev/null
+++ b/tests/template/tmore_regressions.nim
@@ -0,0 +1,44 @@
+discard """
+output: '''0
+
+0.0'''
+"""
+
+# bug #11494
+import macros
+
+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: it
+        echo a
+
+forEveryMatchingEntity()
+
+
+# bug #11483
+proc main =
+  template first(body) =
+    template second: var int =
+      var o: int
+      var i  = addr(o)
+      i[]
+
+    body
+
+  first:
+    second = 5
+    second = 6
+
+main()
+