From 4d9a5dc8fff3fc7d455fb9e8044fde1338ee775e Mon Sep 17 00:00:00 2001 From: Araq Date: Thu, 21 Jun 2012 19:08:39 +0200 Subject: [PATCH] fixes #140 --- compiler/sem.nim | 2 ++ tests/compile/tmacro1.nim | 10 ---------- tests/reject/trecmacro.nim | 14 ++++++++++++++ 3 files changed, 16 insertions(+), 10 deletions(-) create mode 100644 tests/reject/trecmacro.nim diff --git a/compiler/sem.nim b/compiler/sem.nim index 721b4b0409..63e4011082 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 52c86e7e9a..b4fce97760 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 0000000000..28b6db530d --- /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