Repository navigation
fix(executor): scalar-vs-array verdict and malformed-expansion diagnostics (#755, #758) - #785
Merged
Merged
Conversation
…expansions (#755, #758) #755: a scalar whose text looks like a parenthesised list was re-parsed as an array by `"${x[@]}"`, so `x='(a b c)'` expanded to three elements and `$#` shifted. GNU decides array-ness from the variable's CELL TYPE (subst.c get_var_and_type: VT_VARIABLE vs VT_ARRAYVAR/VT_ASSOCVAR), never the value text. Add `Executor::parameter_is_array_variable(name)` (ARRAY/ASSOC marks, the structured `shell_state.variables` cell, or the dynamic-array registry) and thread it through the list/subscript read paths, so a scalar is a one-element list everywhere and a genuine array still fans out. #758: a malformed parameter expansion was swallowed as an empty string with status 0 and no diagnostic. Tighten the `valid_brace_expansion_word` gate to require an `identifier[non-empty-subscript]` whose `]` is the last byte (so `${v[0]x}`/`${v[a]b}`/`${v[@]x}` fail), reject the empty substring operand `${v:}`/`${@:}` (while `${v::}`/`${v: }`/`${v:0:}` stay valid), and report the WHOLE word GNU's `report_error` names (subst.c:10278) via a one-shot enclosing-word record set by the immutable and mutable walkers. Tests: tests/issue755_scalar_array_expansion.rs and tests/issue758_bad_substitution_status.rs (sandboxed CWD; value/stdout/ stderr/status asserted separately, with genuine-array and valid-form guards).
caomengxuan666
added a commit
that referenced
this pull request
Oct 17, 2026
(#755, #758) PR #785 typed the array-vs-scalar verdict (`parameter_is_array_variable`) but missed the prefixed-storage case: `local v=("${foo[@]}")` / `declare d=("${foo[@]}")` render `\u{1d}([0]=...)` while the ARRAY mark lands late, so the copy collapsed into a single element holding the whole storage render (a regression in the merged #785 — `command_chaining::part_003::test_local_compound_array_assignment_preserves_quoted_array_at`). The STORAGE_WORD_PREFIX is an UNAMBIGUOUS array marker (a scalar value never carries it), so it is now accepted; the bare `(a b c)` shape that #755 is about deliberately stays a scalar. Adds the declared-compound-copy guard to tests/issue755_scalar_array_expansion.rs. Refs #755. Fixes #758.
caomengxuan666
added a commit
that referenced
this pull request
Oct 18, 2026
(#755, #758) (#786) PR #785 typed the array-vs-scalar verdict (`parameter_is_array_variable`) but missed the prefixed-storage case: `local v=("${foo[@]}")` / `declare d=("${foo[@]}")` render `\u{1d}([0]=...)` while the ARRAY mark lands late, so the copy collapsed into a single element holding the whole storage render (a regression in the merged #785 — `command_chaining::part_003::test_local_compound_array_assignment_preserves_quoted_array_at`). The STORAGE_WORD_PREFIX is an UNAMBIGUOUS array marker (a scalar value never carries it), so it is now accepted; the bare `(a b c)` shape that #755 is about deliberately stays a scalar. Adds the declared-compound-copy guard to tests/issue755_scalar_array_expansion.rs. Refs #755. Fixes #758.
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.
Fixes #755 and #758. The working branch was committed by a session that ended before it built, pushed or opened the PR; I completed the loop (build, byte-comparison against GNU, both new test files, push) and verified the behaviour before opening this.
#755 — a scalar whose text looks like a parenthesised list was re-parsed as an array
x='(a b c)'; printf '[%s] len=%s\n' "${x[@]}" "${#x[@]}"[(a b c)] len=1[a] len=b/[c] len=3[(a b c)] len=1set -- "${x[@]}"; echo argc=$#argc=1argc=3argc=1The array-vs-scalar verdict is now typed rather than re-derived from the value's text, so
"${x[@]}"(the documented "may be scalar or array" idiom) stops fabricating elements from ordinary data —ls-style globs, regexes, config snippets.#758 — a malformed parameter expansion was silently swallowed
v=abc; echo "[${v[0]x}]"; echo status=$?[${v[0]x}]: bad substitution, rc 1[], status 0, no stderr[${v[0]x}]: bad substitution, rc 1w=abcdef; echo "[${w:}]"; echo status=$?[${w:}]: bad substitution, rc 1[], status 0The whole word is discarded before expansion, as GNU does, so
set -e/if ! cmd/&&guards see the failure instead of success.Verification
tests/issue755_scalar_array_expansion.rs(10 passed) andtests/issue758_bad_substitution_status.rs(8 passed), sandboxed CWD.cargo fmt --checkclean (from the original commit).