Skip to content

fix(executor): feed ( of $( to the case-word tracker in comsub walkers (Refs #3605) - #3696

Merged
caomengxuan666 merged 2 commits into
masterfrom
devin/comsub-case-paren-boundary
Nov 16, 2026
Merged

caomengxuan666 merged 2 commits into
masterfrom
devin/comsub-case-paren-boundary

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Summary

Refs #3605 (macOS gate class D, run-comsub-posix).

Every $( arm that consumed the ( inline skipped it for the case WORD in tracker too, so word_boundary stayed false after $( and a case right at a nested substitution's start never armed the tracker. The pattern ) then decremented paren depth: $(echo $(case w in e) echo l;; esac) truncated the outer span at esac) — the inner substitution's own closer — the body tokenized unclosed, and the driver reported unexpected EOF while looking for matching ')'.

GNU treats ( as a reserved-word-permitting separator (special_case_tokens, parse.y:3369-3386) and reads the comsub body as fresh input in parse_comsub (parse.y:4451), so $(case is a command-position keyword.

  • Feed the skipped ( through the tracker (and update prev_sig) in the four walkers that consume it inline:
    • src/executor/substitution_metadata.rs scan_substitution_spans
    • src/lexer/quotes.rs copy_dollar_paren_body_raw / copy_dollar_paren_body_raw_cursor
    • src/executor/command_prepare.rs copy_comsub_body_verbatim_for_ifs_marking
  • The earlier nested_case_subst arms (the $(-inside-case-context direction) and the ')' if !single && !double case-skip arm in collect_command_substitution_source_ex ride along — same class-D subsystem.
  • parser/command_substitution.rs dollar_command_substitution feeds every ( to the tracker and was never affected.

Verified (macOS, GNU bash 5.3.20)

  • cv6–cv11 / cvnest matrix byte-identical: $(echo $(case w in e) x;; esac)), $(echo $(case $(w) in e) x;; esac)), top-level x=$(case w in e) x;; esac), mixed assignment v=$(a=$(case $(w) in e) echo k;; esac); echo "$a").
  • niubash gate run-comsub-posix: the $(case truncation class is gone; remaining diff is the previously flagged error-reprint family (: $(case ...) reprint shape + case:/syntax-error: progname + line-number format) — separate root cause.
  • New tests/issue3605_nested_case_comsub_spans.rs pins four shapes (nested case, nested $(subject), top-level, mixed-assignment).

Flagged sibling

src/executor/alias_helpers.rs::copy_dollar_paren_body keeps the naive paren counter — reachable only through alias-value text containing $(case; noted on the issue for a follow-up.

…lkers (Refs #3605)

run-comsub-posix class D. Every `$(` arm that consumed the `(` inline
skipped it for the `case WORD in` tracker too, so `word_boundary`
stayed false after `$(` and `case` right at a nested substitution's
start never armed the tracker. The pattern `)` then decremented paren
depth: `$(echo $(case w in e) echo l;; esac)` truncated the outer
span at `esac)` (the inner substitution's own closer), the body
tokenized unclosed, and the driver reported
`unexpected EOF while looking for matching ')'`.

GNU treats `(` as a reserved-word-permitting separator
(special_case_tokens, parse.y:3369-3386) and reads the comsub body as
fresh input in parse_comsub (parse.y:4451), so `$(case` is a
command-position keyword. Feed the skipped `(` through the tracker
(and update prev_sig) in the four walkers that consume it inline:
substitution_metadata.rs scan_substitution_spans,
lexer/quotes.rs copy_dollar_paren_body_raw[_cursor],
command_prepare.rs copy_comsub_body_verbatim_for_ifs_marking.

The sibling nested-case arms (nested_case_subst) already cover the
`$(` inside a case context; parser dollar_command_substitution feeds
every `(` to the tracker and was never affected.

Verified vs GNU bash 5.3.20 (macOS, script files): the cv6-cv11 /
cvnest matrix is byte-identical — `$(echo $(case w in e) x;; esac))`,
`$(echo $(case $(w) in e) x;; esac))`, top-level and mixed-assignment
shapes. New tests/issue3605_nested_case_comsub_spans.rs pins four.

Remaining run-comsub-posix diff is the previously flagged
error-reprint family (`: $(case ...)` reprint shape + case:
progname/line-number format) — separate root cause, tracked on the
issue. alias_helpers::copy_dollar_paren_body keeps the naive counter
(alias-value text only); flagged in the same comment.

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@caomengxuan666
caomengxuan666 marked this pull request as ready for review November 16, 2026 09:40
@caomengxuan666
caomengxuan666 merged commit d3f1cce into master Nov 16, 2026
8 of 12 checks passed
@caomengxuan666

Copy link
Copy Markdown
Member Author

【WIN-AGENT-AUDIT】PR #3696 第1轮 — 建议:PASS(已合并 squash d3f1cce)

head(合并时): a7c5f6b base(merge-base): 96802ca 文件: 6 个 +293/-11
关联 issue: #3605(状态:open,我核过的时间:2026-11-16 本地)— #3605 是 macOS gate 伞目录,PR 只 Refs,未关单。

机制核查:

  • GNU 语义核实:parse.y:3369-3386 special_case_tokens(( 属保留字许可分隔符)与 parse.y:4451 parse_comsub(comsub 体作为新输入重解析)引用属实。$(case 处 ( 未喂给 case-word tracker → word_boundary 假 → tracker 不 arm → pattern ) 误减 paren depth → 外层 span 在 esac) 提前截断。修法在四个 walker(scan_substitution_spans / copy_dollar_paren_body_raw{,_cursor} / copy_comsub_body_verbatim_for_ifs_marking)+ parser 侧 dollar_command_substitution 同步喂 (,并新增 nested_case_subst 深度计数保护 case 体内嵌套 $( 的 ) 归属——机制一致,非个案补丁。
  • 同族波及:embedded_mutations 的 ')' if !single && !double case-skip arm 随车修正,属同 class-D 子系统,合理。
  • 已披露 sibling:alias_helpers.rs::copy_dollar_paren_body 保留朴素 paren 计数(仅 alias 文本含 $(case 可达)——PR 明示留作 follow-up,报告认可该披露,不阻塞。
  • 无关改动:无。本 PR 删除了什么 节:无删除,正文未单列(轻微,不扣分)。

腿(逐项):

  • 钉自跑:issue3605_nested_case_comsub_spans 4 passed / 0 failed(head)。
  • fail-first:base 96802ca 上 1 passed / 3 failed,红名 = {issue3605_nested_case_comsub_mixed_assignment, issue3605_nested_case_in_comsub_body, issue3605_nested_case_subject_comsub} — 与 PR 声称的嵌套 $( 族一致;top_level 格 base 即绿(顶层形态本就工作),作边界锁保留,非废钉。
  • lib 双边:head {issue2084_session_end_restores_host_process_state} / base {issue2084_session_end_restores_host_process_state}(同 merge-base 96802ca,本 session 早前已跑)/ 差集 {}。
  • -D warnings:cargo check --lib --bins 0 警告;钉 stem --no-run 0 警告。--all-targets 基线红 issue1021 unused-import(既有,非本 PR)。
  • 卫生:rustfmt 初检发现 command_substitution.rs 2 处 fmt 违规,已补 a7c5f6bf style(parser): rustfmt ...(WSL git 提交;Windows cargo fmt 受 32K 命令行上限不可跑,WSL cargo fmt --check 全仓净);marker-lint OK;utf8-boundary clean。
  • CI:3 红任务(Rust tests / macOS / goldens)唯一红格 = issue2875_input_procsub_child_runs_as_rubash_shell 基线;其余全绿。
  • GNU 对照(WSL /usr/local/bin/bash 5.3.20,脚本文件形态):c1 eight= rc=0;c2 seven=l;c3 nine=;c4 six=k —— 与钉期望逐字节一致。

F 点:无。

续作记录:

未跑/VOID 的腿:无。

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