parent
d146516008
commit
39ad3a0da6
2 changed files with 11 additions and 2 deletions
|
|
@ -42,10 +42,11 @@ proc semDiscard(c: PContext, n: PNode): PNode =
|
||||||
if n.sons[0].kind != nkEmpty:
|
if n.sons[0].kind != nkEmpty:
|
||||||
n.sons[0] = semExprWithType(c, n.sons[0])
|
n.sons[0] = semExprWithType(c, n.sons[0])
|
||||||
let sonType = n.sons[0].typ
|
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:
|
if isEmptyType(sonType) or sonType.kind == tyNone or n.sons[0].kind == nkTypeOfExpr:
|
||||||
localError(c.config, n.info, errInvalidDiscard)
|
localError(c.config, n.info, errInvalidDiscard)
|
||||||
if sonType.kind == tyProc:
|
if sonType.kind == tyProc and sonKind notin nkCallKinds:
|
||||||
# tyProc is disallowed to prevent ``discard foo`` to pass, when ``discard foo()`` is meant.
|
# 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] & "()")
|
localError(c.config, n.info, "illegal discard proc, did you mean: " & $n[0] & "()")
|
||||||
|
|
||||||
proc semBreakOrContinue(c: PContext, n: PNode): PNode =
|
proc semBreakOrContinue(c: PContext, n: PNode): PNode =
|
||||||
|
|
|
||||||
|
|
@ -27,3 +27,11 @@ proc bar(b: int):int =
|
||||||
|
|
||||||
echo foo(0)
|
echo foo(0)
|
||||||
echo bar(0)
|
echo bar(0)
|
||||||
|
|
||||||
|
# bug #9726
|
||||||
|
|
||||||
|
proc foo: (proc: int) =
|
||||||
|
proc bar: int = 1
|
||||||
|
return bar
|
||||||
|
|
||||||
|
discard foo()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue