Commit 18e8bf3
fix(vm): combinations on lazy iterators skipped tail combinations π’
CombinationsIter's pivot algorithm assumed `self.buffer.len()` reflects
the full pool, but for lazy sources the buffer is filled on demand.
When `indices[k-1]` reached the current buffer end the algorithm would
declare the rightmost index "at max" against the not-yet-extended pool
and advance an earlier index instead β yielding combinations out of lex
order and skipping ones whose rightmost index lived in the unpulled
tail.
Concretely, `[1, 2, 3, 4].enumerate().combinations(2)` yielded five
combinations instead of six, missing `((0, 1), (3, 4))`. Eager sources
(`[...].combinations(...)`) were unaffected.
Fix: pull `indices[k-1] + 1` before computing pivot. The rightmost index
then pivots whenever the source still has elements, matching eager
ordering. When pulls fail the buffer stays as-is and the pivot logic
correctly falls back to advancing an earlier index.
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>1 parent 3f2dbc6 commit 18e8bf3
2 files changed
Lines changed: 41 additions & 15 deletions
File tree
- ndc_vm/src
- tests/functional/programs/900_bugs
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
462 | 462 | | |
463 | 463 | | |
464 | 464 | | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
465 | 477 | | |
466 | 478 | | |
467 | 479 | | |
468 | 480 | | |
469 | 481 | | |
470 | 482 | | |
471 | 483 | | |
472 | | - | |
473 | | - | |
474 | | - | |
475 | | - | |
476 | | - | |
477 | | - | |
478 | | - | |
479 | | - | |
480 | | - | |
481 | | - | |
482 | | - | |
| 484 | + | |
483 | 485 | | |
484 | 486 | | |
485 | 487 | | |
486 | 488 | | |
487 | 489 | | |
488 | 490 | | |
489 | | - | |
490 | | - | |
491 | | - | |
492 | | - | |
493 | 491 | | |
494 | 492 | | |
495 | 493 | | |
| |||
Lines changed: 28 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 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
0 commit comments