Skip to content

Commit

Permalink
py/emitnative: Fix try-finally in outer scope, so finally is cancelled.
Browse files Browse the repository at this point in the history
  • Loading branch information
dpgeorge committed Sep 11, 2018
1 parent 67ee4e2 commit f2de9d6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion py/emitnative.c
Original file line number Diff line number Diff line change
Expand Up @@ -914,7 +914,7 @@ STATIC void emit_native_label_assign(emit_t *emit, mp_uint_t l) {

if (is_finally) {
// Label is at start of finally handler: pop exception stack
emit_native_leave_exc_stack(emit, true);
emit_native_leave_exc_stack(emit, false);
}
}

Expand Down
12 changes: 12 additions & 0 deletions tests/basics/try_finally1.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,15 @@ def func2():
print("except2")
print("finally1")
print()

# case where exception is raised after a finally has finished (tests that the finally doesn't run again)
def func():
try:
print("try")
finally:
print("finally")
foo
try:
func()
except:
print("except")

0 comments on commit f2de9d6

Please sign in to comment.