Skip to content

heredoc3/heredoc7: stderr diagnostic gaps (warning line numbers + syntax error message) #72

Closed

Description

@caomengxuan666

Summary

Two stderr-only diagnostic gaps uncovered when running heredoc3.sub and heredoc7.sub against WSL GNU Bash 5.3.0. These do not affect stdout (the harness diff is 0 for heredoc suite), only stderr diagnostics.

heredoc7.sub — warning line number

GNU:

./heredoc7.sub: line 29: warning: here-document at line 29 delimited by end-of-file (wanted `EOF')

rubash:

./heredoc7.sub: line 26: warning: here-document at line 26 delimited by end-of-file (wanted `EOF')

Root cause

cat <<EOF && grep $( on line 26 opens a heredoc, but the body (foobar, EOF) is swallowed by the command substitution $(. When the ) closes on line 29, GNU make_cmd.c:627 reports the heredoc start as the closing-paren line (29), not the <<EOF line (26).

In rubash, report_unterminated_heredoc (src/executor/public_accessors.rs:605) computes warning_line = start_line + body_lines, but cmd.heredoc only contains the \x1f sentinel (body was consumed by comsub), so body_lines = 0 and warning_line = start_line = 26.

Fix direction

When a heredoc spans a command-substitution boundary, the warning line should be the comsub closing line, not the <<EOF line. This requires the executor to track the comsub close line and pass it to report_unterminated_heredoc, or to store the actual body line count in cmd.heredoc even when the body was consumed by comsub.

heredoc3.sub — syntax error message

GNU:

./heredoc3.sub: line 99: syntax error: unexpected end of file from `(' command on line 96

rubash:

./heredoc3.sub: line 92: syntax error near unexpected end of file

Root cause

The final (cat <<EOF\nstill more text\nEOF) (lines 96-98) is an unterminated subshell heredoc. rubash has report_unterminated_subshell_heredoc (src/executor/public_accessors.rs:630) that produces the correct GNU-format message, but this case falls through to the generic parse_loop.rs error path instead.

Fix direction

The parser needs to recognize (cat <<EOF ... EOF) as an unterminated subshell heredoc and route to report_unterminated_subshell_heredoc instead of the generic EOF error.

heredoc3.sub — 5 warnings (GNU over-reporting, NOT a rubash bug)

GNU emits 5 here-document at line N delimited by end-of-file warnings for $(cat <<EOF\n...\nEOF) patterns where EOF) is on the same line. These are GNU over-warnings — rubash correctly handles EOF) on the same line without warning. Matching GNU here would mean intentionally emitting false positives, which is wrong. These 5 warnings should NOT be "fixed".

Verification

# GNU
MSYS_NO_PATHCONV=1 wsl bash /mnt/d/repo/rubash-audit/scripts/true-baseline-audit.sh heredoc

# Both produce identical stdout; only stderr differs

Generated with Devin

Activity

  1. added
    bug
    deferred
    gnu-baseline
    on Sep 12, 2026
  2. caomengxuan666 commented on Sep 17, 2026

    @caomengxuan666
    MemberAuthor

    Fixed in 7476764.

    heredoc7.sub — GNU semantics: make_here_document receives the parser's line_number at gather_here_documents time (parse.y:3130), i.e. the physical line where the logical command ended — when the body was swallowed by $(, that's the ) line (29), not the << line (26). HereDocBody tokens now carry this gather line (HereDocRedirect::gather_line → CommandNode::heredoc_gather_line), and all three warning reporters use it. Output now byte-identical: line 29: warning: here-document at line 29 delimited by end-of-file (wanted \EOF')`.

    heredoc3.sub — the unclosed ( now takes the GNU yyerror EOF path (parse.y:6890-6901, compoundcmd_lineno stack): pending-heredoc warnings are recovered by pairing << delimiters with their body tokens in the failed region, then line 99: syntax error: unexpected end of file from \(' command on line 96`. Both lines now byte-identical to GNU.

    Verified: 21/21 stderr + 25/25 stdout probes vs WSL GNU 5.3.0; head-vs-mine zero regressions on heredoc/alias/redir/comsub/func/varenv/errors/parser.

    Not covered (separate issues): -c executes earlier commands before the parse error (GNU parses the whole -c string atomically — architectural difference); /usr/bin/grep-style argv0 prefixes; x* filename errors are WinuxCmd Windows-filename limits.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugdeferredgnu-baseline

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions