Commit 3a46b19
authored
fix(compiler): pop stale bool from stack in emitLoopBackwards (#954)
emitLoopBackwards uses OpMoreOrEqual + OpJumpIfFalse to check the loop
condition, but never pops the comparison result from the stack. This
leaves a stale bool that corrupts the value stack for the parent context.
When findLast or findLastIndex is used inside a map literal like
{"r": findLast([1, 2, 3], # > 3)}, the OpMap opcode tries to pop a
string key but finds the leftover bool instead, causing:
interface conversion: interface {} is bool, not string
The forward-iterating emitLoop avoids this by using OpJumpIfEnd, which
checks scope.Index directly without touching the stack.
Fix: add OpPop after OpJumpIfFalse (continue path) and after patchJump
(exit path), matching the convention used by emitCond and every other
OpJumpIfFalse callsite in the compiler.
Fixes #950
Co-authored-by: lawrence3699 <lawrence3699@users.noreply.github.com>1 parent b90e77c commit 3a46b19
2 files changed
Lines changed: 18 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1213 | 1213 | | |
1214 | 1214 | | |
1215 | 1215 | | |
| 1216 | + | |
1216 | 1217 | | |
1217 | 1218 | | |
1218 | 1219 | | |
1219 | 1220 | | |
1220 | 1221 | | |
1221 | 1222 | | |
| 1223 | + | |
1222 | 1224 | | |
1223 | 1225 | | |
1224 | 1226 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1275 | 1275 | | |
1276 | 1276 | | |
1277 | 1277 | | |
| 1278 | + | |
| 1279 | + | |
| 1280 | + | |
| 1281 | + | |
| 1282 | + | |
| 1283 | + | |
| 1284 | + | |
| 1285 | + | |
| 1286 | + | |
| 1287 | + | |
| 1288 | + | |
| 1289 | + | |
| 1290 | + | |
| 1291 | + | |
| 1292 | + | |
| 1293 | + | |
1278 | 1294 | | |
1279 | 1295 | | |
1280 | 1296 | | |
| |||
0 commit comments