1 When compiling alternative syntax blocks, such as `for ...: endfor`, 2 `if ...: endif` etc., the compiler didn't assign the contained statements 3 to a dedicated lexical scope, which caused a stack mismatch between 4 compiler and vm when such blocks declaring local variables weren't 5 actually executed. 6 7 -- Expect stdout -- 8 2 9 -- End -- 10 11 -- Testcase -- 12 {% 13 if (false): 14 let a = 1; 15 endif; 16 17 /* Due to lack of own lexical scope above, the compiler assumed 18 * that `a` is still on stack but the code to initialize it was 19 * never executed, so stack offsets were shifted by one from here 20 * on throughout the rest of the program. */ 21 22 let b = 2; 23 24 print(b, "\n"); 25 %} 26 -- End -- 27 28 29 Test a variation of the bug using `for in..endfor` loop syntax. 30 31 -- Expect stdout -- 32 2 33 -- End -- 34 35 -- Testcase -- 36 {% 37 for (let x in []): 38 let a = 1; 39 endfor; 40 41 let b = 2; 42 43 print(b, "\n"); 44 %} 45 -- End -- 46 47 48 Test a variation of the bug using `for..endfor` count loop syntax. 49 50 -- Expect stdout -- 51 2 52 -- End -- 53 54 -- Testcase -- 55 {% 56 for (let i = 0; i < 0; i++): 57 let a = 1; 58 endfor; 59 60 let b = 2; 61 62 print(b, "\n"); 63 %} 64 -- End -- 65 66 67 Test a variation of the bug using `while..endwhile` loop syntax. 68 69 -- Expect stdout -- 70 2 71 -- End -- 72 73 -- Testcase -- 74 {% 75 while (false): 76 let a = 1; 77 endwhile; 78 79 let b = 2; 80 81 print(b, "\n"); 82 %} 83 -- End --
This page was automatically generated by LXR 0.3.1. • OpenWrt