summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--compiler/semstmts.nim11
-rw-r--r--tests/errmsgs/t10489_a.nim9
-rw-r--r--tests/errmsgs/t10489_b.nim9
3 files changed, 27 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)
diff --git a/tests/errmsgs/t10489_a.nim b/tests/errmsgs/t10489_a.nim
new file mode 100644
index 000000000..7cfe0176c
--- /dev/null
+++ b/tests/errmsgs/t10489_a.nim
@@ -0,0 +1,9 @@
+discard """
+errormsg: "cannot assign macro symbol to variable here"
+line: 9
+"""
+
+macro m(body: untyped): untyped =
+  body
+
+let x1 = m
diff --git a/tests/errmsgs/t10489_b.nim b/tests/errmsgs/t10489_b.nim
new file mode 100644
index 000000000..e690f028a
--- /dev/null
+++ b/tests/errmsgs/t10489_b.nim
@@ -0,0 +1,9 @@
+discard """
+errormsg: "cannot assign macro symbol to constant here"
+line: 9
+"""
+
+macro m(body: untyped): untyped =
+  body
+
+const x2 = m
04' href='#n204'>204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326