Skip to content

arith: nameref bind failure enters the evaluation-order event log - #3288

Merged
caomengxuan666 merged 3 commits into
masterfrom
fix-3246-arith-nameref-eval-order
Nov 10, 2026
Merged

caomengxuan666 merged 3 commits into
masterfrom
fix-3246-arith-nameref-eval-order

Conversation

@caomengxuan666

@caomengxuan666 caomengxuan666 commented Nov 10, 2026 •

Copy link
Copy Markdown
Member

摘要

空 cell nameref 在算术里被赋非名字形值时,GNU 在绑定点即时发 `1': not a valid identifier(variables.c:3076-3079 的 sh_invalidid,expr.c:331-354 的 expr_bind_variable 在 NULL 绑定上不 longjmp,求值继续、赋值取 RHS 值)。本 PR 让该报错进入求值序事件日志(沿 rubash #3244 的 ArithEvalEvent 单日志机制),取代边界后补发的单槽 marker 报告器。

修法后五形行为与 GNU 一致:

  • (( ref=1, LC_ALL=5 )):diag → 警告,rc=0(原序反、rc=1);
  • (( LC_ALL=5, ref=1 )):警告 → diag,rc=0(原序偶合、rc=1);
  • x=$(( ref=1, LC_ALL=5 )):diag → 警告,x=5(原 diag 整条缺失);
  • x=$(( ref=1 )) 后接 (( 1 )):diag 当场发,不再泄漏到下一条命令(原当场缺失、下一条命令补发陈旧 diag 并 rc=1);
  • let "ref=1" "LC_ALL=5":diag → 警告,两操作数都求值,rc=0(原仅 diag、第二操作数未求值、rc=1)。

另两点:

  • 下标求值(${a[ref=1]}、[[ ${a[ref=1]} = y ]])经 &self deferred 路径只评一次且无入口 drain,事件在 apply_pending_subscript_writes 落点以无标签排出(GNU arrayfunc.c:1374-1378,this_command_name 为 NULL);两次求值各打印一行,无去重。
  • drain 的 Diag 臂与下标落点均走 fd-2 绑定通道(arith_diag),(( ref=1 )) 2>file 与 (( a[]=1 )) 2>file 的诊断入文件、外层 stderr 为空(GNU error.c 写 fd 2 as bound;Readonly 臂同路由由 rubash Stage-2 ④ Phase 4: variable-attribute family onto Diag (Refs #2707) #2968 的合入带入)。

本 PR 删除了什么

  • report_arithmetic_nameref_error 函数整体(src/executor/arithmetic_aliases.rs),及 (( 与 let 两处调用点(两处强制 status 1 的逻辑随之移除,状态改由表达式值决定);
  • __RUBASH_ARITH_NAMEREF_ERROR 单槽 marker:src/executor/arithmetic/value.rs 生产点的插入、src/executor/markers.rs 的注册行;src/executor/arithmetic/mod.rs 里 eval_arithmetic_expansion_value 对该报告器的调用(drain 已覆盖)。

验证(头树 f5b903ee,基底 d9555905)

  • 新钉 tests/issue3246_arith_nameref_eval_order.rs:头树 18/18,基底 fail-first 2 过 16 红(仅 valid-cell 控制与 fatal-expansion 守卫在基底上过);
  • 邻茎 issue3078_arith_diag_warning_order:19/19;
  • lib 双边失败名集:头树 1233/0/4(名集 ∅),基底 1232/1/4(唯一红为已知环境 flake issue2875_input_procsub_child_runs_as_rubash_shell,头树同跑过);无头树引入失败;
  • RUSTFLAGS="-D warnings" 检查 lib+bins rc=0;cargo fmt --check 全树 rc=0;scripts/check-marker-literals.py rc=0;scripts/check-utf8-boundary-hygiene.sh rc=0;cargo check --tests rc=0(32 条警告全在既存他茎测试文件,本 PR 文件零警告);
  • GNU oracle 对照探针(probes/,头二进制 vs GNU 5.3.20):7 份中 6 份 stdout/stderr/rc 全同;仅 gnu-extra.sh stderr 差 2 行,见下。

已知残差(不属本 PR 范围,另立单跟踪)

  • 子串偏移 ${v:ref=1:2}:GNU 打印 v: \1': ...(参数名标签,subst.c 侧另一报告路径),头树打印无标签行。行为(值 bc`、rc=0)一致,仅标签差一格;钉文件未收该形。
  • 致命快赋值后的标志泄漏:x=$(( ref=1, 1/0 )) 之后,其后 (( )) 命令的求值被陈旧的 arithmetic_fatal_error 标志跳过、evalerror 报告被陈旧的 arithmetic_expansion_error 闩挡住(基底同病,基底曾靠陈旧 marker 泄漏偶然遮住一行)。已另立 rubash 致命快赋值后算术致命/展开错误标志跨命令泄漏:后续 (( )) 求值被跳过、诊断全静默 #3287,附金丝雀证据与修法面分析;本 PR 不动标志生命周期。

Refs #3246

Empty-cell nameref adoption of an invalid value (GNU variables.c:3076-3079,
sh_invalidid at the bind point; expr.c:331-354, no longjmp on the NULL bind)
now records ArithEvalDiag::InvalidIdentifier in the ArithEvalEvent log
instead of a single-slot env marker consumed after the boundary. The
diagnostic drains in evaluation order with the locale warnings, the status
is the expression value, later let operands still evaluate, and the
fast-assignment route no longer leaks a stale diagnostic into the next
command. The drain's Diag arm and the deferred subscript-write apply point
emit through the fd-2-bound channel (GNU error.c writes diagnostics to fd 2
as currently bound).
@caomengxuan666
caomengxuan666 marked this pull request as ready for review November 10, 2026 21:10
@caomengxuan666
caomengxuan666 merged commit 3a93856 into master Nov 10, 2026
11 checks passed
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.

1 participant