Repository navigation
fix(heredoc,lexer): emit comsub EOF warning independent of cat-plan admission and advance batch gather lines (Fixes #4166) - #4264
Conversation
|
Captain review — passes the gate; merge blocked only by the conflict. #4264 passed read-only review: GNU references verified line-by-line (parse.y:4513-4519, :4563-4567, :3120-3131; make_cmd.c:606-611, :622-627; redir.c:348-404), census 7 FAIL all known with 0 SIGABRT, goldens only the 2 standing snapshots, new pins 6/6 PASS, and all three #4166 faces closed with a single warning emission point preserved. As predicted in the review, #4263 merged first and the two PRs touched the same mod-registration line in |
…dmission and advance batch gather lines (Fixes #4166)
69d26e4 to
532c77e
Compare
Summary
Fixes #4166 by decoupling command-substitution EOF-terminated here-document warnings from the
catfast-path admission gate and aligning batch gather-line tracking and here-document stdin readback with GNU Bash 5.3.20.GNU C Specification
third_party/bash/parse.y:4513-4519(parse_comsub()): setsPST_EOFTOKENandshell_eof_token = ')'; pending heredocs are gathered at the end of the substitution parse (parse.y:4563-4567).third_party/bash/make_cmd.c:606-611,622-627(make_here_document()):PST_EOFTOKENaccepts delimiter-prefix +)without settingfull_line, somake_cmd.c:626-627unconditionally emitswarning: here-document at line %d delimited by end-of-file (wanted '%s')at parse/gather time regardless of command shape (non-cat, multi-stage pipelines, later commands in a list). Body lines keep their trailing newlines (make_cmd.c:622-624).third_party/bash/parse.y:3120-3135(gather_here_documents()): passes the parser's advancingline_numberto eachmake_here_document()call in FIFO operator order; after one document's delimiter line is consumed, the next pending heredoc in the same batch gathers from that physical line.third_party/bash/redir.c:348-404(heredoc_expand()/heredoc_write()): writes the expanded here-document verbatim to stdin without applying command-substitution trailing-newline trimming.Changes
src/executor/command_substitution_pipelines.rs:#4140/#4190) EOF-warning block ahead of allcatfast-path admission decline gates so 3-stage pipelines (cat <<E | sort | tr ...), non-catcommands (sort <<E), and multi-command lists (echo a; cat <<E) warn at parse time even when thecatfast path declines.last_comsub_heredoc_site(&tokens)to replay FIFOHereDoc->HereDocBodygather order (parse.y:3120-3135) and recover the exact(delimiter, gather_line, end_line)for the warned document rather than reading fromfirstor derivingwarning_linefrom the whole substitution text.src/executor/command_substitution_values.rs:report_command_substitution_heredoc_warningto take explicit(gather_line, warning_line, delimiter)instead of re-deriving line numbers and delimiter from the first command and whole source.src/lexer/mod.rs:next.gather_line = self.line_number.saturating_sub(1)when a heredoc in a multi-heredoc gather batch completes (parse.y:3130), so subsequent heredocs in the same batch carry their true gather line.src/executor/substitution_metadata.rs&src/executor/command_input_scope.rs:SubstitutionOutput::stdin_body()for here-document stdin readback (redir.c:348-404) so interior record newlines survive when multiple heredoc-fed commands concatenate.tests/issues_3900_4199/issue4166_heredoc_eof_warning_comsub_piped.rs(registered intests/issues_3900_4199.rs) &tests/issues_3900_4199/issue4141_quoted_comsub_piped_heredoc_delimiter_regressions.rs:catcomsub decline, latercatin a list, multi-heredoc batch gather lines + preserved body newlines, properly closed silence, and preceding-line offsets in bothC.UTF-8andClocales.#4141pins to assert exact GNU stderr on the 3-stage and unquoted shapes.What this PR deletes
start_line/warning_line/delimiterwhole-source re-derivation and unused_current_linelookup inExecutor::report_command_substitution_heredoc_warning(src/executor/command_substitution_values.rs).Executor::heredoc_comsub_plan(src/executor/command_substitution_pipelines.rs) after relocating it ahead of fast-path admission declines.tests/issues_3900_4199/issue4141_quoted_comsub_piped_heredoc_delimiter_regressions.rsby asserting exact GNU stderr.Verification
target/debug/rubash.exe):RUSTFLAGS="-D warnings" cargo check --lib --locked: 0 warnings.issues_3900_4199heredoc warning suites:issue4166(6/6),issue4140(4/4),issue4141(5/5),issue4190(7/7),issue4193(9/9),issue4128(5/5) — 36/36 PASS.cargo test --lib: 1,449/1,449 PASS;heredoc/comsub/comsub2snapshots PASS.scripts/check-rustfmt.py: ok (226 targets);scripts/check-marker-literals.py: OK;scripts/check-api-ledger.py: OK (298 symbols)./usr/local/bin/bash5.3.20 oracle vs Linuxrubash):RUSTFLAGS="-D warnings" cargo check --lib --locked: 0 warnings.issues_3900_4199heredoc warning suites:issue4166(6/6),issue4140(4/4),issue4141(5/5),issue4190(7/7),issue4193(9/9),issue4128(5/5) — 36/36 PASS.cat, list-second heredoc, two-heredoc batch, closed silence, preceding-line offsets, unquoted piped): 100% byte-exact stdout + stderr + exit code.