Skip to content

fix(executor): reject [@]/[*] in compound assignment before arith eval (#636) - #656

Merged
caomengxuan666 merged 1 commit into
masterfrom
fix/issue636-atstar-compound
Oct 16, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
fix/issue636-atstar-compound

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

fix(executor): reject [@]/[*] in compound assignment before arithmetic eval (#636)

What

a+=( [@]=q ) aborted on both shells, but GNU says [@]=q: cannot assign to non-numeric index while rubash said @: arithmetic syntax error.
GNU rejects ALL_ELEMENT_SUB before arithmetic eval, naming the whole
element word (arrayfunc.c:786-792); rubash fell through to evalexp.

Fix

Two guards (preexpanded + declare compound arms), matching the resolved
subscript exactly ([@], ['@'], [$k], both =/+= tails) before
eval_indexed_subscript_expression, emitting <word>: cannot assign to non-numeric index via diagnostic_prefix (report_error channel, no
command: segment — same as the #631 err_badarraysub fix). No abort:
like the []= arm, Err carries GNU's break (partial store kept, eval
contains it — which also fixes the eval-escape for this branch; the
a[-2]=q escape stays with #637). Assoc @ never reaches the guards
(structurally excluded — the assoc arms return first); [ @ ] stays
arithmetic (exact match, no trim); single a[@]=v untouched (different
GNU owner, arrayfunc.c:355-360, already correct).

Verification

GNU owners: arrayfunc.c:786-792 (+array.h:177 ALL_ELEMENT_SUB),
arrayfunc.c:355-360 (single-element route, untouched).

#636)

a+=( [@]=q ) aborted on both shells, but GNU says [@]=q: cannot assign
to non-numeric index while rubash said @: arithmetic syntax error. GNU
rejects ALL_ELEMENT_SUB before arithmetic eval, naming the whole element
word (arrayfunc.c:786-792); rubash fell through to evalexp.

Two guards (preexpanded + declare compound arms) match the resolved
subscript exactly ([@], ['@'], [$k], both =/+= tails) before
eval_indexed_subscript_expression, emitting <word>: cannot assign to
non-numeric index via diagnostic_prefix. No abort: like the []= arm, Err
carries GNU's break (partial store kept, eval contains it). Assoc @ never
reaches the guards (assoc arms return first); [ @ ] stays arithmetic;
single a[@]=v untouched (different GNU owner, already correct).

Verification: new 15-case GNU differential 4/15 -> 14/15 (only
declare-abort case 3 remains, reserved for #635's fatal channel; message
bytes already exact there); new tests/issue636_atstar_compound.rs (9
tests); focused suites green; full serial failure-set gate vs ea9c18e
identical (NEW=0/DISAPPEARED=0 both levels); niubash A/B identical apart
from the known load-flaky timing test (passes in isolation).
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