Repository navigation
fix(parser): count consumed physical lines into unclosed-compound EOF report (Refs #3605) - #3681
Merged
Merged
Conversation
… 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>
Member
Author
|
【WIN-AGENT-AUDIT】 机制核查:
腿:
F 点:无 未跑/VOID 的腿:无 |
caomengxuan666
marked this pull request as ready for review
November 16, 2026 07:10
This was referenced Nov 16, 2026
Member
Author
|
【WIN-AGENT-AUDIT】S 波 s6 批次汇总(PR #3681 / #3680 / #3678 / #3676 / #3675 / #3674 / #3673 / #3672 / #3671 / #3670)
合并后自检(master 尖 阻塞项 / 待队长裁断:
原始证据(本 worktree,未提交): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 tokenpositionalone. GNU'sline_numberat EOF counts every physical line the reader consumed (parse.y:2504per-line bump + the final exhaustion read, reported byparse.y:6890-6901's yyerror EOF path) — which includes linespositiondoes not see:Token::heredoc_end_line, whilepositionstays at the<<line (it feeds theat line Nwarning);\n\n/blank/comment tail's line-break;ends atend_position, not its first-lineposition.{ cat <<EOF\nxreported the{'-EOF atline 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: newtoken_last_consumed_line=max(position, end_position, heredoc_end_line); the token-slicelast_linecomputations inunclosed_brace_eof_node,unclosed_paren_eof_nodeandunclosed_keyword_eof_nodeall max over it;push_unclosed_paren_error's non-heredoc arm folds it alongside the existingheredoc_end_lineterm. The collapsed-{inner_textarm's text count subtracts a trailing newline (it completes a consumed line rather than starting one).Verification
{/(/function bodies with and without trailing newline, blank/comment/whitespace tails,\<newline>continuations,if/while/for/until/select/caseopeners, eval-wrapped variants.tests/issue3605_compound_eof_last_line.rs(4 cases).odcolumn-padding environment issue inheredoc_regressions(unrelated).heredoc_end_linecompletes 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 priorpositioncount.