Skip to content

readonly/export compound operand: one err_readonly line then DISCARD (Refs #2658) - #3598

Merged
caomengxuan666 merged 1 commit into
masterfrom
fix/2658-readonly-compound-abort
Nov 15, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
fix/2658-readonly-compound-abort

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Summary

[upstream] A W_COMPASSIGN operand of an assignment builtin binds during
word expansion (subst.c:12949-13036 expand_declaration_argument). A
readonly refusal on that nested bind splits by builtin family:

  • export/readonly (setattr.def): err_readonly prints the bare
    {name}: readonly variable and the failure is a real DISCARD
    (subst.c:13033 exp_jump_to_top_level) — inside a function the body is
    abandoned after the single line, before the special builtin runs.
    rubash printed the refusal twice and let the function continue.
  • declare/typeset/local: the nested bind surfaces through builtin_error
    with this_command_name = the enclosing function name (f: r: readonly variable), skips the bind, and the outer builtin reports
    the operand again — rubash emitted the first line without the
    function-name segment.

Pin: tests/issue2658_readonly_compound_abort.rs (6 cases, byte-checked
against vendored GNU bash 5.3.20 script-file runs).

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

…(Refs #2658)

[upstream] A W_COMPASSIGN operand of an assignment builtin binds during
word expansion (subst.c:12949-13036 expand_declaration_argument). A
readonly refusal on that nested bind splits by builtin family:

- export/readonly (setattr.def): err_readonly prints the bare
  `{name}: readonly variable` and the failure is a real DISCARD
  (subst.c:13033 exp_jump_to_top_level) — inside a function the body is
  abandoned after the single line, before the special builtin runs.
  rubash printed the refusal twice and let the function continue.
- declare/typeset/local: the nested bind surfaces through builtin_error
  with this_command_name = the enclosing function name (`f: r:
  readonly variable`), skips the bind, and the outer builtin reports
  the operand again — rubash emitted the first line without the
  function-name segment.

Pin: tests/issue2658_readonly_compound_abort.rs (6 cases, byte-checked
against vendored GNU bash 5.3.20 script-file runs).

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 #3598 第1轮 — 建议:PASS
head: 53d60ef base(merge-base): 96802ca 文件: 2 个 +159/-10
关联 issue: #2658(状态:open,我核过的时间:2026-11-15 本地)

机制核查:

  • W_COMPASSIGN 操作数在词扩展期绑定(GNU subst.c:12949 expand_declaration_argument → subst.c:13026 make_internal_declare);嵌套绑定失败时 W_FORCELOCAL 则 skip 继续、否则 subst.c:13036 exp_jump_to_top_level(DISCARD)。declare/typeset/local 在函数内带 W_FORCELOCAL → declare.def:680 sh_readonly(builtin_error 家族,this_command_name=外层函数名)→ f: r: + declare: r: 两行、继续执行;export/readonly 无 W_FORCELOCAL → error.c:453 err_readonly 裸名一行 + DISCARD 抛弃函数体。PR 按 declare_family 分流两序言类并在 function_depth==0 || !declare_family 时 DISCARD,与 GNU 输出逐字节吻合。无无关改动、无桥接层。

腿:

  • 钉自跑(head):issue2658_readonly_compound_abort 6 passed / 0 failed。
  • fail-first(base 96802ca):同 stem 2 passed / 4 failed;红名 = {readonly_compound_in_function_reports_once_and_aborts, export_compound_in_function_reports_once_and_aborts, declare_compound_in_function_reports_twice_and_continues, local_compound_in_function_reports_twice_and_continues}——base 表现为 err_readonly 行打印两次、缺 f: 函数名段,与 PR 声称的缺陷一致;scalar/top-level 两钉 base 已绿(本就正确的对照格)。
  • lib 双边:以 CI head 腿日志代——Linux 腿红集 {issue2875}(1250 中 1)、macOS 腿 {issue2875}(1243/1247);均为已知基线红,差集 ∅。
  • -D warnings:同 worktree fix(printf): pass-granular fd-1 write-failure abort (Refs #3453) #3597 head 已 0 警告;本 PR 仅动 declare_local.rs 单函数内分支 + 测试文件,rustfmt --check 两文件 OK。
  • 卫生:rustfmt --check 2 文件 OK。
  • CI:红腿 3 个(GNU regression goldens / Rust tests / Rust tests macOS),红名各仅 issue2875(基线);其余腿全绿。
  • GNU 对照:wsl bash 5.3.20(1)-release,脚本 target/p-2658{a..f}.sh,六形状全中:
    • a f() { readonly r=(4); ... }:GNU 一行 line 2: r: readonly variable、f 体弃、外层 declare 打出 declare -ar r=([0]="1") ✓
    • b export t=(4):一行、跳 f-end、outer 打印 ✓
    • c declare r=(4):f: r: + declare: r: 两行、f-end/done 打印 ✓
    • d local r=(4):f: r: + local: r: 两行 ✓
    • e 标量 readonly s=2:一行、继续 ✓
    • f 顶层 readonly r=(4):一行、同行丢弃、next-line 打印 ✓

F 点:无

未跑/VOID 的腿:本地全量 lib 与 -D warnings 全量 check 未跑(以 CI head 腿 + fmt/编译通过代替判读)。

@caomengxuan666

Copy link
Copy Markdown
Member Author

【队长终裁】PASS

核过审计报告(6886804126)+ CI 全表。钉 6/6,fail-first 2/4(4 红 = issue 形状:base err_readonly 行打印两次、缺 f: 函数名段);GNU oracle 六形状全中(readonly/export 一行 + DISCARD;declare/local 两行 + 继续;标量与顶层对照格);CI 三红红名全为 issue2875 基线;fmt 干净。合入轮补跑 lib 双边 + RUSTFLAGS="-D warnings" 全量(agent 以 #3597 同 worktree 的 0 警告代证,合入轮实跑)。合入正文 Refs #2658(合入后由队长手动关闭;#3174 的合入门仍挂 #2658/#2771——本单合入后 #2658 关,#2771 另案)。

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