Skip to content

fix(executor): bind empty array for failed compound assignment (rubash#3383) - #3458

Merged
caomengxuan666 merged 1 commit into
masterfrom
fix/3383-mixed-assign-arith-error
Nov 15, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
fix/3383-mixed-assign-arith-error

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Refs rubash#3383.

GNU arrayfunc.c:507-517 assign_array_from_string runs find_or_make_array_variable BEFORE assign_array_var_from_string expands the elements, so a brand-new compound target is bound as an empty indexed array even when an element expansion fails fatally and the command is abandoned. Rubash kept this contract in the nonfatal arm of execute_empty_words_command but returned from the fatal arm without binding, so a=($((1/0)) 2) left a unbound (declare: a: not found) where GNU leaves declare -a a=(). This PR extracts the shared helper bind_empty_array_for_failed_compound_assignment and calls it from both arms (the nonfatal arm now calls the helper instead of its inline copy, logically identical); the fatal arm calls it before every return below. A pre-existing target or a declared-but-unset one keeps its prior state (niubash #121).

Regression pin tests/issue3383_mixed_assign_arith_error.rs (11 cells, GNU 5.3.20 literal expectations). Face 2 of #3383 (pipeline-element prefix) is a separate mechanism, filed as rubash#3456 and deliberately not pinned here.

Local legs not run: the local write wall is closed (cargo rc=101 disk I/O error 778; git commit EPERM), so CI compile is the first verification; full legs run at captain review on X299/box.

本 PR 删除了什么

无产品符号删除:非致命臂的内联空数组绑定块移入同一文件内的共享 helper(同一逻辑);未删除任何公开/内部函数、符号或测试文件。

UNVERIFIED-BY-CAPTAIN

…h#3383)

GNU arrayfunc.c:507-517 assign_array_from_string runs find_or_make_array_variable BEFORE assign_array_var_from_string expands the elements, so a brand-new compound target is bound as an empty indexed array even when an element expansion fails fatally and the command is abandoned. Rubash kept this contract in the nonfatal arm of execute_empty_words_command but returned from the fatal arm without binding, so a=($((1/0)) 2) left a unbound (declare: a: not found) where GNU leaves declare -a a=(). Extract the shared helper bind_empty_array_for_failed_compound_assignment and call it from both arms (the nonfatal arm now calls the helper instead of its inline copy, logically identical); the fatal arm calls it before every return below. A pre-existing target or a declared-but-unset one keeps its prior state (niubash #121).

Refs rubash#3383. Regression pin tests/issue3383_mixed_assign_arith_error.rs (11 cells, GNU 5.3.20 literal expectations). Face 2 of #3383 (pipeline-element prefix) is a separate mechanism, filed as rubash#3456 and deliberately not pinned here.
@caomengxuan666

Copy link
Copy Markdown
Member Author

【WIN-AGENT-AUDIT】

PR #3458 第1轮 — 建议:PASS
head: 3e64567 base(merge-base): e50cea9 文件: 2 个 +304/-20
关联 issue: #3383(状态:open,我核过的时间:本地当前;本 PR 无先验评论)

机制核查:

  • 根因正确:GNU arrayfunc.c:507-517 assign_array_from_string 先跑 find_or_make_array_variable 绑变量再 expand 元素,所以全新复合赋值目标在元素展开失败时仍留下 declare -a a=() 空索引数组。旧代码只在 execute_empty_words_command 的 nonfatal 臂守此契约,fatal 臂直接 return 不绑 → a=($((1/0)) 2) 后 declare: a: not found。修复抽出共享 helper bind_empty_array_for_failed_compound_assignment 供两臂调用(防再漂移),且对既存/declared-unset 目标 no-op(保 niubash $() 内引号词仍被 glob 展开(#119 场景 2 的残留变体) #121 面)。
  • 无关改动:无。

腿(逐项):

  • 钉自跑:issue3383_mixed_assign_arith_error 为 #![cfg(unix)]——Windows 本机编译 0 tests;同 stem 在 head 的 Linux CI「Rust tests」全绿(11 格在 Linux 实跑通过)。
  • fail-first:钉无法在 Windows 执行;用钉同源脚本在 base e50cea9 手工复跑核心形状实证语义红:m8 a=($((1/0)) 2) → base declare: a: not found(GNU/head:declare -a a=());m8f 函数体形 → base 同样 not found;m8d a=(1 2); a+=($((1/0))) 在 base 即正确保留先元素(控制格,base/head 同绿)——红集与 PR 声称的 fatal-臂缺绑定面一致。
  • lib 双边:head 失败名集 {issue2084_session_end_restores_host_process_state} / base 同集 / 差集 ∅。
  • -D warnings:lib check 干净 0 警告。
  • 卫生:rustfmt --check 两文件 FMT-OK;marker-lint OK(117 consts);utf8-boundary clean。
  • CI:全绿(API ledger / compat CLI / cross-target×2 / GNU goldens / Rust tests / macOS / shell tests / Windows compile / niubash build 均 pass)。
  • GNU 对照:WSL GNU bash 5.3.20(1),脚本文件逐行语句布局(关键:同 ; 行后续命令随失败语句一并放弃,逐行才继续)。5 形状逐字节吻合:m8 a=($((1/0)) 2) → after rc=1+declare -a a=();m8d += → a=([0]="1" [1]="2");m8f 函数内 → INNER 不跑、declare -a a=();ctrl x=$((1/0)) 标量 → x=[] 续行;ctrl2 前缀形 → after rc=1。head rubash.exe 同脚本输出与 GNU 完全一致。脚本:target/probes-3458/cases/{m8,m8d,m8f,ctrl,ctrl2}.sh。

F 点:无。

续作记录:未动代码。

未跑/VOID 的腿:

  • 钉 stem 在 Windows 本地 0 tests(cfg unix);已由 Linux CI 绿 + Windows 手工等价探针(base 红 / head 绿 / GNU 三方一致)覆盖,无实质缺口。

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