summary refs log tree commit diff stats
path: root/tests/template
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2019-08-23 16:15:02 +0200
committerGitHub <noreply@github.com>2019-08-23 16:15:02 +0200
commitb07694cd90ab7c6eb4660971ddb818b461d4eed8 (patch)
treea158993297748d4c55b6e069a6636eefcacd9865 /tests/template
parentf28a47ea7b9c579b172653c15dc2cc054adf599a (diff)
downloadNim-b07694cd90ab7c6eb4660971ddb818b461d4eed8.tar.gz
new gensym handling (#11985)
* new .gensym implementation
* make astspec test green again
* introduce a --useVersion switch to group compatibility switches
* fixes #10180
* fixes #11494 
* fixes #11483
* object constructor fields and named parameters are also not gensym'ed
* disabled broken package
Diffstat (limited to 'tests/template')
-rw-r--r--tests/template/tmore_regressions.nim44
-rw-r--r--tests/template/tparams_gensymed.nim15
-rw-r--r--tests/template/tredefinition.nim13
3 files changed, 72 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()
+
diff --git a/tests/template/tparams_gensymed.nim b/tests/template/tparams_gensymed.nim
index b19ed7afc..f7a02efa0 100644
--- a/tests/template/tparams_gensymed.nim
+++ b/tests/template/tparams_gensymed.nim
@@ -8,6 +8,7 @@ output: '''
 1
 2
 3
+wth
 '''
 """
 # bug #1915
@@ -130,3 +131,17 @@ template test() =
       doAssert(foo.len == 3)
 
 test()
+
+# regression found in PMunch's parser generator
+
+proc namedcall(arg: string) =
+  discard
+
+macro m(): untyped =
+  result = quote do:
+    (proc (arg: string) =
+      namedcall(arg = arg)
+      echo arg)
+
+let meh = m()
+meh("wth")
diff --git a/tests/template/tredefinition.nim b/tests/template/tredefinition.nim
new file mode 100644
index 000000000..8efc5ae2f
--- /dev/null
+++ b/tests/template/tredefinition.nim
@@ -0,0 +1,13 @@
+discard """
+  errormsg: "redefinition of 'a`gensym"
+  line: 9
+"""
+# bug #10180
+proc f() =
+  template t() =
+    var a = 1
+    var a = 2
+    echo a
+  t()
+
+f()