diff options
-rwxr-xr-x | compiler/sem.nim | 2 | ||||
-rwxr-xr-x | tests/compile/tmacro1.nim | 10 | ||||
-rw-r--r-- | tests/reject/trecmacro.nim | 14 |
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 |