From 3ce6b2acb9ce21d33f0f14161b0abf89a9ff7af9 Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Sun, 27 Jan 2019 10:32:44 +0100 Subject: [PATCH] Fix exception tracking in try blocks (#10455) Exceptions raised inside a nkFinally/nkExcept block are not caught by the block itself. Fixes #3886 --- compiler/sempass2.nim | 10 +++++++++- tests/effects/teffects7.nim | 14 ++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 tests/effects/teffects7.nim diff --git a/compiler/sempass2.nim b/compiler/sempass2.nim index 81d637fee3..622e72074b 100644 --- a/compiler/sempass2.nim +++ b/compiler/sempass2.nim @@ -353,6 +353,8 @@ proc trackTryStmt(tracked: PEffects, n: PNode) = var branches = 1 var hasFinally = false + + # Collect the exceptions caught by the except branches for i in 1 ..< n.len: let b = n.sons[i] let blen = sonsLen(b) @@ -368,12 +370,18 @@ proc trackTryStmt(tracked: PEffects, n: PNode) = else: assert(b.sons[j].kind == nkType) catches(tracked, b.sons[j].typ) + else: + assert b.kind == nkFinally + # Add any other exception raised in the except bodies + for i in 1 ..< n.len: + let b = n.sons[i] + let blen = sonsLen(b) + if b.kind == nkExceptBranch: setLen(tracked.init, oldState) track(tracked, b.sons[blen-1]) for i in oldState..