enforce void for nkWhileStmt [backport: 2.0] (#21170)

enforce void for nkWhileStmt

(cherry picked from commit 9323cb7b2a)
This commit is contained in:
ringabout
2022-12-24 17:37:32 +08:00
committed by narimiran
parent 8155b8d3ce
commit 0fc1b79b75
2 changed files with 11 additions and 1 deletions

View File

@@ -100,7 +100,6 @@ proc semWhile(c: PContext, n: PNode; flags: TExprFlags): PNode =
result.typ = n[1].typ
elif implicitlyDiscardable(n[1]):
result[1].typ = c.enforceVoidContext
result.typ = c.enforceVoidContext
proc semProc(c: PContext, n: PNode): PNode

View File

@@ -99,3 +99,14 @@ block: # bug #13583
let t = test
doAssert t() == 12
block:
proc bar(): string {.discardable.} =
"15"
proc foo(): int =
while true:
raise newException(ValueError, "check")
12
doAssertRaises(ValueError):
doAssert foo() == 12