bugfix: tests should be green again
This commit is contained in:
parent
1d30798363
commit
2193460ea6
2 changed files with 13 additions and 5 deletions
|
|
@ -723,9 +723,6 @@ proc buildEchoStmt(c: PContext, n: PNode): PNode =
|
||||||
addSon(result, semExpr(c, arg))
|
addSon(result, semExpr(c, arg))
|
||||||
|
|
||||||
proc discardCheck(result: PNode) =
|
proc discardCheck(result: PNode) =
|
||||||
proc ImplicitelyDiscardable(n: PNode): bool {.inline.} =
|
|
||||||
result = isCallExpr(n) and n.sons[0].kind == nkSym and
|
|
||||||
sfDiscardable in n.sons[0].sym.flags
|
|
||||||
if result.typ != nil and result.typ.kind notin {tyStmt, tyEmpty}:
|
if result.typ != nil and result.typ.kind notin {tyStmt, tyEmpty}:
|
||||||
if result.kind == nkNilLit:
|
if result.kind == nkNilLit:
|
||||||
# XXX too much work and fixing would break bootstrapping:
|
# XXX too much work and fixing would break bootstrapping:
|
||||||
|
|
@ -1105,7 +1102,9 @@ proc semProcBody(c: PContext, n: PNode): PNode =
|
||||||
# ``result``:
|
# ``result``:
|
||||||
if result.kind == nkSym and result.sym == c.p.resultSym:
|
if result.kind == nkSym and result.sym == c.p.resultSym:
|
||||||
nil
|
nil
|
||||||
elif result.kind == nkNilLit:
|
elif result.kind == nkNilLit or ImplicitelyDiscardable(result):
|
||||||
|
# intended semantic: if it's 'discardable' and the context allows for it,
|
||||||
|
# discard it. This is bad for chaining but nicer for C wrappers.
|
||||||
# ambiguous :-(
|
# ambiguous :-(
|
||||||
result.typ = nil
|
result.typ = nil
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -1088,6 +1088,10 @@ proc insertDestructors(c: PContext, varSection: PNode):
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
|
proc ImplicitelyDiscardable(n: PNode): bool =
|
||||||
|
result = isCallExpr(n) and n.sons[0].kind == nkSym and
|
||||||
|
sfDiscardable in n.sons[0].sym.flags
|
||||||
|
|
||||||
proc semStmtList(c: PContext, n: PNode): PNode =
|
proc semStmtList(c: PContext, n: PNode): PNode =
|
||||||
# these must be last statements in a block:
|
# these must be last statements in a block:
|
||||||
const
|
const
|
||||||
|
|
@ -1134,7 +1138,12 @@ proc semStmtList(c: PContext, n: PNode): PNode =
|
||||||
|
|
||||||
# a statement list (s; e) has the type 'e':
|
# a statement list (s; e) has the type 'e':
|
||||||
if result.kind == nkStmtList and result.len > 0:
|
if result.kind == nkStmtList and result.len > 0:
|
||||||
result.typ = lastSon(result).typ
|
var lastStmt = lastSon(result)
|
||||||
|
if not ImplicitelyDiscardable(lastStmt):
|
||||||
|
result.typ = lastStmt.typ
|
||||||
|
#localError(lastStmt.info, errGenerated,
|
||||||
|
# "Last expression must be explicitly returned if it " &
|
||||||
|
# "is discardable or discarded")
|
||||||
|
|
||||||
proc SemStmt(c: PContext, n: PNode): PNode =
|
proc SemStmt(c: PContext, n: PNode): PNode =
|
||||||
# now: simply an alias:
|
# now: simply an alias:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue