summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2012-06-21 19:08:39 +0200
committerAraq <rumpf_a@web.de>2012-06-21 19:08:39 +0200
commit4d9a5dc8fff3fc7d455fb9e8044fde1338ee775e (patch)
treedbc97a072a9a978ab2c329da0c8addfc7314f000
parent2294c02cc899d42695e659572e75d7f87680de2b (diff)
downloadNim-4d9a5dc8fff3fc7d455fb9e8044fde1338ee775e.tar.gz
fixes #140
-rwxr-xr-xcompiler/sem.nim2
-rwxr-xr-xtests/compile/tmacro1.nim10
-rw-r--r--tests/reject/trecmacro.nim14
3 files changed, 16 insertions, 10 deletions
diff --git a/compiler/sem.nim b/compiler/sem.nim
index 721b4b040..63e401108 100755
--- a/compiler/sem.nim
+++ b/compiler/sem.nim
@@ -117,6 +117,8 @@ proc semAfterMacroCall(c: PContext, n: PNode, s: PSym): PNode =
 proc semMacroExpr(c: PContext, n: PNode, sym: PSym, 
                   semCheck: bool = true): PNode = 
   markUsed(n, sym)
+  if sym == c.p.owner:
+    GlobalError(n.info, errRecursiveDependencyX, sym.name.s)
   if c.evalContext == nil:
     c.evalContext = newEvalContext(c.module, "", emStatic)
   result = evalMacroCall(c.evalContext, n, sym)
diff --git a/tests/compile/tmacro1.nim b/tests/compile/tmacro1.nim
index 52c86e7e9..b4fce9776 100755
--- a/tests/compile/tmacro1.nim
+++ b/tests/compile/tmacro1.nim
@@ -18,13 +18,3 @@ macro test*(a: stmt): stmt =
 
 test:
   "hi"
-
-macro dump(n: stmt): stmt =
-  dump(n)
-  if kind(n) == nnkNone:
-    nil
-  else:
-    hint($kind(n))
-    for i in countUp(0, len(n)-1):
-      nil
-
diff --git a/tests/reject/trecmacro.nim b/tests/reject/trecmacro.nim
new file mode 100644
index 000000000..28b6db530
--- /dev/null
+++ b/tests/reject/trecmacro.nim
@@ -0,0 +1,14 @@
+discard """
+  file: "trecmacro.nim"
+  line: 8
+  errormsg: "recursive dependency: 'dump'"
+"""
+
+macro dump(n: stmt): stmt =
+  dump(n)
+  if kind(n) == nnkNone:
+    nil
+  else:
+    hint($kind(n))
+    for i in countUp(0, len(n)-1):
+      nil