Repository navigation
fix(arith): trap set -u at GNU's read points, not a text pre-scan (Refs #3496 #3497 #3498) - #3561
Conversation
#3496 #3497 #3498) GNU raises the arithmetic nounset error only when evalexp READS a variable (expr.c:1150-1216 expr_streval), after the text has been expanded (subst.c:3981 expand_arith_string), and at the position the word walk reaches the `$((...))` (subst.c:11229 expand_word_internal). Three rubash text scans judged it instead: - the (( ))/$(( ))/let/write-path entries ran arithmetic_unbound_variable over the expanded text, so `let '$undef'` reported `undef` (GNU: operand expected on `$undef`) and `0 && i` / `0 ? i : 2` trapped under noeval. The scan is removed; the evaluator's own read-point trap now covers every read: a subscript frame's UnboundVariable propagates out of eval_subscript_index (FORCE_EOF, not a subscript evalerror), and the variable cell is looked up first (expr.c:1183-1190: absent or att_invisible `declare -a e` traps the array name; `h=()` does not). - (( ))/$(( )) subscripts are expanded unquoted (subst.c:11107/11147 expand_array_subscript) when the text holds an expansion character: `b['$undef']` hands evalexp the literal `$undef`; `let` keeps the double-quoted array_expand_index pass (arrayfunc.c:1370). - the word pre-scan now judges each `$((...))` in place: its expansion `$` reads, then a scratch evaluation's bare-name trap, before later words (`echo $(( i++ )) + b[$undef]` reports `i`). Pin: tests/issue3496_arith_nounset_read_points.rs (8 tests; base 2/8, head 8/8). Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Same content as af0a6d2 on another lane: origin/master carries this stem unformatted, so `cargo fmt --check` (the pre-commit gate) fails on any branch cut from it. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
【WIN-AGENT-AUDIT】s10 lane — 建议:PENDING(CONFLICTING,跳过不合) head: 6229dec base(merge-base): 8b48c16 文件: 5 个 +549/-27 处置:不合并。 背景提示(供续作参考):
腿:本轮全部未跑(按 CONFLICTING 跳过规则),不记为通过。 未跑/VOID 的腿:
|
|
【WIN-AGENT-AUDIT】 机制核查:
腿(逐项数字):
F 点:无(代码与钉本体合格)。 阻塞(判 PENDING 的理由):
未跑/VOID 的腿:无。 |
…arith-nounset-read-points
|
【WIN-AGENT-AUDIT】f1 续作(第3轮)— 建议:PASS(冲突已解,merge head 全腿绿;合入与关单口径留队长) head: 机制核查:
腿(逐项数字):
F 点:无。 续作记录:
未跑/VOID 的腿:无。 |
Refs #3563 Arithmetic `set -u` residuals from the #3561 review — seven shapes, one family rule: GNU traps nounset only where evalexp actually reads (expr.c:1190-1216 `expr_streval`), with the context each read site owns. - Row 1 (`[[ 0 -eq '0 && u' ]]`, `$(( 0 && u ))` words): the text scan `arithmetic_unbound_variable` trapped names evalexp never reads (noeval short-circuit, assignment targets). Deleted with its last callers; `[[ ]]` arithcomp and whole-word `$(( ))` now take the evaluator's own category + recorded name. - Rows 2-3 (`echo $(( k=1 )) $k`, `$(( h[k]=4 )) ${h[k]}`): the word pre-scan's `$(( ))` verdict discarded the scratch evaluation's writes. `arith_body_nounset_verdict` now returns them and the scan records them (per changed array element) in its simulated bindings, mirroring GNU's left-to-right walk (subst.c:11229). Round 2 fixed the remaining gap: the verdict env excluded SCAN_SIM_BINDINGS, so an arithmetic unit's scratch eval could not see an earlier bind in the same command (`scan_evolved_env_vars`, applied at both verdict call points). - Row 4 (`(( b[${undef:-'$q'}] ))`): a subscript's `${...}` word inherits the subscript's unquoted context (subst.c:11147), so `'$q'` is literal data. The subscript masker recurses into braced bodies inside subscripts, and the subscript nounset scan masks the same spans; the top-level arithmetic context (where the quote is data and `$q` does read) is unchanged. - Row 5 (`declare -n r=zz; $(( r[0] ))`): array lvalues now carry the written name alongside the resolved one; the nounset verdict reads the resolved cell but records the written name (expr.c:1194 `array_variable_name`). - Row 6 (`declare -i di; di=undef+1`): the integer-assignment evaluation keeps the evaluator's category; an unbound read reports `undef: unbound variable` and takes the nounset FORCE_EOF rails instead of a synthesized operand-expected text (variables.c:2905 `make_variable_value`). - Row 7 (`a[undef]=1` abort class): verified already conformant on current master; pinned as a guard. Regression pins: `tests/issue3563_arith_nounset_residuals.rs` (fail-first on 622ee66: rows 1-6 red, row 7 green). ## 本 PR 删除了什么 - Deleted the `arithmetic_unbound_variable` text scan and its last callers (row 1: it trapped names evalexp never reads). No public API, no builtin, no user-visible behaviour other than the fixed nounset mis-traps was removed. ## Captain adjudication (head 5945fc5, run 44461379248) - Regression pin stem census: 69 fail names, **zero new** vs the previous head's 71. The defect cell `arith_assignment_binds_for_later_words` (all three shapes: `k=1`, `set -u` arith-to-arith `j`, assoc `h[k]`) now PASSES; the whole stem is 11/11 PASS in CI. Guard cells `subscript_default_single_quoted_dollar_is_data` and `arith_compound_assignment_still_reads_first` PASS. `issue1902_stdin_bound_to_regular_file_follows_the_binding` remains red — documented-unstable fd-alias flake family, adjudicated, unreachable from this diff. The `issue2883` read-prompt cell flipped green (same flake family). - GNU regression goldens: exactly the baseline 2 (`issue_753::case_9_declare_indexed_operand_binds_nothing`, `upstream_suite_slice_snapshots`), 232 passed. - Compatibility CLI tests, Rust tests (Linux + macOS), Shell functionality tests, cross-target checks, Windows compile check, niubash-builds-against-tree, API ledger tripwire: all PASS. - The two red job lamps (census, goldens) are the adjudicated-by-name failures above, not unreviewed breakage. - Zero-intersection vs tip f37b90e proven programmatically: base 622ee66...tip = 6 commits / 15 files, none of them among this PR's 10 files — merged without update-branch. - History: round-1 rework commits c768b9f + f25cd5b were committed and pushed by the captain from the lane's written, fmt-clean fix (disclosed on the PR); head 5945fc5 is the captain's paren-hygiene commit removing two `-D warnings` findings (PR-introduced, base 0). ## Verification debt (owed post-merge) Fresh server legs for the final head (stem + lib failure-name sets both directions, `RUSTFLAGS="-D warnings"`, per-file rustfmt) were not run: the earlier server legs covered prior heads. Recorded as debt; the CI census by name above is the merge basis.
修了什么
set -u下算术的 unbound 判定改由 GNU 的读点与展开相序决定,不再由文本预扫描决定。三处文本扫描各自误判:(( ))/$(( ))/let/ 下标写路径在求值前对展开后文本跑arithmetic_unbound_variable,于是let '$undef'报undef: unbound variable(GNU:let: $undef: arithmetic syntax error: operand expected),0 && i、0 ? i : 2、for ((;0 && n;))在 noeval 下误陷。删去这三处扫描,改由求值器自己的读点陷阱(rubash#3200 已有的variable_value读点)覆盖全部读:eval_subscript_index)里的 UnboundVariable 原样传出(GNU 为 FORCE_EOF 跳出,不是下标 evalerror),(( b[i]++ ))仍报i;array_variable_part先于下标求值):不存在或 att_invisible(declare -a e=DECLARED_UNSET_VARS+ 空镜像)报数组名;h=()已赋空数组可见、读 0。(( ))/$(( ))文本含展开字符时,下标经expand_array_subscript在不带引号的上下文展开(单引号去引号、体为字面),b['$undef']交给 evalexp 的是字面$undef→ operand expected;let/[[仍走array_expand_index的双引号上下文('是数据,$undef照展开);无展开字符时走 quote-removal 分支保留'(b['1']报'1')。新增expand_arith_command_subscripts(命令入口)与unquoted_subscript_single_quotes_as_data。$((...))时就地裁决:先按展开相扫其$读(下标按不带引号上下文),再在变量副本上用真求值器判裸名陷阱(保存/恢复全部算术 thread-local,只出判决),然后才走向后续词。echo $(( i++ )) + b[$undef]报i。删了什么
arithmetic_unbound_variable(&expression, ..)文本扫描调用(src/executor/arithmetic/mod.rs命令入口 / 下标写路径 /$(( ))求值入口)。函数本身保留([[ ]]操作数与 expand_word 整词$((仍在用,见 Owed)。GNU 依据
expr_streval(noeval 短路 :1164-1167;数组格查找 :1183;v == 0 || invisible_p (v):1190);expr.c:1393-1401 readtok 对=目标不读expand_array_subscript,subst.c:11147expand_subscript_string (exp, quoted & ~(Q_ARITH|Q_DOUBLE_QUOTES))array_expand_index→expand_arith_string (exp, Q_DOUBLE_QUOTES|Q_ARITH|Q_ARRAYSUB)ARITH_EXP_CHAR,subst.c:3981-4033expand_arith_string(展开分支 vs quote-removal 分支)expand_word_internal(逐词左到右、$((就地展开求值)验证
tests/issue3496_arith_nounset_read_points.rs(8 测,全部期望为 GNU 5.3.20bash -c实测逐字):base 2/8 → head 8/8(fail-first:base 上 6 红)。target/probe/{m,n},共 52 格):SAME 格 base 31 → head 45(m 17→27,n 14→18),base SAME 的格在 head 全部仍 SAME(无新增 DIFF);改进格含 noeval ×5、let×2、nn[0]=3、declare -a e×2、h=()、local -a l、b['$undef']、$(( i++ )) + b[$undef]。另target/probe/s下标引号矩阵 19 格 head 18 SAME(剩${undef:-'$q'},见 算术 nounset 同族残差:[[ ]] 操作数文本扫描、预扫描不见 $((k=1)) 绑定、nameref/declare -i/元素赋值诊断 #3563)。arith_cache_fallback 7/7、issue1130 4/4、issue1149_1150 2/2、issue1709 4/4、issue200 2/2、issue2486 5/5、issue3024 23/23、issue3199 6/6、issue319 5/5、issue3200 11/11、issue3429 14/14、issue638 20/20;issue0067… 4/5、issue639 2/11、issue705_nounset 3/4、oils_spec_arith 57/68—— 红格与 base 同名同数,失败全是本车道路径导致的$0/路径前缀不等(/d/repo/rubash-lanes/L03/target/debug/rubash.exe:vs 期望bash:),归一化前缀后左右逐字相等。$0路径差(Windows 车道环境),另 issue1932/1933 为/dev/fd进程替换环境差;未见语义差。cargo test --lib executor461/461;cargo fmt --check(WSL,pre-commit 钩子实跑)绿。Owed
[[ 0 -eq '0 && u' ]]的操作数文本扫描(conditional.rsconditional_nounset_arith_trap)与 expand_word.rs 整词$((扫描仍是文本扫描;词级预扫描不模拟$((k=1))的绑定(echo $(( k=1 )) $k);${undef:-'$q'}下标内嵌套词的引号上下文;nameref 数组读报目标名(zz)而非r;declare -i di; di=undef+1。$读预扫描)同文件相邻改动:本 PR 改了first_unbound_dollar_read的调用上下文(下标先按不带引号上下文转写),合并顺序需要队长裁定,可能需 rebase。Fixes #3496
Fixes #3497
Fixes #3498