diff options
-rw-r--r-- | compiler.c | 8 | ||||
-rw-r--r-- | tests/03_bugs/01_try_catch_stack_mismatch | 24 |
2 files changed, 28 insertions, 4 deletions
@@ -2427,14 +2427,14 @@ uc_compiler_compile_try(uc_compiler *compiler) !uc_compiler_parse_check(compiler, TK_EOF)) uc_compiler_compile_declaration(compiler); - /* jump beyond catch branch */ - try_to = chunk->count; - jmp_off = uc_compiler_emit_jmp(compiler, 0, 0); - uc_compiler_parse_consume(compiler, TK_RBRACE); uc_compiler_leave_scope(compiler); + /* jump beyond catch branch */ + try_to = chunk->count; + jmp_off = uc_compiler_emit_jmp(compiler, 0, 0); + /* Catch block ---------------------------------------------------------- */ if (try_to > try_from) { 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 -- |