summaryrefslogtreecommitdiffhomepage
path: root/tests/custom/99_bugs/12_altblock_stack_mismatch
diff options
context:
space:
mode:
Diffstat (limited to 'tests/custom/99_bugs/12_altblock_stack_mismatch')
-rw-r--r--tests/custom/99_bugs/12_altblock_stack_mismatch83
1 files changed, 83 insertions, 0 deletions
diff --git a/tests/custom/99_bugs/12_altblock_stack_mismatch b/tests/custom/99_bugs/12_altblock_stack_mismatch
new file mode 100644
index 0000000..e350660
--- /dev/null
+++ b/tests/custom/99_bugs/12_altblock_stack_mismatch
@@ -0,0 +1,83 @@
+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 --
+
+
+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 --