diff options
author | Jo-Philipp Wich <jo@mein.io> | 2021-03-31 10:07:04 +0200 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2021-03-31 12:11:02 +0200 |
commit | 97bf297aebaca893734edc5d90a225479494c218 (patch) | |
tree | e38835ca0566911bd9313eeb98f21aa0aca5e5e2 /compiler.c | |
parent | f0e2a6494b7553a89611bd7062459071119dae3c (diff) |
compiler: ensure that alternative if/for/while syntax has own block scope
The `if ...: endif`, `for ...: endfor`, `while ...: endwhile` etc. syntax
statements are supposed to have their own lexical scope, like curly brace
blocks in normal statements.
Without this, local variable declarations within such blocks would
incorrectly shift stack offsets for the remainder of the program.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'compiler.c')
-rw-r--r-- | compiler.c | 4 |
1 files changed, 4 insertions, 0 deletions
@@ -1867,12 +1867,16 @@ uc_compiler_compile_local(uc_compiler *compiler) static uc_tokentype_t uc_compiler_compile_altifblock(uc_compiler *compiler) { + uc_compiler_enter_scope(compiler); + while (true) { switch (compiler->parser->curr.type) { case TK_ELIF: case TK_ELSE: case TK_ENDIF: case TK_EOF: + uc_compiler_leave_scope(compiler); + return compiler->parser->curr.type; default: |