Skip to content

fix(executor): compound element word in bad substitution diagnostics (Refs #3500) - #3621

Merged
caomengxuan666 merged 4 commits into
masterfrom
fix/3500-compound-elem-diag-word
Nov 14, 2026
Merged

caomengxuan666 merged 4 commits into
masterfrom
fix/3500-compound-elem-diag-word

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Summary

A bad substitution inside a compound-assignment element was diagnosed with the ${...} fragment instead of the element word. GNU quotes the whole element and reports the word being expanded, e.g. a=([0]=${-x}) → \[0\]=${-x}.

Root cause

subscripted_parameter_element hands the RHS to whole_word_parameter_single_value, whose has_word_operator arm misjudges ${-x} (empty var_name at position 0) and expands it standalone with no pending diagnostic word installed, so expand_braced_parameter_word falls back to the synthesized ${-x} fragment. The plain-element path had the same gap (the walker default names the raw token, without quote_assign's \[sub\] quoting).

Fix

  • New compound_element_diag_word (module level, mirrors GNU quote_assign): indexed [sub]=value → \[sub\]=value; assoc elements → the bare value; a quoted value keeps the fragment's own word.
  • The element word is installed as the pending diagnostic word at the two element-expansion sites (subscripted_parameter_element, compound_plain_element_value[_fields]), install-if-absent.
  • An assoc parameter is threaded through expand_compound_positional_at_assignment[_bare] (4 call sites), computed by new compound_assignment_is_assoc (live ASSOC_VARS marking OR the declare-assoc hint).
  • New declare-assoc thread-local hint (DECLARE_ASSOC_HINT + RAII guard), installed by the declare_assoc_operand_names() scan in command_prepare.rs, covering the declare -A command-word expansion path, which runs before the declare builtin.
  • Bare (eval-argument) flatten installs no word: documented residual, not fixed here.

GNU anchors: arrayfunc.c:557/:581/:594-599/:606/:630/:938-977/:1108-1129; subst.c:10278.

Regression pin

tests/issue3500_compound_elem_diag_word.rs — 19 cells (10 fix shapes + 6 guard shapes + 2 quiet guards + 1 first-bad-wins). Expectations verified against GNU bash 5.3.20.

Verification (continuation lane, base 11719895)

  • Pin head: 19/19 (twice: before fail-first and after the stash-pop restore).
  • Fail-first: pin on base 11/19 — 8 red, each reporting Some("${-x}") where the element word is expected. git stash pop restored the tree byte-identical (sha256 verified).
  • Full lib bilateral: base 1247 passed / 0 failed / 4 ignored; head 1247 passed / 0 failed / 4 ignored — failure name-set diff empty.
  • Bin built first: cargo build --bin rubash RC=0.
  • RUSTFLAGS="-D warnings" cargo check RC=0; cargo fmt --check RC=0.
  • continuation.rs untouched.

本 PR 删除了什么

Nothing — purely additive fix plus the new regression pin. No code, test, file, or behaviour removed.

Note: the commit body was reconstructed by the continuation lane from REPORT §6/§9.2 (the original brief text was unrecoverable); captain, please amend if the wording needs it.

UNVERIFIED-BY-CAPTAIN

…(Refs #3500)

A bad substitution inside a compound-assignment element was diagnosed
with the `${...}` fragment instead of the element word. GNU quotes the
whole element (arrayfunc.c:938-977 over :1108-1129) and reports the word
being expanded (subst.c:10278), e.g. `a=([0]=${-x})` -> `\[0\]=${-x}`.

Install the element word (quote_assign mirror) as the pending diagnostic
word at the two element-expansion sites; assoc elements name the bare
value (arrayfunc.c:594-599/:630). A declare-assoc thread-local hint
(DECLARE_ASSOC_HINT + RAII guard, installed by the
declare_assoc_operand_names() scan in command_prepare.rs) covers the
`declare -A` command-word expansion path, which runs before the declare
builtin. Bare (eval-argument) flatten installs no word: documented
residual, not fixed here.

Pin: tests/issue3500_compound_elem_diag_word.rs (19 cells; fail-first
8 red on base, 19/19 on head; lib bilateral 1247 passed / 0 failed
both sides; RUSTFLAGS="-D warnings" check clean; cargo fmt clean).

NOTE: commit body reconstructed by the continuation lane from REPORT
§6/§9.2; the original brief text was unrecoverable. Captain: please
amend before merge if the wording needs it.
@caomengxuan666

Copy link
Copy Markdown
Member Author

Captain review: PASS (reviewer-run legs, spot-checked by the captain from the raw logs).

  • Pin head 19/19 (tests/issue3500_compound_elem_diag_word.rs); fail-first top-up on base 11719895 11 passed / 8 failed — all 8 reds named, each reporting base's Some("${-x}") vs the expected element word (the diagnosed root cause).
  • Neighbor array_compound_quote_regressions 17/17 on head. (The [bug] 模式词里的 bad substitution 应静默(GNU 不作参数展开诊断) #3501 pin, 68 cells, does not exist in this head tree — it arrives with the update-branch; the merge round runs it as the same-file neighbor.)
  • Lib bilateral ∅: base 1247/0/4 vs head 1247/0/4, zero FAILED lines on both sides; reviewer re-ran lib head independently: 1247/0/4.
  • RUSTFLAGS="-D warnings" on head: rc=0, 0 warnings (non-idle recompile). cargo fmt --check rc=0. utf8-boundary hygiene clean.
  • GNU oracle: all 19 pin shapes match GNU bash 5.3.20 exactly. Mechanism correct against the anchors: arrayfunc.c:938-977 (quote_assign), arrayfunc.c:594-599 (assoc skip), subst.c:10278 (whole-string diagnostic).
  • Reconstructed commit body verified byte-identical to the message on 00c0a07 and accurate. Nail-typo claim resolved: no stray backslash in the pin on disk.
  • Head CI run 43611590908: 3 failing jobs, sole FAILED name issue2875 (known baseline).

Merge round notes: intersection vs live tip 8eb07872 is exactly {src/executor/assignment_expansion.rs} via #3599 (#3501, hunks ≥164 lines from this PR's, no overlap) — no zero-intersection exception: update-branch + merged-shape re-verify mandatory (issue3500 19/19, issue3501 68/68, issue3573, lib name sets). #3581's fix (PR #3632) is disjoint — no overlap. Merge body Refs #3500 (the captain closes #3500 manually after the merge shows MERGED); strip the PR body's UNVERIFIED-BY-CAPTAIN marker and substitute these verified legs. Dossier: ~/workspace/review-3621/CAPTAIN-VERIFY.md.

@caomengxuan666
caomengxuan666 marked this pull request as ready for review November 14, 2026 17:03
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.

1 participant