diff options
author | Jo-Philipp Wich <jo@mein.io> | 2021-03-23 11:05:25 +0100 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2021-03-23 12:30:20 +0100 |
commit | 091ae1b198e019430f342ae1444c68d6517e077e (patch) | |
tree | e4dcaebc23cadcb82ddca59f308fdc1bb71f3f5a /tests | |
parent | fcedb19bdcf09c120818ea39fec6caa7c504dad6 (diff) |
compiler: fix another try/catch miscompilation
When skipping over the catch block of a try/catch statement, make sure to
emit the jump after the try scope variables have been popped off the stack
in order to prevent a stack position mismatch between compiler and vm.
Fixes: 9ad9afb ("compiler: fix try/catch miscompilation")
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/03_bugs/01_try_catch_stack_mismatch | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/tests/03_bugs/01_try_catch_stack_mismatch b/tests/03_bugs/01_try_catch_stack_mismatch index ae7c760..f6e5a0a 100644 --- a/tests/03_bugs/01_try_catch_stack_mismatch +++ b/tests/03_bugs/01_try_catch_stack_mismatch @@ -26,3 +26,27 @@ compiler and vm, causing local variables to yield wrong values at runtime. f() %} -- End -- + + +When compiling a try/catch statement with local variable declearations +within the try block, the catch skip jump incorrectly happened before the +local try block variables were popped off the stack, leading to a stack +position mismatch between compiler and vm, causing local variables to +yield wrong values at runtime. + +-- Expect stdout -- +1 +-- End -- + +-- Testcase -- +{% + try { + let a; + } + catch {} + + let b = 1; + + print(b, "\n"); +%} +-- End -- |