Repository navigation
WIP: fix(expand): positional holders in indirect transforms (#2608) - #2609
Merged
Merged
Conversation
… resolution
${!N@op} — indirect expansion with a transformation operator —
resolved its holder only in env_vars, so a target name held in a
positional parameter never resolved and the transform silently
expanded to empty (ble.sh's ble/is-array, [[ ${!1@a} == *a* ]], read
every array as a non-array; niu#805).
GNU subst.c parameter_brace_find_indir (7839-7881) expands the holder
as a parameter reference — subst.c:7907-7910: an indirect reference
to a positional parameter or a special parameter is ok — and
get_var_and_type (subst.c:8540) names the transform's variable
through the same resolution before parameter_brace_transform
(subst.c:8923) applies the operator to the resolved variable.
Mirror that: the new Executor::indirect_holder_target_name factors
the holder resolution the plain ${!...} path performs inline in
expand_braced_special.rs (# -> last positional value, ? -> exit
status text, bare nameref -> its target name, numeric holder ->
positional window, name[sub] -> element value, any other name -> the
variable's scalar form via indirect_source_scalar_value), and both
arms of indirect_parameter_transform resolve through it — the plain
arm for the target name, the [@]/[*] arm for a non-env source's
scalar value (env sources keep contributing raw storage,
rubash#1147). An unresolvable holder still returns None and falls
through to the plain path / word error scan, preserving the
unset-holder outcomes.
Tests: tests/issue2608_indirect_positional_transform_regressions.rs
— the issue's three lines verbatim, @a/@Q/@A/@k/@U at $1 and
@a/@A/@k/@k at $2 (assoc target reports A), a name[sub] holder, an
unset positional holder, and [@]/[*]-arm variable-source controls.
Expectations generated from GNU bash 5.3.20 script-file probes.
Refs #2608
caomengxuan666
force-pushed
the
fix/2608-indirect-positional-transform
branch
from
November 2, 2026 11:31
2af17ba to
5f1b238
Compare
… not the array join Captain verification of the #2608 fix: `${!holders[0]@A}` with holders=(arr zz) errored `arr zz: invalid variable name` while the plain `${!holders[0]}` resolved fine. The word error scan's array-operator arm computed t for EVERY subscripted indirect source as the dollar_at join of all elements. That join is GNU's t only for the [@]/[*] subscript, where array_value runs with AV_ALLOWALL (arrayfunc.c:1563). For a general subscript, parameter_brace_find_indir / parameter_brace_expand_indir (subst.c:7839-7885, 7924-7945) resolve the subscripted reference itself and t is the single element's value, validated before the operator applies (subst.c:7955-7961). The scan now splits on the subscript kind: [@]/[*] keeps the join adjudication verbatim; any other subscript validates t from array_element_parameter_value on the full reference - the exact fetch the plain form's scan arm and the plain expansion path (expand_braced_special.rs) use for a subscripted holder - so literal, variable, and arithmetic subscripts and assoc keys all judge the element GNU judges. The value path (indirect_holder_target_name) already resolved subscripted holders through that fetch; the scan was the remaining consumer of the joined scalar. Probed on GNU bash 5.3.20 with script files (workdir probes-repair/): sub0_a=[a], sub1_Q=['hi there'], variable / arithmetic / assoc-key holders all ['hi there'], an unset element silent; an element of "1bad" under @q, :- and assoc @q tails reports `1bad: invalid variable name` and aborts the command (rc=1) in all three shapes. Pins for the whole class added to the issue2608 stem. Refs #2608 (PR #2609).
caomengxuan666
marked this pull request as ready for review
November 2, 2026 12:05
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refs #2608
${!N@op}— indirect expansion with a transformation operator whose target name is held in a positional parameter — silently expanded to empty: the transform entry (indirect_parameter_transform) resolved its holder inenv_varsonly, and positional parameters do not live there. This is the defect that made ble.sh'sble/is-array([[ ${!1@a} == *a* ]]) report every array as a non-array (niu#805).Fix follows GNU's own structure:
parameter_brace_find_indir(subst.c:7839-7881) expands the holder as a parameter reference — "An indirect reference to a positional parameter or a special parameter is ok" (subst.c:7907-7910) — andget_var_and_type(subst.c:8540) names the transform's variable through that same resolution. The newExecutor::indirect_holder_target_namefactors the holder resolution the plain${!...}path performs inline inexpand_braced_special.rs(#→ last positional value,?→ exit-status text, bare nameref → target name, numeric holder → positional window,name[sub]→ element value, other names → scalar form viaindirect_source_scalar_value), and both arms ofindirect_parameter_transformnow resolve through it. Unresolvable holders still fall through to the plain path / word error scan.Tests:
tests/issue2608_indirect_positional_transform_regressions.rs— the issue's three lines verbatim; @a/@Q/@A/@k/@U at $1 and @a/@A/@k/@k at $2 (assoc target →A); aname[sub]holder; an unset positional holder; [@]/[*]-arm variable-source controls. All expectations generated by running the probe scripts through GNU bash 5.3.20 as script files. Test stem UNVERIFIED-BY-CAPTAIN (cluster is code-only per the 2026-11-02 pace directive;cargo check --testsclean, per-file rustfmt clean).