Skip to content

fix(executor): treat prefixed array storage as an array, completing #755 (#755, #758) - #786

Merged
caomengxuan666 merged 1 commit into
masterfrom
fix/755-758-parameter-expansion
Oct 18, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
fix/755-758-parameter-expansion

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Refs #755. Fixes #758.

This completes the work merged as #785. That PR typed the array-vs-scalar verdict (Executor::parameter_is_array_variable) so a scalar whose text looks like (a b c) is no longer re-parsed as a list, and made malformed parameter expansions report bad substitution with the whole word and status 1 (instead of an empty string with status 0). Both behaviours are in master and verified byte-for-byte against WSL GNU Bash 5.3.0.

What this follow-up fixes

#785's typing missed the prefixed-storage case. local v=("${foo[@]}") and declare d=("${foo[@]}") render the array as \u{1d}([0]=...) before the ARRAY mark lands, so the copy collapsed into a single element holding the whole storage render:

$ f() { foo=(a 'b c' d); local v=("${foo[@]}"); printf '<%s>\n' "${v[@]}"; }; f
 GNU bash 5.3.0        master (post-#785)          this PR
 <a>                   <([0]="a" [1]="b c" [2]="d")>   <a>
 <b c>                                                  <b c>
 <d>                                                    <d>

This was caught by a pre-existing test that regressed:
command_chaining::part_003::test_local_compound_array_assignment_preserves_quoted_array_at (confirmed failing on master and fixed here; part_003 passes again).

The STORAGE_WORD_PREFIX is an unambiguous array marker — a scalar value never carries it — so it is now accepted alongside the ARRAY/ASSOC mark tables, the structured cell, and the dynamic-array registry. The BARE (a b c) shape that #755 is about deliberately stays a scalar (the prefix arm is the only addition; the bare-paren arm of is_array_storage is not reintroduced).

Verification

Residual (out of scope)

command_chaining::part_071::test_shellmath_decimal_divide_script_path, part_080::test_unclosed_arithmetic_subscript_does_not_execute_tail_bracket, part_005/part_031/part_043, and the cli_tests/regression failures are pre-existing on master in this environment (path translation, missing third_party/bash/tests, Windows signal/fd handling) — part_080 was confirmed failing on a pristine origin/master worktree.

 (#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
caomengxuan666 merged commit 141b460 into master Oct 18, 2026
8 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/755-758-parameter-expansion branch October 18, 2026 09:29
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.

a malformed parameter expansion is silently swallowed: wrong value, no diagnostic, status 0 (breaks set -e / && / ||)

1 participant