Skip to content

nounset pre-scan: run subscript comsubs, honor evalerror abort - #3592

Merged
caomengxuan666 merged 1 commit into
masterfrom
fix/3540-3541-subscript-prescan
Nov 15, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
fix/3540-3541-subscript-prescan

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Summary

Refs #3540
Refs #3541

#3540: GNU evaluates an indexed subscript via expand_arith_string
(arrayfunc.c:1356 array_expand_index -> subst.c:3981), which forks each
comsub (subst.c:7143) before err_unboundvar names the parameter text.
The pre-scan's nounset_subscript_unset_name split the subscript text and
reported the comsub's first command (echo), and the braced-name arm of
nounset_unbound_parameter_with_comsubs never collected bodies inside
${...} so the child never ran. Both sides now treat $(...)/backtick
spans inside the name text as forked units: bodies are collected in
order and executed before the fatal, and the subscript scan skips them
so b[$(echo 5)]: unbound variable names the parameter, not echo.

Residual: GNU reprints the comsub canonically in the diagnostic name
(>&2 -> 1>&2, print_comsub); the reported name still carries the
verbatim text — a display-only divergence left for the reprint lane.

#3541: evalexp's error jump (expr.c) abandons parameter_brace_expand
BEFORE subst.c:8216 parameter_brace_expand_error can run, so an
arithmetic failure inside the tested subscript is the whole verdict.
scan_question_is_error now defers when the fetch raised the
fatal-expansion flags, so ${a[$(echo E; echo 5)]:?err} emits the
arith diagnostic and aborts without the extra :? report.

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

Refs #3540
Refs #3541

#3540: GNU evaluates an indexed subscript via expand_arith_string
(arrayfunc.c:1356 array_expand_index -> subst.c:3981), which forks each
comsub (subst.c:7143) before err_unboundvar names the parameter text.
The pre-scan's nounset_subscript_unset_name split the subscript text and
reported the comsub's first command (`echo`), and the braced-name arm of
nounset_unbound_parameter_with_comsubs never collected bodies inside
`${...}` so the child never ran. Both sides now treat `$(...)`/backtick
spans inside the name text as forked units: bodies are collected in
order and executed before the fatal, and the subscript scan skips them
so `b[$(echo 5)]: unbound variable` names the parameter, not `echo`.

Residual: GNU reprints the comsub canonically in the diagnostic name
(`>&2` -> `1>&2`, print_comsub); the reported name still carries the
verbatim text — a display-only divergence left for the reprint lane.

#3541: evalexp's error jump (expr.c) abandons parameter_brace_expand
BEFORE subst.c:8216 parameter_brace_expand_error can run, so an
arithmetic failure inside the tested subscript is the whole verdict.
scan_question_is_error now defers when the fetch raised the
fatal-expansion flags, so `${a[$(echo E; echo 5)]:?err}` emits the
arith diagnostic and aborts without the extra `:?` report.

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@caomengxuan666

Copy link
Copy Markdown
Member Author

【WIN-AGENT-AUDIT】
PR #3592 第1轮 — 建议:PASS
head: b2d7619 base(merge-base): 96802ca 文件: 2 个 +153/-0
关联 issue: #3540 #3541(我核过的时间:2026-11-15 本机)

机制核查:

  • [bug] set -u: unbound array element with a comsub subscript names echo and never runs the comsub #3540:pre-scan 的 name-walk 新增 `...` 与 $(...) 跳过/收集(parameter_errors.rs:3137/4157 两处),comsub 体不再被当下标文本拆出第一个命令名当 unbound 名。GNU 依据:arrayfunc.c:1356 array_expand_index → subst.c:3981 expand_arith_string(forked child, subst.c:7143)——comsub 变量属子进程,pre-scan 跳过方向正确。
  • [bug] ${a[$(...)]:?err}: an arithmetic error in the subscript still emits the :? report #3541:fetch 前后对比 arithmetic_expansion_error/arithmetic_fatal_error(parameter_errors.rs:2173+),新增错误 → NoError 让出,不叠加 :? 报告。GNU 依据:evalerror 跳转在 subst.c:8216 parameter_brace_expand_error 之前中止 parameter_brace_expand。
  • WSL GNU 5.3.20 oracle(target/p-a..e.sh):bash -c 'set -u; : ${b[$(echo 5)]}; echo done' → b[$(echo 5)]: unbound variable,rc=127(脚本形式 rc=1,钉的 -c/127 声称正确);a=(x); : ${a[$(echo E; echo 5)]:?err} → E\n5: arithmetic syntax error...,无 err 报告;子 shell 形式 st=1。三形状与钉完全一致。
  • 手扫 comsub 边界(\``/嵌套 $(`/转义)实现中规中矩,属既有 pre-scan 解析器的覆盖补全,非新增黑名单哨兵。

腿(逐项):

  • 钉自跑:cargo test --test issue3540_3541_nounset_comsub_subscript --locked @b2d7619d → 3 passed / 0 failed。
  • fail-first:merge-base → 0 passed / 3 failed,红名 = 全部三钉,症状与 issue 形状逐字一致(echo: unbound variable、comsub 副作用缺失、err 报告叠加在 arith 错后)。
  • lib 双边(CI 代跑):红名 {issue2875} 基线双边同。
  • 警告:stem 编译出 1 条新警告 unused variable: stdout(tests/issue3540_3541_nounset_comsub_subscript.rs:72,建议 _stdout)——卫生小项,非 F 点。
  • CI:三红任务名全 = {issue2875} 基线。
  • GNU 对照:上,WSL bash 5.3.20 全一致。

F 点:无。
续作记录:无。
未跑/VOID 的腿:-D warnings 全量(记录了钉文件 1 条 unused 警告);fmt 直检(CI 未报,新增代码形状随编译)。

@caomengxuan666

Copy link
Copy Markdown
Member Author

【队长终裁】PASS

核过审计报告(6886565995)+ CI 全表。钉 3/3,fail-first 0/3(全红,症状与 issue 形状逐字一致);GNU oracle 三形状全一致(comsub 体不再被当下标文本拆出命令名;evalerror 跳转中止 :? 报告叠加);CI 三红红名全为 issue2875 基线。合入条件:合入轮修掉钉文件 1 条新警告(tests/issue3540_3541_nounset_comsub_subscript.rs:72 stdout → _stdout),并补跑 lib 双边 + RUSTFLAGS="-D warnings" 全量(agent 未跑)。合入正文 Refs #3540 #3541(两单合入后由队长手动关闭)。

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