summaryrefslogtreecommitdiffhomepage
path: root/compiler.c
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2021-03-31 12:24:01 +0200
committerJo-Philipp Wich <jo@mein.io>2021-03-31 12:24:50 +0200
commit973cc6c865dcf6075c493125313058b650b08234 (patch)
tree82fe430b603df734bba078afbd40ac607d617c13 /compiler.c
parent97bf297aebaca893734edc5d90a225479494c218 (diff)
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 <jo@mein.io>
Diffstat (limited to 'compiler.c')
-rw-r--r--compiler.c12
1 files changed, 12 insertions, 0 deletions
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);