Skip to content

[bug] 函数体内 eval 遇 bad substitution 后放弃整个函数体,显式 return 不再执行(rc=1 vs GNU rc=5) #188

Closed

Description

@caomengxuan666

现象

f13() { eval 'x=${.sh.version}'; return 5; }
f13 2>/dev/null
echo "rc=$?"
  • GNU 5.3.0: rc=5(eval 的 bad substitution 非致命,函数体继续,return 5 执行)
  • rubash 49b7d8bf: rc=1(ExpansionFailure 放弃了函数体剩余部分,return 5 未执行)

stderr 双侧均干净(#167 修复后诊断走 fd-2 端点,被 2>/dev/null 吞掉)——纯控制流分歧。

定位方向

eval 的 bad substitution 在函数上下文返回 ExecuteError::ExpansionFailure,函数执行器把该错误上抛为整个函数调用的终止,而 GNU subst.c:10277-10288 的 expand_wdisc_error → exp_jump_to_top_level(DISCARD) 只放弃当前命令列表,函数体内后续命令(含显式 return)仍执行。顶层的同形(eval 'x=${.sh.version}' 2>/dev/null || w=fallback,#167 矩阵 m3)双侧一致,分歧仅在函数体内。

复现与产物

  • probe: target/issue-suites/results/n1-exec-2026-09-26/funceval-probe.sh(LF 双侧脚本文件)
  • rubash: funceval-rub.out(rc=1);GNU: funceval-gnu.out(rc=5)

版本: rubash 49b7d8bf (wt/n1-exec),对照 WSL GNU Bash 5.3.0(1)-release。

Activity

  1. caomengxuan666 commented on Sep 27, 2026

    @caomengxuan666
    MemberAuthor

    已在 51df49a 修复并关闭(commit 48089806,四单合一)。GNU 锚点与矩阵见 issue 评论区独立说明。

  2. added
    bug
    on Oct 17, 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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions