Skip to content

fix(heredoc,lexer): emit comsub EOF warning independent of cat-plan admission and advance batch gather lines (Fixes #4166) - #4264

Merged
caomengxuan666 merged 1 commit into
masterfrom
fix/4166-heredoc-eof-warning-comsub-piped
Nov 28, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
fix/4166-heredoc-eof-warning-comsub-piped

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Summary

Fixes #4166 by decoupling command-substitution EOF-terminated here-document warnings from the cat fast-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()): sets PST_EOFTOKEN and shell_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_EOFTOKEN accepts delimiter-prefix + ) without setting full_line, so make_cmd.c:626-627 unconditionally emits warning: 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 advancing line_number to each make_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:
    • Move the existing occurrence-deduped (#4140/#4190) EOF-warning block ahead of all cat fast-path admission decline gates so 3-stage pipelines (cat <<E | sort | tr ...), non-cat commands (sort <<E), and multi-command lists (echo a; cat <<E) warn at parse time even when the cat fast path declines.
    • Add last_comsub_heredoc_site(&tokens) to replay FIFO HereDoc -> HereDocBody gather order (parse.y:3120-3135) and recover the exact (delimiter, gather_line, end_line) for the warned document rather than reading from first or deriving warning_line from the whole substitution text.
  • src/executor/command_substitution_values.rs:
    • Simplify report_command_substitution_heredoc_warning to 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:
    • Advance 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:
    • Add non-trimming 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 in tests/issues_3900_4199.rs) & tests/issues_3900_4199/issue4141_quoted_comsub_piped_heredoc_delimiter_regressions.rs:
    • Add 6 regression pins covering 3-stage pipeline decline, non-cat comsub decline, later cat in a list, multi-heredoc batch gather lines + preserved body newlines, properly closed silence, and preceding-line offsets in both C.UTF-8 and C locales.
    • Tighten existing #4141 pins to assert exact GNU stderr on the 3-stage and unquoted shapes.

What this PR deletes

  • Deletes the obsolete start_line / warning_line / delimiter whole-source re-derivation and unused _current_line lookup in Executor::report_command_substitution_heredoc_warning (src/executor/command_substitution_values.rs).
  • Deletes the post-decline EOF-warning block from the bottom of Executor::heredoc_comsub_plan (src/executor/command_substitution_pipelines.rs) after relocating it ahead of fast-path admission declines.
  • Deletes the two "missing pre-existing warning" caveats in tests/issues_3900_4199/issue4141_quoted_comsub_piped_heredoc_delimiter_regressions.rs by asserting exact GNU stderr.

Verification

  • Windows (target/debug/rubash.exe):
    • RUSTFLAGS="-D warnings" cargo check --lib --locked: 0 warnings.
    • issues_3900_4199 heredoc 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 / comsub2 snapshots PASS.
    • scripts/check-rustfmt.py: ok (226 targets); scripts/check-marker-literals.py: OK; scripts/check-api-ledger.py: OK (298 symbols).
  • WSL Linux (/usr/local/bin/bash 5.3.20 oracle vs Linux rubash):
    • RUSTFLAGS="-D warnings" cargo check --lib --locked: 0 warnings.
    • issues_3900_4199 heredoc warning suites: issue4166 (6/6), issue4140 (4/4), issue4141 (5/5), issue4190 (7/7), issue4193 (9/9), issue4128 (5/5) — 36/36 PASS.
    • Script-file differential matrix against WSL GNU Bash 5.3.20 (including 3-stage pipeline, non-cat, list-second heredoc, two-heredoc batch, closed silence, preceding-line offsets, unquoted piped): 100% byte-exact stdout + stderr + exit code.

@caomengxuan666

Copy link
Copy Markdown
Member Author

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 tests/issues_3900_4199.rs — this PR is now CONFLICTING. Please rebase onto current master (bc394886) and resolve that one line. Once rebased I'll re-check mergeability and the new CI run — if census is still the same known set, it merges right away and closes #4166.

…dmission and advance batch gather lines (Fixes #4166)
@caomengxuan666
caomengxuan666 force-pushed the fix/4166-heredoc-eof-warning-comsub-piped branch from 69d26e4 to 532c77e Compare November 28, 2026 09:12
@caomengxuan666
caomengxuan666 merged commit f5ed938 into master Nov 28, 2026
11 of 13 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/4166-heredoc-eof-warning-comsub-piped branch November 28, 2026 10:34
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.

Heredoc EOF-warning face: three gaps in the quoted-comsub/piped neighbourhood (outputs correct)

1 participant