diff options
-rw-r--r-- | compiler.c | 12 | ||||
-rw-r--r-- | tests/03_bugs/12_altblock_stack_mismatch | 57 |
2 files changed, 69 insertions, 0 deletions
@@ -2016,11 +2016,15 @@ uc_compiler_compile_while(uc_compiler *compiler) /* compile loop body */ if (uc_compiler_parse_match(compiler, TK_COLON)) { + uc_compiler_enter_scope(compiler); + if (!uc_compiler_compile_delimitted_block(compiler, TK_ENDWHILE)) uc_compiler_syntax_error(compiler, compiler->parser->curr.pos, "Expecting 'endwhile'"); else uc_compiler_parse_advance(compiler); + + uc_compiler_leave_scope(compiler); } else { uc_compiler_compile_statement(compiler); @@ -2116,11 +2120,15 @@ uc_compiler_compile_for_in(uc_compiler *compiler, bool local, uc_token *kvar, uc /* compile loop body */ if (uc_compiler_parse_match(compiler, TK_COLON)) { + uc_compiler_enter_scope(compiler); + if (!uc_compiler_compile_delimitted_block(compiler, TK_ENDFOR)) uc_compiler_syntax_error(compiler, compiler->parser->curr.pos, "Expecting 'endfor'"); else uc_compiler_parse_advance(compiler); + + uc_compiler_leave_scope(compiler); } else { uc_compiler_compile_statement(compiler); @@ -2219,11 +2227,15 @@ uc_compiler_compile_for_count(uc_compiler *compiler, bool local, uc_token *var) /* Body ----------------------------------------------------------------- */ if (uc_compiler_parse_match(compiler, TK_COLON)) { + uc_compiler_enter_scope(compiler); + if (!uc_compiler_compile_delimitted_block(compiler, TK_ENDFOR)) uc_compiler_syntax_error(compiler, compiler->parser->curr.pos, "Expecting 'endfor'"); else uc_compiler_parse_advance(compiler); + + uc_compiler_leave_scope(compiler); } else { uc_compiler_compile_statement(compiler); diff --git a/tests/03_bugs/12_altblock_stack_mismatch b/tests/03_bugs/12_altblock_stack_mismatch index 6805888..e350660 100644 --- a/tests/03_bugs/12_altblock_stack_mismatch +++ b/tests/03_bugs/12_altblock_stack_mismatch @@ -24,3 +24,60 @@ actually executed. print(b, "\n"); %} -- End -- + + +Test a variation of the bug using `for in..endfor` loop syntax. + +-- Expect stdout -- +2 +-- End -- + +-- Testcase -- +{% + for (let x in []): + let a = 1; + endfor; + + let b = 2; + + print(b, "\n"); +%} +-- End -- + + +Test a variation of the bug using `for..endfor` count loop syntax. + +-- Expect stdout -- +2 +-- End -- + +-- Testcase -- +{% + for (let i = 0; i < 0; i++): + let a = 1; + endfor; + + let b = 2; + + print(b, "\n"); +%} +-- End -- + + +Test a variation of the bug using `while..endwhile` loop syntax. + +-- Expect stdout -- +2 +-- End -- + +-- Testcase -- +{% + while (false): + let a = 1; + endwhile; + + let b = 2; + + print(b, "\n"); +%} +-- End -- |