Skip to content

fix(eval): report EOF-close line with the same -1 eval mapping as open lines (Refs #3605) - #3674

Merged
caomengxuan666 merged 1 commit into
masterfrom
devin/eval-close-char-eof-line
Nov 16, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
devin/eval-close-char-eof-line

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Summary

run-exportfunc (exportfunc.tests:82): eval 'foo() { _; } >_[${ $() }] ;{ echo eval ok; }' printed eval: line 84: unexpected EOF while looking for matching \}'where GNU printseval: line 83`.

GNU reports line_number at EOF for a matched-pair construct (yyerror EOF branch, parse.y:6883-6891), and inside eval the string's lines continue the caller's counter as caller_line + i - 1 (evalstring.c:345 line_number-- — SEVAL_RESETLINE is not set for eval). rubash's eval close-char path mapped the scan's eof_line (last content line + 1 — a line index like open_line) as caller_line + eof_line, i.e. one past the line GNU reports. This applies the identical -1 index conversion the open_line arm and both sibling call sites (command_substitution.rs, command_input_scope.rs) already use.

Refs #3605 (class B, run-exportfunc — clears the suite's only real diff; the cannot execute binary file noise belongs to #3586).

GNU anchors

  • parse.y:6883-6891 — yyerror EOF branch reports line_number at EOF.
  • builtins/evalstring.c:345 — line_number-- under push_stream(lreset=0): eval-string line i sits at caller_line + i - 1, EOF at caller_line + lines.
  • builtins/eval.def — eval passes SEVAL_NOHIST|SEVAL_NOOPTIMIZE (no SEVAL_RESETLINE).

Verification (macOS arm64, GNU bash 5.3.20 oracle)

  • niubash gate run-exportfunc → PASS (zero diff).
  • Byte-identical vs GNU on: eval 'foo() { _; } >_[${ $() }] ;{ echo eval ok; }' (caller lines 1, 3, 82), multi-line eval strings, x=${a[1 (}' close), x=$(echo foo, x=$((1+, x="foo, x=`echo, nested eval inside eval.
  • New tests/issue3605_eval_eof_close_char_line.rs (3 tests) — the EOF mapping at caller line 1, scaled across a multi-line string, and the subscript }' variant.
  • Regression slices: issue318_eval_eof_diagnostics, issue1609_eval_parse_diag_routing, issue2342_eval_arith_eof_line, issue2780_eval_arith_for_eof_line, issue3183_redirect_and_eof_lines — 46/46 green; cargo fmt --check clean.

Test plan

  • cargo test --test issue3605_eval_eof_close_char_line
  • niubash upstream gate run-exportfunc PASS
  • eval EOF diagnostic family regression slices

…n lines (Refs #3605)

GNU yyerror (parse.y:6883-6891) reports line_number at EOF for a
matched-pair construct (\'unexpected EOF while looking for matching
`X\'\'), and inside eval the eval-string lines map to the caller's
counter as caller_line + i - 1 (evalstring.c:345 line_number--,
SEVAL_RESETLINE not set). The eval close-char path in
execute_eval_source mapped the scan's eof_line (last content line + 1,
a line index like open_line) as caller_line + eof_line — one past the
line GNU reports — so exportfunc.tests:82's eval printed
'eval: line 84: unexpected EOF while looking for matching `}\'' where
GNU prints 83.

Map eof_line through the identical -1 index conversion the open_line
arm and both sibling call sites (command_substitution.rs,
command_input_scope.rs) already use. run-exportfunc now matches GNU
byte-for-byte (macOS gate PASS).

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 #3674 第2轮 — 建议:PASS(已 squash 合并 6267c436,不关单)
head: b2eb3a6 base(merge-base): 96802ca 文件: 2 个 +99/-1
关联 issue: #3605(open,umbrella 目录 issue — 按铁律不关单;核于 2026-11-16 19:2x 本地)

机制核查:

  • GNU parse.y:6891 yyerror 的 EOF 分支 parser_error (line_number, "unexpected EOF while looking for matching ..."):报的是 EOF 时的 line_number(最后一条内容行的下一行)。
  • builtins/evalstring.c:345 if (lreset == 0) line_number--;:eval 不设 SEVAL_RESETLINE(builtins/eval.def 只传 SEVAL_NOHIST|SEVAL_NOOPTIMIZE),所以 eval 串第 i 行落在 caller+i-1,EOF 落在 caller+lines。
  • rust 侧 unclosed_input_close_char_posix 的 eof_line 是行索引(src/lexer/continuation.rs:1153-1162,最后内容行 +1),所以 eval 路径必须与 open_line 臂及两个兄弟调用点(command_substitution.rs base + eof_line - 1、command_input_scope.rs 同式)一致地取 -1。改动就是把 eof_line 改成 eof_line.saturating_sub(1),与 GNU 的编号空间对齐,不是散点特判。
  • diff 只碰 src/executor/trap_exec.rs 一行 + 新测试;无顺手改无关面;无桥接/翻译层。
  • 正文:无「本 PR 删除了什么」小节(仅 1 行替换,可豁免)。

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

  • 钉自跑(head):issue3605_eval_eof_close_char_line 3 passed / 0 failed(test result: ok. 3 passed)。
  • fail-first(base 96802caf,钉文件原样放入):2 failed; 1 passed — 红名 = {eval_dollar_brace_eof_reports_eof_line, eval_dollar_brace_eof_line_scales_with_caller},与 PR 声称的映射错误面一致;base 报 eval: line 3/line 6,GNU 为 line 2/line 5。第三个钉 eval_unclosed_subscript_reports_eof_line 在 base 上本就绿(走 report_open 臂,本 PR 未触及),属既存行为钉、非本修复的判别钉 —— 记为弱钉,不阻断。
  • lib 双边:head 失败名集 {api::consumer_tests::issue2084_session_end_restores_host_process_state}(1350 passed/1 failed/4 ignored);base 同集 {同一条};差集 ∅。该条两侧同红,是环境/宿主态绑定,不记本 PR 的账。
  • -D warnings(cargo check --all-targets):rc=101,唯一告警在 tests/issue592_argv_translation_completeness.rs:249 unused variable: stdout — 非本 PR 文件,基线既有;本 PR 两文件 0 告警。
  • 卫生:rustfmt --check 两文件 clean;check-marker-literals.py → OK (117 registry consts, 268 allowlisted sites);check-utf8-boundary-hygiene.sh → clean。
  • 回归切片实跑:issue318_eval_eof_diagnostics 15/15、issue1609_eval_parse_diag_routing_regressions 3/3、issue2342_eval_arith_eof_line_regressions 12/12、issue2780_eval_arith_for_eof_line 5/5、issue3183_redirect_and_eof_lines 0 tests(平台门控)= 35/35 可跑全绿。正文写的 46/46 与实跑差 11:正文明写了两个不含 _regressions 后缀的 stem 名(真实文件名带后缀),另 issue3183 本机 0 例 —— 以实跑为准。
  • CI(head b2eb3a6f,run 43704953357):红 = Rust tests(唯一 FAIL api::consumer_tests::issue2875_input_procsub_child_runs_as_rubash_shell,consumer_tests.rs:3503 前置 "no rubash binary found")、Rust tests (macOS)(同一条 issue2875)、GNU regression goldens and canaries(同一条 issue2875 在 canary 单测里红)。三条全部归因 issue2875 基线签名,非本 PR 引入;无 E0063/编译类红。
  • GNU 对照(WSL GNU bash 5.3.20(1)-release, x86_64-pc-linux-gnu):
    • caller 第 1 行 → GNU eval: line 2 / rubash eval: line 2 → 一致
    • caller 第 3 行 + 2 行 eval 串 → line 5 / line 5 → 一致
    • exportfunc.tests:82 原形(caller 82)→ line 83 / line 83 → 一致(修前 rubash 为 84)
    • 另跑 12 形矩阵(单行/多行/带尾部换行/前导空行/嵌套函数调用 × ${、$(、$((、"、反引号、if、case):全部 stderr 字节一致,rc 均为 2。脚本:.audit-s6/gen-m3674.sh、.audit-s6/m3674/c*.sh。

F 点:无。

未跑/VOID 的腿:无。
平台局限:对照为 WSL Linux 5.3.20,非 Windows 原生;结论不依赖平台专属行为。

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