summary refs log tree commit diff stats
path: root/tests/macros
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2017-07-11 18:07:34 +0200
committerAndreas Rumpf <rumpf_a@web.de>2017-07-11 18:07:34 +0200
commit2ad9a16e0ad84517eab3555b2736ffa38ef86514 (patch)
tree13e31ef3ae92260b7f82f29d9dcc02551350b26c /tests/macros
parent76cf4f4c1bd1a8a799f26fb6c9d0c8df304e9c3b (diff)
downloadNim-2ad9a16e0ad84517eab3555b2736ffa38ef86514.tar.gz
fixes anon procs created by macros
Diffstat (limited to 'tests/macros')
-rw-r--r--tests/macros/tclosuremacro.nim33
1 files changed, 32 insertions, 1 deletions
diff --git a/tests/macros/tclosuremacro.nim b/tests/macros/tclosuremacro.nim
index c29fbe1c8..9f2137dec 100644
--- a/tests/macros/tclosuremacro.nim
+++ b/tests/macros/tclosuremacro.nim
@@ -6,10 +6,14 @@ discard """
 3
 noReturn
 6
+calling mystuff
+yes
+calling mystuff
+yes
 '''
 """
 
-import future
+import future, macros
 
 proc twoParams(x: (int, int) -> int): int =
   result = x(5, 5)
@@ -41,3 +45,30 @@ proc pass2(f: (int, int) -> int): (int) -> int =
   ((x: int) -> int) => f(2, x)
 
 echo pass2((x, y) => x + y)(4)
+
+
+
+proc register(name: string; x: proc()) =
+  echo "calling ", name
+  x()
+
+register("mystuff", proc () =
+  echo "yes"
+)
+
+proc helper(x: NimNode): NimNode =
+  if x.kind == nnkProcDef:
+    result = copyNimTree(x)
+    result[0] = newEmptyNode()
+    result = newCall("register", newLit($x[0]), result)
+  else:
+    result = copyNimNode(x)
+    for i in 0..<x.len:
+      result.add helper(x[i])
+
+macro m(x: untyped): untyped =
+  result = helper(x)
+
+m:
+  proc mystuff() =
+    echo "yes"