summary refs log tree commit diff stats
path: root/tests/template
diff options
context:
space:
mode:
Diffstat (limited to 'tests/template')
-rw-r--r--tests/template/template_issues.nim15
-rw-r--r--tests/template/template_various.nim18
-rw-r--r--tests/template/tmore_regressions.nim44
-rw-r--r--tests/template/tparams_gensymed.nim15
-rw-r--r--tests/template/tredefinition.nim13
5 files changed, 103 insertions, 2 deletions
diff --git a/tests/template/template_issues.nim b/tests/template/template_issues.nim
index dd545d1e2..b7dd2a1a7 100644
--- a/tests/template/template_issues.nim
+++ b/tests/template/template_issues.nim
@@ -6,6 +6,7 @@ output: '''
 a
 hi
 Hello, World!
+(e: 42)
 '''
 """
 
@@ -220,3 +221,17 @@ block t5235:
 
   outer:
     test("Hello, World!")
+
+
+# bug #11941
+type X = object
+  e: int
+
+proc works(T: type X, v: auto): T = T(e: v)
+template fails(T: type X, v: auto): T = T(e: v)
+
+var
+  w = X.works(42)
+  x = X.fails(42)
+
+echo x
diff --git a/tests/template/template_various.nim b/tests/template/template_various.nim
index 36fa42050..ac7e91fa2 100644
--- a/tests/template/template_various.nim
+++ b/tests/template/template_various.nim
@@ -9,6 +9,7 @@ bar7
 10
 4true
 132
+20
 '''
 """
 
@@ -192,7 +193,7 @@ block ttempl:
 
 
 block ttempl4:
-  template `:=`(name, val: untyped): typed =
+  template `:=`(name, val: untyped) =
     var name = val
 
   ha := 1 * 4
@@ -211,7 +212,7 @@ block ttempl5:
       discard
 
   # Call parse_to_close
-  template get_next_ident: typed =
+  template get_next_ident =
       discard "{something}".parse_to_close(0, open = '{', close = '}')
 
   get_next_ident()
@@ -231,3 +232,16 @@ block ttempl5:
 block templreturntype:
   template `=~` (a: int, b: int): bool = false
   var foo = 2 =~ 3
+
+# bug #7117
+template parse9(body: untyped): untyped =
+
+  template val9(arg: string): int {.inject.} =
+    var b: bool
+    if b: 10
+    else: 20
+
+  body
+
+parse9:
+  echo val9("1")
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()