Repository navigation
fix(expansion): apply arithmetic writes in list-subject substring expansion (rubash#3649) - #3769
Conversation
…ansion (rubash#3649)
${a[@]:$((i+=1))} and ${@:…} sliced correctly but silently dropped
the offset/length arithmetic's write (`i` stayed 0): the whole-word
list fan-outs expand these forms through the `&self` substring parse,
whose offset evaluation ran on a cloned env and discarded the writes,
and the fan-out returns the values directly, so the `&mut` parse that
applies writes live never runs for them.
Make the offset/length writes ride with the parse result
(`parse_parameter_substring_with_writes`) and commit them exactly once,
only at the consumer that uses the result; probes (and the error
pre-scan) keep the plain parse and discard them, so a bare scalar
${v:i+=1} still evaluates exactly once. Drain the deferred writes
at every fan-out success return so sequential words observe the write
left-to-right. The plain `eval_conditional_arith_value_categorized`
loses its only caller and is removed with its re-export.
GNU oracle (bash 5.2.21): 29/30 matrix cases byte-identical; the one
diff is a pre-existing diagnostic wording gap (`syntax error` vs
`arithmetic syntax error`, rc=1 both), verified identical on the
unfixed tree. New regression suite tests/issue3649_*.rs: 20/20 (14/20
fail on the unfixed tree). cargo test --lib: 1249 passed, 0 failed.
|
Thank you for the fix, @arookieofc-ai. Per the owner's rule, external PRs are reviewed by the captain first — this PR is queued for captain review; I am leaving a first-pass check here, not a merge and not a request for changes. First pass (verified from the PR and CI logs, not a re-run):
Points for the captain's review:
No other PR targets #3649, and #3649 itself stays open pending this review. Thanks again for the thorough evidence section. |
|
【WIN-AGENT-AUDIT】PR #3769 第1轮 — 建议:PASS 机制核查:
腿(逐项给数字与名字):
F 点:无 正文卫生备注(不阻塞):PR 正文含 已披露限制复核:正文称「sequential &self segment/arg/compound-element writes 仍从写前活值计算」——本审计 9 个残差形状(含同词相邻 slice、跨参数、嵌套赋值)在 head 上与 GNU 5.3 逐字节一致,该限制在所测形状上未复现;可能已被 overlay/边界 drain 覆盖,或残留面更窄,建议队长按需复核。 续作记录:无(本轮未改代码) 未跑/VOID 的腿:无 备注:本 PR 下有一条 2026-11-16T07:56:10Z 的 captain intake 评论(id=6910699194,"queued for captain review"),距本审计约 10 小时;调度方补充明确本批「已过 24h,正常审计」,故按指令完成审计,仅供队长知悉。 |
|
【WIN-AGENT-AUDIT】PR #3769 第2轮 — 建议:PASS(已合并 squash V 波收网复核:
|
Refs #3649.
Problem
${a[@]:$((i+=1))}and${@:…}sliced correctly but silently dropped the offset/length arithmetic's write: GNU printsi=1, rubash printedi=0.Root cause
The whole-word list fan-outs (
array_at_word_values,quoted_positional_at_word_values) expand these forms through the&selfsubstring parse, whose offset arithmetic ran on a cloned env and discarded the writes; the fan-out then returns the sliced values directly, so the&mutsubstring parse (which applies writes live) never runs for them.Fix
eval_parameter_substring_offsetnow returns the offset/length arithmetic's write deltas alongside the value (eval_conditional_arith_value_categorized_with_writes);parse_parameter_substring_implthreads them out throughwrites_out.parse_parameter_substring_with_writesreturns the deltas with the parse result; the nine consumer sites that USE a result commit them exactly once viaqueue_pending_subscript_writes, only inside the arm that uses the result. Probes and the error pre-scan keep the plain parse and discard the writes, so a bare scalar${v:i+=1}still evaluates exactly once.expand_command_wordandexpand_for_word_values_impl, so sequential words observe the write left-to-right (GNU order).eval_conditional_arith_value_categorizedloses its only caller and is removed, with itsexecutorre-export.Evidence
@/*/a[*], offset+length, for-list, comsub isolation, unset/out-of-range no-eval, indirect, compound assignment). The one diff is a pre-existing diagnostic wording gap (syntax errorvsarithmetic syntax error, rc=1 both), verified byte-identical on the unfixed tree.tests/issue3649_substring_offset_writes.rs: 20/20 pass; 14/20 fail on the unfixed tree (fail-first verified via stash).cargo test --lib: 1249 passed, 0 failed, 4 ignored. Neighbor suites (substring, expansion, array, positional, for-list): all green.cargo fmt --checkandgit diff --checkclean; build with 0 warnings.Limitations / out of scope
&selfsegment/arg/compound-element writes (e.g. a second slice in the same word viaat_slice_segment_values, comsub/printf args, compound-assignment elements) still compute from the pre-write live value; the finalilands at the next drain but may be short of GNU for multi-write shapes. Values are identical to today — no regression.