Skip to content

fix(parser): case-clause first command takes the pattern line (Refs #3235) - #3614

Merged
caomengxuan666 merged 2 commits into
masterfrom
fix/3235-case-clause-pattern-line
Nov 17, 2026
Merged

caomengxuan666 merged 2 commits into
masterfrom
fix/3235-case-clause-pattern-line

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Summary

Refs #3235 — case-clause stamp residual of #3209.

Root cause: the #3209 restamp walk stops at case_command by design, and nothing else restamps a clause body's first command. rubash therefore reports a redirect-first clause command at its redirect target's end line (line 4 in the issue probe), while GNU reports the pattern line (line 3).

GNU anchor (bash 5.3, parse.y): the pattern word is read at command position — the pattern_list newline_list leaves last_read_token at '\n', which reserved_word_acceptable accepts (parse.y:5900-5903) — so read_token_word plants simplecmd_lineno with the pattern line (parse.y:5850-5851). A redirection element captures the stamp only when it is still unset (parse.y:810-811), so the clause body's first command keeps the pattern line even when its redirect target is split across lines; the command word after the target does not re-plant (WORD is not in reserved_word_acceptable's set), and the plant resets only when that first command completes (clean_simple_command, parse.y:838). Wrapper commands in between (groups, if/loop conditions, time, [[ ]]) consume nothing; a nested case re-plants from its own pattern.

Fix (this PR, second commit): in parse_case_command, restamp each clause body's first redirect-first simple command to its pattern token's line, reusing the #3209 walk shape (stop at nested function/case, descend through wrappers). Pins: tests/issue3235_case_clause_pattern_line_stamp.rs — 15 cells (12 pattern-line pins + 3 guards), all byte-verified against GNU Bash 5.3.20 script-file probes.

Known residual (not pinned): a quoted-newline command word (a) >x\\<newline>y $'a<newline>b') still reports the target end line — the executor text floor in simple_command_first_word_end_line (command_text.rs) takes the max of the restamped value and the first word's newline count. Fixing that floor touches src/executor/command_text.rs, which open PR #3602 is actively editing (same-file guard), so it is recorded in the lane REPORT instead.

本 PR 删除了什么

无删除:只新增回归钉文件与 case 子句行戳对齐修法;未删除任何公开面、命令、选项或测试。

UNVERIFIED-BY-CAPTAIN

Fail-first: clause body's first redirect-first command must report
the pattern line (GNU parse.y:5850-5851 plant, 810-811 capture),
not its redirect target's end line. 15 cells, GNU 5.3.20-verified.
@caomengxuan666

Copy link
Copy Markdown
Member Author

【WIN-AGENT-AUDIT】
PR #3614 第1轮 — 建议:FAIL
head: ea58924 base(merge-base): 27e1d0d 文件: 1 个 +286/-0
关联 issue: #3235(状态:open,我核过的时间:2026-11-16 20:3x 本地)

机制核查:

  • 正文声称的第二条 commit(产品修法)不在分支上:git log 27e1d0d2..ea58924d 只有 ea58924d test: pin case-clause pattern-line stamp (Refs #3235) 一条;git diff --stat 27e1d0d2..ea58924d = tests/issue3235_case_clause_pattern_line_stamp.rs | 286 +,src/parser/case_command.rs 零改动。正文「Fix (this PR, second commit): in parse_case_command, restamp …」在 diff 中不存在 → 按规程 4.2 直接 FAIL。
  • 钉的机制/期望本身读过:GNU parse.y:810-811(重定向元素只在 simplecmd_lineno == -1 时捕获)、parse.y:5850-5851(命令位置词读完后种 pattern 行)、parse.y:838 clean_simple_command 复位,与正文叙述一致;我抽查 3 格脚本用 GNU 5.3.20 复跑,期望逐字节一致(见 GNU 对照腿)。钉方向是对的,缺的是产品修法。

腿:

  • 钉自跑(head ea58924):issue3235_case_clause_pattern_line_stamp → test result: FAILED. 3 passed; 12 failed; 0 ignored。红名 = {clause_first_command_lineno_is_pattern_line, clause_redirect_first_reports_pattern_line, group_wrapped_clause_reports_pattern_line, if_condition_clause_reports_pattern_line, leading_conditional_clause_reports_pattern_line, multi_pattern_reports_pattern_line, nested_case_reports_inner_pattern_line, paren_pattern_reports_pattern_line, second_clause_reports_its_pattern_line, time_on_next_line_clause_reports_pattern_line, time_prefixed_clause_reports_pattern_line, toplevel_clause_redirect_first_reports_pattern_line}。
  • fail-first:base 27e1d0d == head(分支只有测试文件),12 红即 base 红,红名集合与上相同。钉是有效钉(base 红),但本 PR 没有任何一行修法让它变绿。
  • lib 双边:未跑(分支相对 base 只多一个测试文件,对 lib 面零影响;判词由「声称的修法缺失」决定)。
  • -D warnings:未跑(同上)。
  • 卫生:测试文件在 head 上编译通过(上面的 test 运行即证);fmt/marker/utf8 未跑(同上)。
  • CI(head ea58924):红 = GNU regression goldens and canaries、Rust tests、Rust tests (macOS);三者的红名均为 api::consumer_tests::issue2875_input_procsub_child_runs_as_rubash_shell → 基线(逐个 job 日志核对),无本 PR 引入的 CI 红。
  • GNU 对照:WSL /usr/local/bin/bash 5.3.20(1)-release(脚本文件方式),探针 target/devin-s9/probes/p3235_{a,b,c}.sh:
    • 函数体内 a) >x\<NL>y foooo → GNU line 3 / 钉期望 line 3 → 一致
    • 顶层同形 → GNU line 2 / 钉期望 line 2 → 一致
    • a|b) 多模式 → GNU line 3 / 钉期望 line 3 → 一致

F 点:

  • F1(正文与 diff 不符,规程 4.2):正文描述的 parse_case_command restamp 修法缺失,分支只剩钉;head 上 12/15 红。复现:git diff --stat 27e1d0d2..ea58924d;cargo test --test issue3235_case_clause_pattern_line_stamp。
  • F2(可合并性):即便补上修法,正文自述的 known residual(a) >x\<NL>y $'a<NL>b' 走 command_text.rs 文本地板)仍与 GNU 不一致;正文说受 executor: port line_number_for_err_trap for ERR-trap LINENO (Refs #3553) #3602 same-file guard 阻塞,需在补 commit 时明确该残差是否留到后续 PR(不要默默扩大改动面)。

处置:不合入、不关 #3235。建议作者把声称的 parse_case_command 修法 commit push 上来(新 commit 叠加,不改写历史),再复核 15 格全绿。

未跑/VOID 的腿:

  • lib 双边 / -D warnings / fmt+marker+utf8:未跑,原因见上(分支只加测试文件,判词已由 F1 决定)。

…efs #3235)

GNU parse.y reads each pattern word at command position
(reserved_word_acceptable accepts the '\n' left by pattern_list's
newline_list, parse.y:5900-5903), so read_token_word plants
simplecmd_lineno with the pattern word's end line
(parse.y:5850-5851). A redirection element captures the stamp only
while it is unset (parse.y:810-811), so a clause body's first
redirect-first simple command reports the pattern line, not its
redirect target's end line.

Track the last pattern-content token's end line per clause and run
the #3209 restamp walk (restamp_function_body_first_command) over the
parsed clause body: wrappers consume nothing, the first simple
command ends the plant, nested case/function commands block it.
@caomengxuan666

Copy link
Copy Markdown
Member Author

【WIN-AGENT-AUDIT】PR #3614 第2轮 — 建议:PASS(续作完成:补上正文声称的产品修法 commit)
head: c6ea2e4 base(merge-base): 27e1d0d 文件: 2 个 +315/-1
关联 issue: #3235(状态:open,我核过的时间:2026-11-17 本地)

机制核查:

  • 第 1 轮 F1(正文声称的 parse_case_command 修法不在分支上)已修复:新 commit c6ea2e41 落地,生效 diff = 钉文件 +286 与 src/parser/case_command.rs +29/-1。
  • GNU 锚点复核(third_party/bash/):parse.y:5850-5851 read_token_word 在 command position 读词时 simplecmd_lineno = line_number;pattern 词在 pattern_list newline_list 后被读(last_read_token='\n',reserved_word_acceptable parse.y:5900-5903 接受)→ 每个 pattern 词都 plant,最后一个词胜;parse.y:810-811 redirection element 仅在 simplecmd_lineno == -1 时捕获;parse.y:838 command 完成时 clean_simple_command + 复位;make_cmd.c:475-504 make_simple_command 仅在首元素建 Simple->line。实现:逐 clause 跟踪最后一个 pattern-content token 的 end_position(| 分隔符不 plant),body 解析后跑 函数体首命令带重定向时报错行指向命令自身而非函数定义行(行戳捕获面) #3209 的 restamp_function_body_first_command walk(wrapper 透传、首个简单命令结束 plant、嵌套 case/function 阻断——内层 case 的 clause 在各自 parse_case_command 里已按自己的 pattern restamp)。
  • diff 无可疑/无关改动;未触 src/lexer/continuation.rs。

腿(逐项给数字与名字):

  • 钉自跑(head c6ea2e4,Windows):issue3235_case_clause_pattern_line_stamp → 15 passed / 0 failed(12 pattern-line pins + 3 guards 全绿;第 1 轮 head 上为 3/15)。
  • fail-first(merge-base 27e1d0d + 钉原样放入):3 passed / 12 failed,红名 = {clause_first_command_lineno_is_pattern_line, clause_redirect_first_reports_pattern_line, group_wrapped_clause_reports_pattern_line, if_condition_clause_reports_pattern_line, leading_conditional_clause_reports_pattern_line, multi_pattern_reports_pattern_line, nested_case_reports_inner_pattern_line, paren_pattern_reports_pattern_line, second_clause_reports_its_pattern_line, time_on_next_line_clause_reports_pattern_line, time_prefixed_clause_reports_pattern_line, toplevel_clause_redirect_first_reports_pattern_line}——与 PR 声称的 12 判别格完全一致,3 guards 在 base 上即绿。
  • 相邻 stem 回归(head vs merge-base 同跑):issue3209_function_body_first_redirect_stamp 两边同 = 23/1 {coproc_first_reports_definition_line};issue3028_continuation_error_line_regressions 同 = 22/1 {escaped_backslash_plus_continuation_reports_word_end_line};issue3053_time_procsub_first_element_stamp 同 = 19/1 {procsub_input_target_first_split_lineno};issue2769_death_notice_line_stamp_regressions 同 = 3/2 {fg_notice…, subshell_member…}——失败名集合逐一相同,均为旧 base 上的既有红(与 case 无关),非本 PR 账。case 面 8 stem(case_command_head/issue1641/1656/1393/1401/1618/1619/1721)head 全绿(45 tests)。
  • lib 双边:head 1350 passed / 1 failed {api::consumer_tests::issue2084_session_end_restores_host_process_state} / base 1350 passed / 1 failed {同左} / 差集 ∅(两边跑前均先 cargo build --locked --bin rubash)。
  • -D warnings:RUSTFLAGS="-D warnings" cargo check --locked → 0 警告。
  • 卫生:rustfmt --check src/parser/case_command.rs CLEAN(cargo fmt 在本机 os error 206,逐文件核);marker-lint OK(117 consts / 268 allowlisted);utf8 scanned src / clean。
  • CI(head c6ea2e4):红 = GNU regression goldens and canaries(红名 issue_753::case_9_declare_indexed_operand_binds_nothing + upstream_suite_slice_snapshots → master 基线)、Regression pin stem census(10523 tests / 80 failed;失败 stem 集与 master 9e895f1 基线 run 逐名 diff = 空集,同 37 stems/80 tests,且本钉 15/15 全 PASS——见 run 44010237350 job 133795233991 lines ~9394-9408)。其余 job 全绿。零本 PR 引入红。
  • GNU 对照:WSL /usr/local/bin/bash 5.3.20(1)-release(x86_64-pc-linux-gnu,脚本文件方式,探针 target/devin-y4/probes3235/s{1..8}_*.sh):headline/top-level/多模式/嵌套 case/词首折叠/第二命令/第二子句/1 8 形状,rubash 修复后与 GNU 逐字节一致(line 3/2/3/4/4/4/4/3,rc 一致;仅脚本路径前缀因调用方式不同)。

F 点(第 1 轮):

续作记录:

未跑/VOID 的腿:无。

@caomengxuan666
caomengxuan666 marked this pull request as ready for review November 17, 2026 04:01
@caomengxuan666
caomengxuan666 merged commit 735d64d into master Nov 17, 2026
10 of 12 checks passed
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