diff options
author | Andreas Rumpf <rumpf_a@web.de> | 2020-03-09 18:12:52 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-09 18:12:52 +0100 |
commit | ec5cef13cffdb43a7298736b65e1a76e83741dff (patch) | |
tree | 206c989b60e7a318ed3ff25108e48030553f0d0b | |
parent | 63af8ae53ca8e1ffd61a2c2d55d09c5fe30310e1 (diff) | |
download | Nim-ec5cef13cffdb43a7298736b65e1a76e83741dff.tar.gz |
fixes #13599 (#13614)
-rw-r--r-- | compiler/ccgstmts.nim | 2 | ||||
-rw-r--r-- | tests/destructor/tgotoexceptions5.nim | 39 |
2 files changed, 40 insertions, 1 deletions
diff --git a/compiler/ccgstmts.nim b/compiler/ccgstmts.nim index c430dd062..9c067a339 100644 --- a/compiler/ccgstmts.nim +++ b/compiler/ccgstmts.nim @@ -1115,10 +1115,10 @@ proc genTryGoto(p: BProc; t: PNode; d: var TLoc) = # 3. finally is run for exception handling code without any 'except' # handler present or only handlers that did not match. linefmt(p, cpsStmts, "*nimErr_ += oldNimErr$1_ + (*nimErr_ - oldNimErrFin$1_); oldNimErr$1_ = 0;$n", [lab]) - raiseExit(p) endBlock(p) # restore the real error value: linefmt(p, cpsStmts, "*nimErr_ += oldNimErr$1_;$n", [lab]) + if p.prc != nil: raiseExit(p) proc genTrySetjmp(p: BProc, t: PNode, d: var TLoc) = # code to generate: diff --git a/tests/destructor/tgotoexceptions5.nim b/tests/destructor/tgotoexceptions5.nim new file mode 100644 index 000000000..41e62aba0 --- /dev/null +++ b/tests/destructor/tgotoexceptions5.nim @@ -0,0 +1,39 @@ +discard """ + output: ''' +before +swallowed +before +swallowed B +''' + cmd: "nim c --gc:arc --exceptions:goto $file" +""" + +# bug #13599 +proc main() = + try: + echo "before" + raise newException(CatchableError, "foo") + except AssertionError: + echo "caught" + echo "after" + +try: + main() +except: + echo "swallowed" + +proc mainB() = + try: + echo "before" + raise newException(CatchableError, "foo") + # except CatchableError: # would work + except AssertionError: + echo "caught" + except: + raise + echo "after" + +try: + mainB() +except: + echo "swallowed B" |