Skip to content

fix(executor): exempt funsub bodies from bad-substitution scan - #3869

Merged
caomengxuan666 merged 1 commit into
masterfrom
fix-3502-funsub-badsub-scan
Nov 17, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
fix-3502-funsub-badsub-scan

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Summary

  • fix(executor): ${v:?${-x}} reports only the nested bad substitution #3855 added a whole-inner braced_name_is_bad_substitution gate to the parameter-error pre-scan (parameter_expansion_error_in_word_context). It fires on ${ cmd; } funsub bodies (case x in x) esac;, echo 4;), which GNU never routes through parameter_brace_expand: param_expand's case LBRACE (subst.c:10775-10798) sends ${+FUNSUB_CHAR (parser.h:85) to function_substitute (subst.c:6917) first, so valid_brace_expansion_word (subst.c:10053 -> 7583) never sees them.
  • The scan now detects funsub spans with the same three-step admission the real expansion path uses (funsub_introducer + extract_funsub_body + funsub_body_is_terminated, mirroring expand_word.rs / embedded_parameters.rs) and skips the parameter battery for them, advancing past the funsub's own extent. Introducer-led spans that fail admission still fall through to the parameter checks.
  • New pin file tests/issue3502_funsub_bad_substitution_scan.rs (9 tests) covering the i1-audit reproducer, assignment RHS, operator-word nesting (:-/:?), embedded/double-quoted/}-word-text/tab/newline-introducer forms, plus bad-substitution guards.

Refs #3502

Test plan

  • cargo test --test issue3502_funsub_bad_substitution_scan — 9/9 (fail-first on master: 8/9 red)
  • cargo test --test issue3502_question_error_bad_substitution_word — 7/7 (fix(executor): ${v:?${-x}} reports only the nested bad substitution #3855 pins stay green)
  • cargo test --test cli_tests arithmetic_for — 5/5 (2 audit regressions green)
  • cargo test --test regression golden_funsub_valsub — 1/1
  • lib 双边 head vs base: identical failure set {issue2084_session_end_restores_host_process_state} (environmental)
  • RUSTFLAGS="-D warnings" cargo check clean; rustfmt clean; marker-lint + utf8-hygiene clean
  • GNU 对照 WSL bash 5.3.20 script-file probes (scratch-j1/funsub-badsub-cmp.sh): all funsub shapes byte-identical except pre-existing ${ } empty-body gap (unrelated to this change)

Generated with Devin

…3502)

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@caomengxuan666
caomengxuan666 merged commit 5f6fb63 into master Nov 17, 2026
9 of 12 checks passed
@caomengxuan666

Copy link
Copy Markdown
Member Author

【j1 续作报告】#3855 funsub 回归修复 — 已合入(mergeCommit 5f6fb63)

机制:parameter_expansion_error_in_word_context 的 ${...} span 循环在 matching_parameter_brace 之前接入 funsub 判定——与真实展开路径同一组三步准入(funsub_introducer + extract_funsub_body + funsub_body_is_terminated,对齐 expand_word.rs / embedded_parameters.rs),命中即按 funsub 自身 extent 推进 rest、跳过全部参数检查。GNU 依据:param_expand case LBRACE(subst.c:10775-10798)在 parameter_brace_expand 之前把 ${+FUNSUB_CHAR(parser.h:85)路由到 function_substitute(subst.c:6917),valid_brace_expansion_word(subst.c:10053→7583)永不判定其 body。判别是结构性的(FUNSUB_CHAR+可提取+已终止),非文本前缀扫描。

验证腿:

  • 新钉 issue3502_funsub_bad_substitution_scan 9/9 绿;fail-first(master 41279ae)8/9 红,仅 bad-substitution 守卫测试绿——钉有效。
  • fix(executor): ${v:?${-x}} reports only the nested bad substitution #3855 三处回归转绿:cli_tests arithmetic_for 5/5(含 malformed_parameter_expansion_in_arithmetic_for_is_a_syntax_error、stdin_script_stops_after_arithmetic_for_syntax_error_without_errexit)、regression golden_funsub_valsub 1/1。
  • fix(executor): ${v:?${-x}} reports only the nested bad substitution #3855 原钉 issue3502_question_error_bad_substitution_word 7/7 仍绿。
  • lib 双边:head 1376/1/4 vs base(41279ae) 1376/1/4,失败名集同为 {api::consumer_tests::issue2084_session_end_restores_host_process_state}(环境性),差集 ∅。
  • -D warnings cargo check(lib+bins)0 警告;rustfmt clean;check-marker-literals.py OK;check-utf8-boundary-hygiene.sh clean。
  • CI(head b447df7,run 44130423076):Compatibility CLI tests / Rust tests / Shell functionality / Windows compile / niubash builds / API ledger / cross-target linux/android / Rust tests macOS 全 pass。红任务 2 个均为基线/环境:GNU regression goldens(issue_753::case_9_declare_indexed_operand_binds_nothing + upstream_suite_slice_snapshots,与 master 同红;golden_funsub_valsub 本 PR 转 ok);Regression pin stem census(10974 中 101 红,失败名集与 master run 44124943315 逐名 diff:本 PR 反而净消除 13 个 funsub 相关红——issue2761/2763/3092/3823 四个 stem 全系 fix(executor): ${v:?${-x}} reports only the nested bad substitution #3855 同一回归面;新增 3 红 issue2029×2 + issue371×1 本地复跑 10/10、9/9 全绿=环境抖动)。
  • GNU 对照:WSL /usr/local/bin/bash 5.3.20(1),脚本文件 scratch-j1/funsub-badsub-cmp.sh(22 形状:arith-for 头、assign RHS、:-/:? 嵌套、mid-word、双引号、}词文本、tab/换行 introducer、valsub、注释/重定向体、空体、bad-substitution 守卫)。stdout 21/22 一致;stderr(去程序名前缀)除 ${ } 空体一例外逐行一致——${ } 空 funsub body 在 GNU 属合法空命令列(rc=0),rubash 真实路径 funsub_body_is_terminated("")=false 走参数诊断,系 fix(executor): ${v:?${-x}} reports only the nested bad substitution #3855 之前就存在的独立空隙,本 PR 未触碰、未扩大。

相邻残差(未动,供队长知悉):${ } 空体 funsub 与 GNU 的分歧为既有问题;census 环境抖动红(unix_faces/sleep/fd-fold 类)与本 PR 无关。

caomengxuan666 added a commit that referenced this pull request Nov 17, 2026
… the scan can own (Refs #3864)

The #3855 pre-scan gate judges every ${...} inner as a braced name
and reports the scan's whole word with status 1, but GNU's bad
substitution default (subst.c:10276-10288) reports the WORD BEING
EXPANDED with the error class of the context. The scan may only emit
that verdict when it coincides with the real expansion's, so the gate
now defers to the real expansion when (a) the word is a compound
assignment value — GNU expands elements individually
(arrayfunc.c:557) and names the element word, which the scan's
whole-word display cannot name (issue3500); (b) the name head is a
$'...' literal the real expansion decodes — subst.c:7583 judges the
extracted NAME (issue2650); (c) the verdict is POSIX-fatal —
subst.c:10285-10286 FORCE_EOF when POSIX + non-interactive + compat
> 43, which status 1 cannot express (audit B4-F08). All seven #3502
pins and the #3869 funsub pins are preserved by construction: no
deferral fires on their words.

UNVERIFIED-BY-CAPTAIN: no build/test executed in this lane (build
chain down); head census re-run parked for the captain.
caomengxuan666 added a commit that referenced this pull request Nov 18, 2026
… the scan can own (Refs #3864)

## Summary

Refs #3864. PR #3855 added a `braced_name_is_bad_substitution(inner)` check to the `parameter_expansion_error_in_word_context` pre-scan so a bad substitution inside a ` :?` message word surfaces as the inner error (rubash#3502: `${v:?${-x}}` prints only `${-x}: bad substitution`). The check judges the whole `${...}` inner as a braced name and reports the scan's whole word with status 1 — but the scan may only emit that verdict when it coincides with what the real expansion would report. Where it does not, the scan pre-empts the correct diagnostic:

- Compound assignment values (issue3500, whole stem): GNU expands elements individually (`arrayfunc.c:557 expand_compound_array_assignment`) and the diagnostic names the element word (`\\[0\\]=${-x}`); the scan names the raw parenthesised value.
- `$'name'` extquote names (issue2650): `subst.c:7583 valid_brace_expansion_word` judges the extracted NAME; the real expansion decodes `$'x1'` to `x1` in a quoted context, where the gate on the raw literal misjudges it.
- POSIX fatal class (audit B4-F08): `subst.c:10285-10288` makes a bad substitution FORCE_EOF when POSIX + non-interactive + compat > 43; the scan's status 1 downgrades it to DISCARD.

The funsub faces (issue2763/issue2761/issue3092/issue3823, golden_funsub_valsub, the arithmetic-for CLI case) are already fixed by #3869, which exempts funsub bodies at the top of this same scan loop; this PR does not touch that exemption.

## Repair

The gate now fires only when the scan's verdict coincides with the real expansion's: it defers (returns nothing, letting the real expansion report) when any of these holds —

1. the scanned word is (or contains) a compound assignment value (parser compound marker, or a leading `(`): GNU's diagnostic is per-element, which the scan's whole-word display cannot name;
2. the span's name head is a `$'...'` literal that `resolve_dollar_quoted_parameter_name` decodes: the gate must judge the decoded name;
3. the POSIX-fatal predicate holds (POSIX mode, non-interactive, `compatibility_level > 43`, mirroring the fatal arm in `command_execute.rs`): the scan's status 1 cannot express FORCE_EOF.

Everything else is unchanged: the gate still fires for bare bad names (`${-x}`, `${}`, `${(M)y}`), still pre-empts a later `:?` error left-to-right, and still fires inside `:?`/`:-` operator-word recursions — so all seven #3502 pins and the #3869 funsub pins keep passing by construction.

## What this PR removes

Nothing from the product surface: the #3855 gate check stays; only its three over-broad firing slices are deferred to the real expansion. No new diagnostic text, no new error class.

## Validation

**UNVERIFIED-BY-CAPTAIN** — no build or test was executed in this lane: the build chain is down (X299 tunnel refused, Simular box wallet empty, local build banned: MemAvailable ~503M, below the 1.5G gate). `cargo test` / `cargo check` / lib+base alignment / `RUSTFLAGS="-D warnings"` check are all parked; the captain re-runs the head census after the chain recovers.

- New nails `tests/issue3864_parameter_errors_regression.rs` (11 tests): issue3500 element words (indexed/assoc/nested/valid guard), issue2650 extquote top-level + bare forms, POSIX fatal + compat43 guard, funsub-valsub shapes, #3502 inner-only + pin-7 ordering guards. Written fail-first, before the repair; fail-first is by code analysis, not execution (see above).
- GNU oracle probes (local `/bin/bash` 5.2.21; stems already carry 5.3.20 verification): `"[${$'x1'}]"` -> `[hello]`; `a=([0]=${-x})` -> `\\[0\\]=${-x}: bad substitution` rc 1; POSIX `echo ${}` -> fatal, no ALIVE, rc 1; `${v:?${-x}}` -> only `${-x}: bad substitution` rc 1.
- `rustfmt --check` clean on both touched files.
- Evaluation note: reverting #3855 outright was considered and rejected — it would reopen #3502 (7 pins). The scoped repair keeps #3502 green while clearing the mechanically attributable clusters. Three singles in #3864 (issue2029, issue2771, issue2761 x2) have no `${` span in their scripts that can trip the gate, so no `parameter_errors.rs` change can clear them; they are recorded in the lane REPORT as unattributed (likely census flakes / other-window commits) for the captain's census re-run to confirm.

## Captain review (PASS, merged)

Original head 19159b6, captain-extracted from its CI logs:
census total 79 (era baseline), issue3500 19/19, own pins
issue3864 11/11, goldens exactly the two baseline names; the
darwin leg was cancelled with zero steps (never ran, not a red).

Merge-shape head 0a73b4f (update-branch over master 0863639;
the only master-side touch of parameter_errors.rs since the
merge-base was PR #3871's +6/-2 arith-label hunk near line 1417,
~1000 lines from this PR's hunks), captain-extracted:
- issue3500 19/19 PASS, issue3864 11/11 PASS, issue2650 10/10,
  issue2763 6/6, issue201 2/2, issue2771 5/5, audit stems 40/40.
- Census total 81, goldens exactly the two baseline names.
- Two non-blocking cells, both adjudicated churn: the CLI leg's
  sole failure is c_command_keeps_named_coproc_output_fds_distinct
  (2 PASS / 2 FAIL across four era heads, uncorrelated with any
  diff), and census cell issue2029
  head_pipe_fold_leaves_the_remainder is FAIL here but PASS on
  both the original head and on PR #3870's head (which carries
  #3855 without this fix) — not owned by this change.

Fail-first basis (stated honestly): the lane's 11 pins were
written pre-fix but not executed pre-fix (no build route); their
fail-first rests on code analysis, corroborated by the tip census
showing the same shapes red before this PR and green after.

What this removes: the unscoped #3855 gate call in
parameter_expansion_error_in_word_context — the scan emitted
whole-word status-1 verdicts for compound values, $'...' name
heads and the POSIX-fatal class. It is replaced by the
deferral-aware gate; each deferral restores the pre-#3855
behavior for that slice. No other behavior is deleted.
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