more intelligent handling of 'discardable'
This commit is contained in:
parent
635469ec45
commit
cb51c1a0e7
1 changed files with 6 additions and 8 deletions
|
|
@ -107,16 +107,14 @@ proc semExprBranchScope(c: PContext, n: PNode): PNode =
|
||||||
result = semExprBranch(c, n)
|
result = semExprBranch(c, n)
|
||||||
closeScope(c.tab)
|
closeScope(c.tab)
|
||||||
|
|
||||||
proc meaningfulStmt(n: PNode): PNode =
|
const
|
||||||
assert n.kind == nkStmtListExpr
|
skipForDiscardable = {nkIfStmt, nkIfExpr, nkCaseStmt, nkOfBranch,
|
||||||
var last = n.len-1
|
nkElse, nkStmtListExpr, nkTryStmt, nkFinally, nkExceptBranch,
|
||||||
while last > 0 and n.sons[last].kind in {nkPragma, nkCommentStmt, nkEmpty}:
|
nkElifBranch, nkElifExpr, nkElseExpr, nkBlockStmt, nkBlockExpr}
|
||||||
dec last
|
|
||||||
result = n.sons[last]
|
|
||||||
|
|
||||||
proc ImplicitlyDiscardable(n: PNode): bool =
|
proc ImplicitlyDiscardable(n: PNode): bool =
|
||||||
var n = n
|
var n = n
|
||||||
while n.kind == nkStmtListExpr: n = meaningfulStmt(n)
|
while n.kind in skipForDiscardable: n = n.lastSon
|
||||||
result = isCallExpr(n) and n.sons[0].kind == nkSym and
|
result = isCallExpr(n) and n.sons[0].kind == nkSym and
|
||||||
sfDiscardable in n.sons[0].sym.flags
|
sfDiscardable in n.sons[0].sym.flags
|
||||||
|
|
||||||
|
|
@ -136,7 +134,7 @@ proc discardCheck(result: PNode) =
|
||||||
elif ImplicitlyDiscardable(result):
|
elif ImplicitlyDiscardable(result):
|
||||||
var n = result
|
var n = result
|
||||||
result.typ = nil
|
result.typ = nil
|
||||||
while n.kind == nkStmtListExpr:
|
while n.kind in skipForDiscardable:
|
||||||
n = n.lastSon
|
n = n.lastSon
|
||||||
n.typ = nil
|
n.typ = nil
|
||||||
elif result.typ.kind != tyError and gCmd != cmdInteractive:
|
elif result.typ.kind != tyError and gCmd != cmdInteractive:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue