Skip to content

Commit

Permalink
enforce void for nkWhileStmt [backport: 2.0] (#21170)
Browse files Browse the repository at this point in the history
enforce void for nkWhileStmt

(cherry picked from commit 9323cb7)
  • Loading branch information
ringabout authored and narimiran committed Apr 26, 2023
1 parent 8155b8d commit 0fc1b79
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
1 change: 0 additions & 1 deletion compiler/semstmts.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
11 changes: 11 additions & 0 deletions tests/discard/tdiscardable.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 0fc1b79

Please sign in to comment.