Repository navigation
fix(executor): evaluate already-expanded indexed subscripts without re-expansion (Refs #3522) - #3608
Conversation
…e-expansion (Refs #3522) GNU arrayfunc.c:1353-1391 array_expand_index -> subst.c:3981 expand_arith_string runs its single expand_word_internal pass on the subscript text as received; text a parameter expansion produces is data, never re-scanned for command substitution. Rubash ran that pass twice for Raw/ExpandedOnce subscripts — resolve_array_subscript expanded `${x}` to backquote text, then eval_indexed_subscript_expression ran expand_arithmetic_subscript_mut on the result and executed it — so `x='`echo 1`'; unset 'a[${x}]'` silently removed a[1] (rc 0) where GNU fails "operand expected" (rc 1, element survives). Protected (verbatim) subscripts from assignments, W_ARRAYREF operands and `test -v` still take the single pass here (for them it IS the expand_arith_string pass), as do the compound-declare paths; the `${}`-pattern path and all Raw/ExpandedOnce callers now evaluate the resolved text as-is. Pin: tests/issue3522_unset_indexed_backquote_subscript.rs (22 cells; 9 fail-first red on base, 13 controls green on base and head).
|
【WIN-AGENT-AUDIT s1】 PR #3608 第1轮 — 建议:PASS 机制核查:
腿(逐项给数字与名字):
F 点:无 续作记录:本轮未动代码 未跑/VOID 的腿:PR 自述 #3573/#3493 邻居钉在本树不存在(正文已声明),由各自车道补;macOS/Linux 专属行为待队长 Linux oracle 复核(本机 Windows+WSL 5.3.20 已逐形对照一致) |
|
【WIN-AGENT-AUDIT s1 批次汇总】 本批 2 PR 审结:
调度问题答复:#3608 机制与 #3590 arith_grade 分流是否互斥、可否先后落地? 不互斥,可先后落地。两 PR 改的是 array_expand_index 模型的两个正交轴:
文本重叠仅在 env-bound 备忘:本机 lib 全程有 issue2084_session_end_restores_host_process_state 单红(两侧同现,非任一侧账);issue3521/issue2657 邻居钉在 Windows 各 4 红(argv0 前缀断言,cfg(unix)-only 的 arg0("bash")),双侧同红。 |
Keep both mechanisms in eval_indexed_subscript: #3608's expand gate (Protected subscripts still take the single eval-time expansion pass) and #3590's arith-grade resolve dispatch (resolve_indexed_subscript / expand_arith_string, no tilde — arrayfunc.c:1368). Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…#3613) Conflict: src/executor/arithmetic/mod.rs only. #3608 (4e2c529) replaced the two-state array_expand_once gate in eval_indexed_subscript_expression with the three-state `expand` split, so the #3613 carrier decode moves into the `else if array_expand_once` arm (AV_NOEXPAND: text stays verbatim for evalexp) and stays at the expand_arithmetic_subscript_mut entry (the expand_arith_string pass must re-lex decoded bytes). #2701's `${...}` fatal latch from master now reads the decoded text — that is what GNU's expand_arith_string (arrayfunc.c:1368 -> subst.c:3981) re-reads. Both pin stems green after the merge: issue3613 4/4, issue3522_unset_indexed_backquote_subscript 22/22, issue2701 12/12.
|
【WIN-AGENT-AUDIT】s1 批次汇总(清单:#3608、#3629) 逐 PR 结果
#3629 合流明细:只改了 src/executor/arithmetic/mod.rs 的两处冲突(#3608 把 array_expand_once 二态门换成 CI 归因:4 个红 job 中 3 个只红 issue2875(已知基线);Regression pin stem census 的 97 名里有 96 名与 master 同类 run 逐格相同(scripts/ci-pin-exclusions.txt 记录的已知红普查基线),唯一多出的 硬性必答:#3608 的 expand 门 与 #3590 的 arith_grade 分流 是否互斥、能否先后落地、顺序结论:不互斥,可先后落地;顺序应为 #3608 先(已落地 4e2c529),#3590 在其上 rebase/合流。反向顺序机械上也成立,但要多写一遍 #3608 的门,无语义收益。 1) 两者是不同的轴,不共享不变量
2) 合流证据(不是推断)
3) 给调度方的执行建议
阻塞/遗留
|
Summary
x='echo 1'; unset 'a[${x}]'silently removeda[1](rc 0) where GNU fails"operand expected" (rc 1, element survives).
Root cause
GNU
arrayfunc.c:1353-1391array_expand_index->subst.c:3981expand_arith_stringruns its singleexpand_word_internalpass on thesubscript text as received; text a parameter expansion produces is data,
never re-scanned for command substitution (
evalexpthen fails it as"operand expected",
expr.c:1120). Rubash ran that pass twice forRaw/ExpandedOnce subscripts:
resolve_array_subscriptexpanded${x}tobackquote text, then
eval_indexed_subscript_expressionranexpand_arithmetic_subscript_muton the result and executed it.Fix
eval_indexed_subscript_expressiontakes anexpand: boolgate:false— the text already went through the singleexpand_subscript_stringpass (Raw / ExpandedOnce subscripts and the${}-pattern path): evaluate the resolved text as-is.true— the text is still raw (Protected / verbatim subscripts fromassignments, W_ARRAYREF operands and
test -v, and the compound-declarepaths): this IS the single pass.
array_expand_once(AV_NOEXPAND) skips the pass either way and onlyrestores carrier markers.
Deletion
No product paths deleted; only the re-expansion gate changed (3 call sites
take the new
expandargument, plus 1 newexpandbinding ineval_indexed_subscript).Verification
tests/issue3522_unset_indexed_backquote_subscript.rs(22 cells):base 9 red / 13 green (fail-first, run against the rebuilt base binary);
head 22/22 green (cargo test at 13:54 and 14:35 UTC, plus a final 22/22
direct re-confirmation on the committed binary at 15:13 UTC).
Base red names:
unset_backquote_text_via_braced_parameter_fails,unset_backquote_text_via_unbraced_parameter_fails,unset_backquote_text_via_nameref_braced_parameter_fails,unset_backquote_text_in_compound_arithmetic_via_parameter_fails,unset_backquote_text_after_plus_via_parameter_fails,unset_backquote_invalid_output_via_braced_parameter_fails,unset_command_substitution_via_braced_parameter_fails,unset_dollar_name_via_braced_parameter_fails,unset_arith_substitution_via_braced_parameter_fails.unsetof an associative element whose key is a quote/backslash character fails as "not a valid identifier" #2657 10/10,[bug] unset ${foo:t5:h2:l} errors arithmetically instead of short-circuiting to empty #3024 23/23, [bug] unset 诊断路由谓词仍全表扫选项(操作数后 -f/-v 双置形分歧) #3343 12/12 (66/66).
0 failed / 4 ignored — identical, both failure-name sets empty.
RUSTFLAGS="-D warnings" cargo check --locked --lib --bins: rc 0, zerowarnings (full dep chain compiled/checked, non-idle).
cargo fmt --check: clean.`echo "1 2"`token, plain quotes) verified byte-identical to GNU 5.3.20 on the same
script; one pin cell was corrected accordingly (the delivery draft had
backslash-escaped quotes inside a raw string — the product output was
already GNU-correct).
Note: the #3573 and #3493 pin stems do not exist in this tree, so those two
neighbor legs could not be run here; they are owed by their own lanes.
Known residuals (out of scope, not fixed here)
unset 'a[~]'— GNU reportstoken
~, rubash reports the expanded home path; rc and outcome match)."${a[@]#...}"residual from [bug] 模式词里的 bad substitution 应静默(GNU 不作参数展开诊断) #3501).subscript_expansion.rs:1275) and thetest -varrayref arm (:711) are probe-owed, not fixed here.Refs #3522