summary refs log tree commit diff stats
path: root/compiler
diff options
context:
space:
mode:
authorArne Döring <arne.doering@gmx.net>2019-02-19 12:21:42 +0100
committerGitHub <noreply@github.com>2019-02-19 12:21:42 +0100
commit6b9a139f7f27422bc2d7dc3fad20d589518a93b5 (patch)
tree1ecb48e244721679870bd858523765800e3e0334 /compiler
parent257965e105c219f2504a2d1d0952fc43efb9598c (diff)
downloadNim-6b9a139f7f27422bc2d7dc3fad20d589518a93b5.tar.gz
error message for accidental use of macro (#10490)
* error message for accidental use of macro
Diffstat (limited to 'compiler')
-rw-r--r--compiler/semstmts.nim11
1 files changed, 9 insertions, 2 deletions
diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim
index cd570caad..3827da220 100644
--- a/compiler/semstmts.nim
+++ b/compiler/semstmts.nim
@@ -448,10 +448,14 @@ proc semVarOrLet(c: PContext, n: PNode, symkind: TSymKind): PNode =
     var def: PNode = c.graph.emptyNode
     if a.sons[length-1].kind != nkEmpty:
       def = semExprWithType(c, a.sons[length-1], {efAllowDestructor})
-      if def.typ.kind == tyTypeDesc and c.p.owner.kind != skMacro:
+      if def.typ.kind == tyProc and def.kind == nkSym and def.sym.kind == skMacro:
+        localError(c.config, def.info, "cannot assign macro symbol to variable here. Forgot to invoke the macro with '()'?")
+        def.typ = errorType(c)
+      elif def.typ.kind == tyTypeDesc and c.p.owner.kind != skMacro:
         # prevent the all too common 'var x = int' bug:
         localError(c.config, def.info, "'typedesc' metatype is not valid here; typed '=' instead of ':'?")
         def.typ = errorType(c)
+
       if typ != nil:
         if typ.isMetaType:
           def = inferWithMetatype(c, typ, def)
@@ -583,7 +587,10 @@ proc semConst(c: PContext, n: PNode): PNode =
       localError(c.config, a.sons[length-1].info, errConstExprExpected)
       continue
 
-    if def.typ.kind == tyTypeDesc and c.p.owner.kind != skMacro:
+    if def.typ.kind == tyProc and def.kind == nkSym and def.sym.kind == skMacro:
+        localError(c.config, def.info, "cannot assign macro symbol to constant here. Forgot to invoke the macro with '()'?")
+        def.typ = errorType(c)
+    elif def.typ.kind == tyTypeDesc and c.p.owner.kind != skMacro:
       # prevent the all too common 'const x = int' bug:
       localError(c.config, def.info, "'typedesc' metatype is not valid here; typed '=' instead of ':'?")
       def.typ = errorType(c)