tests/basics: Add more tests for unwind jumps from within a try-finally.

These tests excercise cases that are fixed by the previous two commits.
This commit is contained in:
Damien George 2017-05-25 20:48:16 +10:00
parent 8f064e469d
commit 8b13cd7e19
1 changed files with 25 additions and 0 deletions

View File

@ -41,3 +41,28 @@ for i in [1]:
break break
finally: finally:
print('finally 4') print('finally 4')
# Test unwind-jump where there is nothing in the body of the try or finally.
# This checks that the bytecode emitter allocates enough stack for the unwind.
for i in [1]:
try:
break
finally:
pass
# The following test checks that the globals dict is valid after a call to a
# function that has an unwind jump.
# There was a bug where an unwind jump would trash the globals dict upon return
# from a function, because it used the Python-stack incorrectly.
def f():
for i in [1]:
try:
break
finally:
pass
def g():
global global_var
f()
print(global_var)
global_var = 'global'
g()