Commit 0f19fe1
committed
[treeplayer] Fix Alt$(array) to iterate correctly when used standalone
A standalone Alt$ on a variable-length array, e.g.
```c++
t.Scan("Alt$(x,-1)");
```
only ever evaluated the first element of each entry instead of looping
over the whole array. The combined form `x:Alt$(x,-1)` worked because
the sibling formula `x` drove the iteration, which made the bug easy to
miss.
Root cause: `TTreeFormula::ResetDimensions()` never accounted for the
`kAlternate`/`kAlternateString` actions when computing `fMultiplicity`.
By design, `Alt$` hides its primary operand from the TTreeFormulaManager
so that, in expressions like `arr1+Alt$(arr2,0)`, `arr1` drives the loop
and the alternate pads the entries where `arr2` is too short. But when
`Alt$` is the *only* source of multiplicity there is no sibling to drive
the loop, so the formula collapsed to a single instance.
Fix: in `ResetDimensions()`, after the main operand loop, if the formula
has no other multiplicity (`fMultiplicity == 0`) scan for `kAlternate`/
`kAlternateString` operands and register their primary with the manager
when that primary is itself a genuine array.
Adds two regression tests: **AltDollarVariableArray** (standalone `Alt$`
now loops; `Alt$(x[2],-1)` keeps its fall-back behaviour) and
**AltDollarPadsShorterArray** (the documented `arr1+Alt$(arr2,0)`
padding still iterates over the longer array).
Closes #6378.
🤖 Done with the help of [Claude Code](https://claude.com/claude-code) (Claude Opus 4.8)1 parent 4f2cf43 commit 0f19fe1
2 files changed
Lines changed: 117 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5526 | 5526 | | |
5527 | 5527 | | |
5528 | 5528 | | |
| 5529 | + | |
| 5530 | + | |
| 5531 | + | |
| 5532 | + | |
| 5533 | + | |
| 5534 | + | |
| 5535 | + | |
| 5536 | + | |
| 5537 | + | |
| 5538 | + | |
| 5539 | + | |
| 5540 | + | |
| 5541 | + | |
| 5542 | + | |
| 5543 | + | |
| 5544 | + | |
| 5545 | + | |
| 5546 | + | |
| 5547 | + | |
| 5548 | + | |
| 5549 | + | |
| 5550 | + | |
| 5551 | + | |
| 5552 | + | |
| 5553 | + | |
| 5554 | + | |
| 5555 | + | |
| 5556 | + | |
| 5557 | + | |
| 5558 | + | |
| 5559 | + | |
| 5560 | + | |
| 5561 | + | |
| 5562 | + | |
5529 | 5563 | | |
5530 | 5564 | | |
5531 | 5565 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
508 | 508 | | |
509 | 509 | | |
510 | 510 | | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
511 | 594 | | |
512 | 595 | | |
513 | 596 | | |
| |||
0 commit comments