From 2d3e7ca3d350d12bebfd6da4530090bfe60c6a31 Mon Sep 17 00:00:00 2001 From: "K. Lange" Date: Fri, 19 Mar 2021 11:38:26 +0900 Subject: [PATCH] Fix bad pop on bare except-finally --- src/compiler.c | 1 + test/testBareFinally.krk | 18 ++++++++++++++++++ test/testBareFinally.krk.expect | 6 ++++++ 3 files changed, 25 insertions(+) create mode 100644 test/testBareFinally.krk create mode 100644 test/testBareFinally.krk.expect diff --git a/src/compiler.c b/src/compiler.c index c503493..ddaad62 100644 --- a/src/compiler.c +++ b/src/compiler.c @@ -1820,6 +1820,7 @@ _anotherExcept: emitByte(OP_BEGIN_FINALLY); exitJumps = 0; if (nextJump != -1) { + emitByte(OP_NONE); patchJump(nextJump); emitByte(OP_POP); } diff --git a/test/testBareFinally.krk b/test/testBareFinally.krk new file mode 100644 index 0000000..22ff75e --- /dev/null +++ b/test/testBareFinally.krk @@ -0,0 +1,18 @@ +try: + raise ValueError() +except ValueError as e: + print(repr(e)) +finally: + print("Done?") + +try: + print("try") +finally: + print('finally') + +try: + print('try') +except Exception as e: + print('except') +finally: + print('finally') diff --git a/test/testBareFinally.krk.expect b/test/testBareFinally.krk.expect new file mode 100644 index 0000000..87b3e92 --- /dev/null +++ b/test/testBareFinally.krk.expect @@ -0,0 +1,6 @@ +ValueError(None) +Done? +try +finally +try +finally