From 973cc6c865dcf6075c493125313058b650b08234 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Wed, 31 Mar 2021 12:24:01 +0200 Subject: compiler: actually expand block scope fix to for/while alt syntax Fixes: 97bf297 ("compiler: ensure that alternative if/for/while syntax has own block scope") Signed-off-by: Jo-Philipp Wich --- compiler.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'compiler.c') diff --git a/compiler.c b/compiler.c index 362ca8b..7c0a2a1 100644 --- a/compiler.c +++ b/compiler.c @@ -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); -- cgit v1.2.3