Commit af967da
Fix VM slot collision in nested list/map comprehensions
The accumulator slot for an outer list comprehension was assigned
post-analysis as `max_outer_loop_var_slot + 1`. Inner loop variables
were allocated from the same scope offset and therefore received the
same slot number (e.g. outer acc = 3, inner `_` = 3). At runtime the
inner `SetLocal` silently overwrote the outer accumulator list, causing
a panic "ListPush expects a list".
Fix: reserve the accumulator slot in the scope tree *before* analysing
the body expression via a new `ScopeTree::reserve_anonymous_slot()`.
This bumps the scope's offset so any nested loop variables receive
strictly higher slot numbers. The old post-hoc calculation in
`Expression::For` is removed.
Adds regression test bug0008.
Co-Authored-By: Claude Sonnet 4.6 <[email protected]>1 parent dad2098 commit af967da
3 files changed
Lines changed: 42 additions & 38 deletions
File tree
- ndc_interpreter/src/semantic
- tests/programs/900_bugs
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
7 | | - | |
| 6 | + | |
8 | 7 | | |
9 | 8 | | |
10 | 9 | | |
| |||
193 | 192 | | |
194 | 193 | | |
195 | 194 | | |
196 | | - | |
197 | | - | |
198 | | - | |
199 | | - | |
200 | | - | |
201 | | - | |
202 | | - | |
203 | | - | |
204 | | - | |
205 | | - | |
206 | | - | |
207 | | - | |
208 | | - | |
209 | | - | |
210 | 195 | | |
211 | 196 | | |
212 | 197 | | |
| |||
379 | 364 | | |
380 | 365 | | |
381 | 366 | | |
382 | | - | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
383 | 378 | | |
384 | 379 | | |
385 | 380 | | |
386 | 381 | | |
| 382 | + | |
387 | 383 | | |
388 | 384 | | |
| 385 | + | |
389 | 386 | | |
390 | 387 | | |
391 | 388 | | |
| |||
580 | 577 | | |
581 | 578 | | |
582 | 579 | | |
583 | | - | |
584 | | - | |
585 | | - | |
586 | | - | |
587 | | - | |
588 | | - | |
589 | | - | |
590 | | - | |
591 | | - | |
592 | | - | |
593 | | - | |
594 | | - | |
595 | | - | |
596 | | - | |
597 | | - | |
598 | | - | |
599 | | - | |
600 | | - | |
601 | | - | |
602 | | - | |
603 | | - | |
604 | 580 | | |
605 | 581 | | |
606 | 582 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
448 | 448 | | |
449 | 449 | | |
450 | 450 | | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
451 | 459 | | |
452 | 460 | | |
453 | 461 | | |
| |||
Lines changed: 20 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
0 commit comments