summary refs log tree commit diff stats
path: root/compiler/semstmts.nim
diff options
context:
space:
mode:
authorArne Döring <arne.doering@gmx.net>2018-11-08 17:07:02 +0100
committerAndreas Rumpf <rumpf_a@web.de>2018-11-08 22:28:29 +0100
commit16353c2ac8f9a687367b6527c21589bd654a4bc1 (patch)
tree96530fe86bca2e48e3d2b1172c71e2b106cc2715 /compiler/semstmts.nim
parenta147166710ca30adc2d10b4de26348384fbcec40 (diff)
downloadNim-16353c2ac8f9a687367b6527c21589bd654a4bc1.tar.gz
fix #8011
Diffstat (limited to 'compiler/semstmts.nim')
-rw-r--r--compiler/semstmts.nim6
1 files changed, 5 insertions, 1 deletions
diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim
index 5c7f866ce..a2ca50fda 100644
--- a/compiler/semstmts.nim
+++ b/compiler/semstmts.nim
@@ -41,8 +41,12 @@ proc semDiscard(c: PContext, n: PNode): PNode =
   checkSonsLen(n, 1, c.config)
   if n.sons[0].kind != nkEmpty:
     n.sons[0] = semExprWithType(c, n.sons[0])
-    if isEmptyType(n.sons[0].typ) or n.sons[0].typ.kind == tyNone or n.sons[0].kind == nkTypeOfExpr:
+    let sonType = n.sons[0].typ
+    if isEmptyType(sonType) or sonType.kind == tyNone or n.sons[0].kind == nkTypeOfExpr:
       localError(c.config, n.info, errInvalidDiscard)
+    if sonType.kind == tyProc:
+      # tyProc is disallowed to prevent ``discard foo`` to pass, when ``discard foo()`` is meant.
+      localError(c.config, n.info, "illegal discard proc, did you mean: " & $n[0] & "()")
 
 proc semBreakOrContinue(c: PContext, n: PNode): PNode =
   result = n