summaryrefslogtreecommitdiff
path: root/tests/basics
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2019-09-28 00:07:21 +1000
committerDamien George <damien.p.george@gmail.com>2019-10-04 23:01:29 +1000
commit82c494a97e874912e7eb23d2f03f39212e343fb3 (patch)
tree8448ae6191db319f091d4d54da72697e46163460 /tests/basics
parent0096041c9912d34a6227f647c264325b178c0384 (diff)
py/vm: Fix handling of unwind jump out of active finally.
Prior to this commit, when unwinding through an active finally the stack was not being correctly popped/folded, which resulting in the VM crashing for complicated unwinding of nested finallys. This should be fixed with this commit, and more tests for return/break/ continue within a finally have been added to exercise this.
Diffstat (limited to 'tests/basics')
-rw-r--r--tests/basics/try_finally_break2.py19
-rw-r--r--tests/basics/try_finally_continue.py17
-rw-r--r--tests/basics/try_finally_continue.py.exp9
-rw-r--r--tests/basics/try_finally_return5.py17
4 files changed, 62 insertions, 0 deletions
diff --git a/tests/basics/try_finally_break2.py b/tests/basics/try_finally_break2.py
new file mode 100644
index 000000000..086e92e90
--- /dev/null
+++ b/tests/basics/try_finally_break2.py
@@ -0,0 +1,19 @@
+def foo(x):
+ for i in range(x):
+ for j in range(x):
+ try:
+ print(x, i, j, 1)
+ finally:
+ try:
+ try:
+ print(x, i, j, 2)
+ finally:
+ try:
+ 1 / 0
+ finally:
+ print(x, i, j, 3)
+ break
+ finally:
+ print(x, i, j, 4)
+ break
+print(foo(4))
diff --git a/tests/basics/try_finally_continue.py b/tests/basics/try_finally_continue.py
new file mode 100644
index 000000000..50040e5de
--- /dev/null
+++ b/tests/basics/try_finally_continue.py
@@ -0,0 +1,17 @@
+def foo(x):
+ for i in range(x):
+ try:
+ pass
+ finally:
+ try:
+ try:
+ print(x, i)
+ finally:
+ try:
+ 1 / 0
+ finally:
+ return 42
+ finally:
+ print('continue')
+ continue
+print(foo(4))
diff --git a/tests/basics/try_finally_continue.py.exp b/tests/basics/try_finally_continue.py.exp
new file mode 100644
index 000000000..2901997b1
--- /dev/null
+++ b/tests/basics/try_finally_continue.py.exp
@@ -0,0 +1,9 @@
+4 0
+continue
+4 1
+continue
+4 2
+continue
+4 3
+continue
+None
diff --git a/tests/basics/try_finally_return5.py b/tests/basics/try_finally_return5.py
new file mode 100644
index 000000000..aa2327e65
--- /dev/null
+++ b/tests/basics/try_finally_return5.py
@@ -0,0 +1,17 @@
+def foo(x):
+ for i in range(x):
+ try:
+ pass
+ finally:
+ try:
+ try:
+ print(x, i)
+ finally:
+ try:
+ 1 / 0
+ finally:
+ return 42
+ finally:
+ print('return')
+ return 43
+print(foo(4))