diff options
author | ringabout <43030857+ringabout@users.noreply.github.com> | 2022-12-24 17:37:32 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-24 10:37:32 +0100 |
commit | 9323cb7b2a761543df9d875c05f4963c1a8b050f (patch) | |
tree | 189e5dac45e51a56b8644c9cae0a0cc97567ba51 | |
parent | 86a6c90c9e23f2e79d9d43927e114eedec0c230d (diff) | |
download | Nim-9323cb7b2a761543df9d875c05f4963c1a8b050f.tar.gz |
enforce void for nkWhileStmt [backport: 2.0] (#21170)
enforce void for nkWhileStmt
-rw-r--r-- | compiler/semstmts.nim | 1 | ||||
-rw-r--r-- | tests/discard/tdiscardable.nim | 11 |
2 files changed, 11 insertions, 1 deletions
diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim index 356c2d63e..96883255c 100644 --- a/compiler/semstmts.nim +++ b/compiler/semstmts.nim @@ -105,7 +105,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 diff --git a/tests/discard/tdiscardable.nim b/tests/discard/tdiscardable.nim index b13130a13..69cb9f6a1 100644 --- a/tests/discard/tdiscardable.nim +++ b/tests/discard/tdiscardable.nim @@ -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 |