Skip to content

fix(parser): count consumed physical lines into unclosed-compound EOF report (Refs #3605) - #3681

Merged
caomengxuan666 merged 1 commit into
masterfrom
devin/compound-eof-consumed-line
Nov 16, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
devin/compound-eof-consumed-line

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Summary

Refs #3605 — the {-family unclosed-compound EOF residual noted on #3680.

The EOF-emitting arms of unclosed {/(/keyword compounds stamped the report line from region token position alone. GNU's line_number at EOF counts every physical line the reader consumed (parse.y:2504 per-line bump + the final exhaustion read, reported by parse.y:6890-6901's yyerror EOF path) — which includes lines position does not see:

  • a heredoc body gathered to EOF consumed through Token::heredoc_end_line, while position stays at the << line (it feeds the at line N warning);
  • a trailing \n\n/blank/comment tail's line-break ; ends at end_position, not its first-line position.

{ cat <<EOF\nx reported the {'-EOF at line 2where GNU reportsline 3; { echo x\n\nreported 2 where GNU reports 3;f() (\ncat <<EOF\nx` reported 3 where GNU reports 4.

Changes

  • src/parser/parse_loop.rs: new token_last_consumed_line = max(position, end_position, heredoc_end_line); the token-slice last_line computations in unclosed_brace_eof_node, unclosed_paren_eof_node and unclosed_keyword_eof_node all max over it; push_unclosed_paren_error's non-heredoc arm folds it alongside the existing heredoc_end_line term. The collapsed-{ inner_text arm's text count subtracts a trailing newline (it completes a consumed line rather than starting one).

Verification

  • Byte-identical vs GNU Bash 5.3.20 (macOS arm64) across 33 shapes: heredoc-EOF inside {/(/function bodies with and without trailing newline, blank/comment/whitespace tails, \<newline> continuations, if/while/for/until/select/case openers, eval-wrapped variants.
  • New pins: tests/issue3605_compound_eof_last_line.rs (4 cases).
  • EOF-diagnostic regression slice green; the only failure is the pre-existing macOS BSD od column-padding environment issue in heredoc_regressions (unrelated).
  • Note: eval/sourced-context accuracy for heredoc_end_line completes when parser/executor: rebase heredoc gather end line with token positions #3680 lands (its rebase feeds the same field); standalone this change never overshoots — an unrebased value only falls back to the prior position count.

… report (Refs #3605)

The EOF-emitting arms of unclosed `{`/`(`/keyword compounds stamped the
report line from region token `position` alone, so a heredoc body
gathered to EOF (`Token::position` stays at the `<<` line to feed the
"at line N" warning) and a trailing `\n\n`/blank/comment tail's
line-break `;` (first-line `position`) both undercounted what GNU's
reader consumed: parse.y:2504 bumps line_number per physical line and
the final exhaustion read reports one past the last consumed line
(parse.y:6890-6901 yyerror EOF path).

`{ cat <<EOF\nx` reported the `{'-EOF at line 2 where GNU reports 3;
`{ echo x\n\n` reported 2 where GNU reports 3; `f() (\ncat <<EOF\nx`
reported 3 where GNU reports 4.

`token_last_consumed_line` folds `position`/`end_position`/
`heredoc_end_line` into one last-consumed-line; the
`tokens[brace_index+1..]` slices of unclosed_brace_eof_node,
unclosed_paren_eof_node and unclosed_keyword_eof_node all max over it,
and push_unclosed_paren_error's non-heredoc arm folds it alongside the
already-present heredoc_end_line term. The collapsed-`{` inner_text
arm's text count now subtracts a trailing newline (it completes a
consumed line rather than starting one).

Verified byte-identical vs GNU Bash 5.3.20 (macOS arm64) across 33
shapes: heredoc-EOF inside `{`/`(`/function bodies with and without
trailing newline, blank/comment/whitespace tails, `\<newline>`
continuations, nested `if`/`while`/`for`/`until`/`select`/`case`
openers, and eval-wrapped variants.

tests/issue3605_compound_eof_last_line.rs pins 4 of the shapes.
EOF-diagnostic regression slice green; the only failure is the
pre-existing macOS BSD `od` column-padding environment issue in
heredoc_regressions (unrelated to the engine).

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 #3681 第1轮 — 建议:PASS
head: 28a770e base(merge-base): 96802ca 文件: 2 个 +119/-5
关联 issue: #3605(状态:open,核于 2026-11-16 本地 — 追踪目录 issue,合并不关单)

机制核查:

  • token_last_consumed_line = max(position, end_position, heredoc_end_line),覆盖 unclosed_brace/paren/keyword EOF 臂与 push_unclosed_paren_error — 对应 GNU line_number 计全部已消费物理行(parse.y:2504 逐行 bump + 末尾 exhaustion read,经 parse.y:6890-6901 yyerror EOF 路径报告)。机制贴合 GNU。
  • inner_text 臂尾随 \n 减一符合「该换行完成已消费行而非另起一行」语义。
  • diff 无关改动:无;无桥接/翻译层。

腿:

  • 钉自跑:issue3605_compound_eof_last_line 4 passed / 0 failed
  • fail-first:base(96802ca) 上 0 passed / 4 failed,红名 = {brace_eof_after_unterminated_heredoc_reports_consumed_line, inner_paren_eof_after_unterminated_heredoc_reports_consumed_line, brace_eof_counts_trailing_blank_lines, brace_eof_counts_trailing_comment_line},与 PR 声称一致
  • lib 双边:head 失败名集 {api::consumer_tests::issue2084_session_end_restores_host_process_state} / base 失败名集同 / 差集 {}(该项为 Windows 本机环境 flake,双侧相同,不计本 PR 账)
  • -D warnings:lib+bins 0 警告;钉 stem 编译 0 警告(Windows --all-targets 全量在 base 上同样因既有 cfg(unix) 钉文件告警,属基线)
  • 卫生:cargo fmt -- --check 全库 0 diff;CI ubuntu job 的 UTF-8 boundary / marker blind-consumer 两步 success
  • CI:红任务 = GNU regression goldens、Rust tests、Rust tests (macOS) — 逐个核失败名仅 api::consumer_tests::issue2875_input_procsub_child_runs_as_rubash_shell(基线,master run 43779513598 同红);该失败使 pin-stem census 等后续 step 全部 skipped — CI 对新钉无覆盖,以上本地跑为准
  • GNU 对照(WSL GNU bash 5.3.20,脚本文件):{ cat <<EOF\nx → warn line2/err line3 一致;f() {\ncat <<EOF\nx → warn3/err4 一致;x=1\n{\ncat <<EOF\nx → warn4/err5 一致;{ echo x\n\n\n\n → err line5 一致;{ echo x\n# note(无尾 NL)→ err line3 一致;f() (\ncat <<EOF\nx → warn3/err4(() 一致。探针存于 .audit-s6/probes/。分组路径残差(# . marker 形下 warn prefix line3 vs GNU6)为 parser/executor: rebase heredoc gather end line with token positions #3680 修复面,本 PR 正文已声明「heredoc_end_line 精度随 parser/executor: rebase heredoc gather end line with token positions #3680 落地完成」,实测吻合,不计本 PR 账。

F 点:无

未跑/VOID 的腿:无

@caomengxuan666
caomengxuan666 marked this pull request as ready for review November 16, 2026 07:10
@caomengxuan666
caomengxuan666 merged commit aea5b15 into master Nov 16, 2026
8 of 11 checks passed
@caomengxuan666

Copy link
Copy Markdown
Member Author

【WIN-AGENT-AUDIT】S 波 s6 批次汇总(PR #3681 / #3680 / #3678 / #3676 / #3675 / #3674 / #3673 / #3672 / #3671 / #3670)

本批铁律执行情况:#3605 是 umbrella 目录 issue,本批全部 PR 只写 Refs #3605,没有关闭 #3605(现仍 OPEN);#3671 已先于 #3672 处置;DIRTY/CONFLICTING 的 #3676 未合并。

PR 处置 结果 关键证据
#3681 skip(already merged) squash aea5b152 前序 s6 已审+合,本轮不重审
#3680 skip(already merged) squash 2815ed3b 前序 s6 已审+合;已知遗留:其钉在 base 上非判别,前序已补判别探针但 cargo fmt os error 206,钩子未提交 —— 本轮按调度方要求不重做,仅记账
#3678 skip(already merged) squash bbcaafa7 前序 s6 已审+合
#3676 skip(conflicting) 未合并 mergeable=CONFLICTING;merge-tree 对当前 master 6089aefd 冲突于 src/executor/function_calls.rs、src/executor/trap_exec.rs(与已落地的 #3674/#3673 同文件相撞)。上轮 PASS 判词仅对旧 head 有效,需 rebase 后重审
#3675 skip(already merged) squash 656a0f84 前序 s6 已审+合
#3674 PASS → MERGED squash 6267c436 钉 3/3;base fail-first 2 红(eval_dollar_brace_eof_reports_eof_line、..._scales_with_caller);lib 差集 ∅;WSL GNU 5.3.20 12 形矩阵 stderr 字节一致;parse.y:6891 / evalstring.c:345
#3673 PASS → MERGED squash 23102adf 钉(本地去 cfg)3/3;base fail-first 1 红(issue3605_last_line_backslash_newline_collapses);lib 差集 ∅;WSL GNU 12 形 stdout+rc 全一致;parse.y:5376-5385
#3672 PENDING(阻塞) 未合并 分支叠在 #3671 上并整份包含其 printf 改动;#3671 已判 FAIL,按「#3671 先于 #3672」不能先落。其自身 Session::run alias-live 改动经临时 API 探针验证有判别力(父提交红 foo in v+syntax error,head 绿 foo=v bar= = GNU);另有钉在 Windows 上因未加引号的 C:\... 路径必红
#3671 FAIL 未合并 内联 precision 回绕是 Darwin libc 行为,与唯一基线 WSL GNU 5.3.20(glibc → EOVERFLOW)相反:%.9223372036854775825s GNU 报错 rc1 / 本 PR 输出 XY rc0;printf.right:393 正是 EOVERFLOW 那一行,正文「vendored .right expects XY」属误读(尾部 XY 来自 printf7.sub:91 的 %Q)
#3670 FAIL 未合并 钉 issue3605_this_sh_child_exit_trap 在 base 与 head 上全绿(废钉);静态原因:CLI 在 src/main.rs:126 启用 real shell children,${THIS_SH} 走真实 spawn(实测父子 PID 不同),进不到被改的 in-process 仿真;PR 声称的 trap.tests 尾形在 base 上本来就打印 exiting

合并后自检(master 尖 6089aefd):issue3605_eval_eof_close_char_line 3/3 绿;issue3605_grouped_trailing_continuation 按 #![cfg(unix)] 在 Windows 为 0 tests(与仓库 209 个同类 cfg(unix) 测试一致)。

阻塞项 / 待队长裁断:

  1. test(builtins): pin inline printf width/precision overflow EOVERFLOW (Refs #3605) #3671 的平台口径:GNU 的 PF() 把内联 width/precision 交给宿主 libc,GNU 自己也在 printf7.sub:86 注明「can't test %s, too many varying implementations」。rubash 是跨平台引擎,必须选一个口径;本报告按「WSL GNU 5.3.20 = 唯一基线」判 FAIL。若队长裁定要贴 macOS gate,则应改为按 target 门控,而不是全平台回绕。
  2. api: Session::run admits live expand_aliases with an empty table #3672 的落地顺序:待 test(builtins): pin inline printf width/precision overflow EOVERFLOW (Refs #3605) #3671 处置后,把 bbd29523 单独 rebase 到新 master(不要带着 printf 提交)。
  3. rubash#3605 run-func: rebase end_position with position in line_offset paths #3676 的冲突:需要在 fix(eval): report EOF-close line with the same -1 eval mapping as open lines (Refs #3605) #3674/fix(driver): keep the group's final physical newline for \<newline> collapse (Refs #3605) #3673 已落地的 master 上 rebase。
  4. fix(executor): scope in-process ${THIS_SH} child's exit-trap latch to the child (Refs #3605) #3670 的钉:需改成能进入 in-process 仿真的形状(库内 Executor/Session 且不启用 real shell children,或 ENOEXEC 仿真),并确认在 base 上红。
  5. parser/executor: rebase heredoc gather end line with token positions #3680 遗留:前序补的判别探针因 cargo fmt os error 206 未提交(非本批回归)。

原始证据(本 worktree,未提交):D:/repo/rubash-devin-s6/.audit-s6/(report-*.md、m3673/、m3674/、探针脚本与 lib 日志)。

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