Skip to content

[6.40] [treeplayer] Fix Alt$(array) to iterate correctly when used standalone#22667

Merged
guitargeek merged 1 commit into
root-project:v6-40-00-patchesfrom
root-project-bot:BP_6.40_pull_22599
Jun 19, 2026
Merged

[6.40] [treeplayer] Fix Alt$(array) to iterate correctly when used standalone#22667
guitargeek merged 1 commit into
root-project:v6-40-00-patchesfrom
root-project-bot:BP_6.40_pull_22599

Conversation

@root-project-bot

Copy link
Copy Markdown

Backport of #22599, requested by @guitargeek.

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 root-project#6378.

🤖 Done with the help of [Claude Code](https://claude.com/claude-code) (Claude Opus 4.8)

(cherry picked from commit 0f19fe1)
@root-project-bot root-project-bot requested a review from pcanal as a code owner June 19, 2026 17:48
@guitargeek guitargeek changed the title [6.40] [treeplayer] Fix \Alt$(array)\ to iterate correctly when used standalone [6.40] [treeplayer] Fix Alt$(array) to iterate correctly when used standalone Jun 19, 2026
@guitargeek guitargeek merged commit 40cef9d into root-project:v6-40-00-patches Jun 19, 2026
29 of 30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants