This commit is contained in:
Arne Döring
2018-11-20 13:12:47 +01:00
committed by GitHub
parent d146516008
commit 39ad3a0da6
2 changed files with 11 additions and 2 deletions

View File

@@ -42,10 +42,11 @@ proc semDiscard(c: PContext, n: PNode): PNode =
if n.sons[0].kind != nkEmpty:
n.sons[0] = semExprWithType(c, n.sons[0])
let sonType = n.sons[0].typ
let sonKind = n.sons[0].kind
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.
if sonType.kind == tyProc and sonKind notin nkCallKinds:
# tyProc is disallowed to prevent ``discard foo`` to be valid, 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 =

View File

@@ -27,3 +27,11 @@ proc bar(b: int):int =
echo foo(0)
echo bar(0)
# bug #9726
proc foo: (proc: int) =
proc bar: int = 1
return bar
discard foo()