Skip to content

[bug] Error-line attribution: multi-line comsub string and function-body runtime errors report different lines than GNU (5 vs 4; { line vs select line) #201

Closed

Description

@caomengxuan666

Found by the suite2 ledger run (comsub2.tests:71-78 and errors.tests:56-62), WSL GNU Bash 5.3.0 baseline. Same family as #136 (error-line attribution) but a different shape: not consecutive same-line errors — here the attribution differs for runtime errors inside (a) a multi-line command-substitution string and (b) a function body.

Repro A (LF script, exact comsub2.tests extract)

alias p=printf
alias e='echo aliasval'
echo "${ typeset x;
	for f in 1 2; do p '%s\n' $f ; shopt expand_aliases; done
	unalias p
	alias e='echo inside redefine'
 	x=42 ; return; echo gone; }"
echo done

GNU stderr (twice):

probe.sh: line 5: p: command not found

rubash stderr (twice):

probe.sh: line 4: p: command not found

The failing p word is on physical line 4; GNU attributes the error to line 5, rubash to line 4.

Repro B (errors.tests extract)

bad-select()
{
	select $1 in a b c ; do echo $REPLY ; done
}
bad-select 'a b'

GNU stderr:

probe.sh: line 2: `$1': not a valid identifier

rubash stderr:

probe.sh: line 3: `$1': not a valid identifier

GNU attributes the runtime select-variable error to the function body's opening { line (line 2; in errors.tests that is line 59 with the select on line 60 — GNU prints 59, rubash prints 60). rubash reports the select keyword's own line in both repros, and in the full errors.tests run it reported the call-site line. All three placements differ from GNU.

GNU anchor

  • execute_cmd.c:407 uw_restore_lineno / the save_line_number-restore pairs in execute_command_internal (execute_cmd.c:694,742) — how line_number is saved/restored across function and comsub execution
  • error.c:461 internal_error("`%s': not a valid identifier") — the select diagnostic itself
  • subst.c:6925 function_substitute / subst.c:7143 command_substitute — parse_and_execute inside a comsub string (Repro A)

Artifacts

Activity

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

    @caomengxuan666
    MemberAuthor

    部分修复已合入 master(commit ea792b2c):函数体/select 形态的行号归属已与 GNU 对齐——execute_select_command 先做 check_identifier 再盖 line_number(execute_cmd.c:3001-3010 先于 :3013,与 for 循环 :2996-2999 相反),函数体现在以 body 开行作为环境行号(execute_cmd.c:5351 tc->line);errors.tests 的 stderr 已从 line 60 修正到 GNU 的 line 59。剩余:多行 comsub 字符串的 +1/+2 行漂移需要移植 string reader 的 line_number 精确递增点(evalstring.c:340-346 line_number-- 与 reader 递增的配合)——属深水区,保留开放继续跟进。感谢报告!

  3. caomengxuan666 commented on Sep 27, 2026

    @caomengxuan666
    MemberAuthor

    已修复并合入 master(lane wt4/deep201,commit df3ecd4d,此前 select/函数体半区已由 commit ea792b2c 落地)。深水半区(多行 comsub 字符串)完整移植了 GNU 的行号生命周期:parse_comsub 在解析期用 print_comsub 的 canonical 序列化替换原文(parse.y:4451/4632 → print_cmd.c 布局:do/done/then/elif/case/funcdef/heredoc 各自的行推进规则 + inside_function_def 的分号换行规则),执行期 command_substitute → parse_and_execute 的 push_stream + line_number-- 补偿(evalstring.c:340-346),净公式 (S-1)+canonical_line。验证:1500/1500 矩阵(25 形状×5 位置×嵌套 1-3×错误/$LINENO×填充)与 WSL GNU 5.3.0 字节一致;issue 复现形 line 5 与 GNU 相同;true-baseline comsub2 套件 66→0 差异。残留(已记录未修):$BASH_COMMAND 携带原文而非 canonical 序列化、comsub 体内 xtrace PS4 $LINENO——另行跟进。感谢报告!

  4. added a commit that references this issue on Sep 27, 2026
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

    buggnu-baseline

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions