Skip to content

Syntax-error message quotes the wrong source line: line NUMBER is correct but the printed offending line is the PREVIOUS line's text #204

Closed

Description

@caomengxuan666

Corpus: target-tools P1. Probe target-tools/scripts/probe4.sh, artifacts target-tools/results/P4/{gnu,rub}.out.

File probe4.sh:

echo t1
echo )
...

GNU 5.3.0: probe4.sh: line 2: syntax error near unexpected token ) + probe4.sh: line 2: echo )'rubash: same first line, but the offending-line echo printsprobe4.sh: line 2: echo t1' — the text of line 1.

GNU owner: third_party/bash/parse.y:6859-6861 parser_error() prints the message, and the offending source line is taken from the current parse buffer at the error point; rubash's equivalent appears to read the line buffer before the token that forced the error is appended.

Related to #201 (error-line attribution for multi-line comsub strings / function-body runtime errors) — same diagnostics family, distinct symptom: here the number is right and the TEXT is wrong. Discovered via the zoxide/starship corpus; also visible for the top-level echo ) case (both sides abort rc=2 after the message).

Activity

  1. added
    bug
    on Sep 27, 2026
  2. caomengxuan666 commented on Sep 27, 2026

    @caomengxuan666
    MemberAuthor

    已修复并合入 master(commit ea792b2c,lane wt/diag)。根因:诊断取行文本时把词法行号当字节偏移用(source_line_at_byte_offset);现按行号取(GNU parse.y:6813-6824 print_offending_line 语义)。探针覆盖 mid-file done、eval 重解析、-c、深层行号四种形态,与 WSL GNU Bash 5.3.0 字节一致。感谢报告!

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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions