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 /tests | |
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 'tests')
-rw-r--r-- | tests/03_bugs/12_altblock_stack_mismatch | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/tests/03_bugs/12_altblock_stack_mismatch b/tests/03_bugs/12_altblock_stack_mismatch new file mode 100644 index 0000000..6805888 --- /dev/null +++ b/tests/03_bugs/12_altblock_stack_mismatch @@ -0,0 +1,26 @@ +When compiling alternative syntax blocks, such as `for ...: endfor`, +`if ...: endif` etc., the compiler didn't assign the contained statements +to a dedicated lexical scope, which caused a stack mismatch between +compiler and vm when such blocks declaring local variables weren't +actually executed. + +-- Expect stdout -- +2 +-- End -- + +-- Testcase -- +{% + if (false): + let a = 1; + endif; + + /* Due to lack of own lexical scope above, the compiler assumed + * that `a` is still on stack but the code to initialize it was + * never executed, so stack offsets were shifted by one from here + * on throughout the rest of the program. */ + + let b = 2; + + print(b, "\n"); +%} +-- End -- |