fixes #6980
This commit is contained in:
parent
e49f18801c
commit
0b0baece89
3 changed files with 25 additions and 2 deletions
|
|
@ -780,6 +780,19 @@ proc buildEchoStmt(c: PContext, n: PNode): PNode =
|
||||||
|
|
||||||
proc semExprNoType(c: PContext, n: PNode): PNode =
|
proc semExprNoType(c: PContext, n: PNode): PNode =
|
||||||
result = semExpr(c, n, {efWantStmt})
|
result = semExpr(c, n, {efWantStmt})
|
||||||
|
# make an 'if' expression an 'if' statement again for backwards
|
||||||
|
# compatibility (.discardable was a bad idea!); bug #6980
|
||||||
|
var isStmt = false
|
||||||
|
if result.kind == nkIfExpr:
|
||||||
|
isStmt = true
|
||||||
|
for condActionPair in result:
|
||||||
|
let action = condActionPair.lastSon
|
||||||
|
if not implicitlyDiscardable(action) and not
|
||||||
|
endsInNoReturn(action):
|
||||||
|
isStmt = false
|
||||||
|
if isStmt:
|
||||||
|
result.kind = nkIfStmt
|
||||||
|
result.typ = nil
|
||||||
discardCheck(c, result)
|
discardCheck(c, result)
|
||||||
|
|
||||||
proc isTypeExpr(n: PNode): bool =
|
proc isTypeExpr(n: PNode): bool =
|
||||||
|
|
|
||||||
|
|
@ -732,7 +732,7 @@ proc semRaise(c: PContext, n: PNode): PNode =
|
||||||
var typ = n.sons[0].typ
|
var typ = n.sons[0].typ
|
||||||
if typ.kind != tyRef or typ.lastSon.kind != tyObject:
|
if typ.kind != tyRef or typ.lastSon.kind != tyObject:
|
||||||
localError(n.info, errExprCannotBeRaised)
|
localError(n.info, errExprCannotBeRaised)
|
||||||
|
|
||||||
# check if the given object inherits from Exception
|
# check if the given object inherits from Exception
|
||||||
var base = typ.lastSon
|
var base = typ.lastSon
|
||||||
while true:
|
while true:
|
||||||
|
|
|
||||||
|
|
@ -140,4 +140,14 @@ echo(
|
||||||
else:
|
else:
|
||||||
quo do (a: int) -> bool:
|
quo do (a: int) -> bool:
|
||||||
a mod 3 != 0
|
a mod 3 != 0
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# bug #6980
|
||||||
|
|
||||||
|
proc fooBool: bool {.discardable.} =
|
||||||
|
true
|
||||||
|
|
||||||
|
if true:
|
||||||
|
fooBool()
|
||||||
|
else:
|
||||||
|
raise newException(ValueError, "argh")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue