Skip to content

fix(executor): resolve ${!src<op>tail} indirection for positional and special sources - #3747

Merged
caomengxuan666 merged 5 commits into
masterfrom
devin/indirect-special-source
Nov 17, 2026
Merged

caomengxuan666 merged 5 commits into
masterfrom
devin/indirect-special-source

Conversation

@caomengxuan666

@caomengxuan666 caomengxuan666 commented Nov 15, 2026 •

Copy link
Copy Markdown
Member

Summary

run-errors / errors6.sub ivar -3 divergence: ${!src<op>tail} indirections whose source is a positional index or a VALID_INDIR_PARAM special (#, ?, @, *) were misclaimed — ${!#:-d} produced empty instead of b, ${!?-d} printed the default word instead of the script name, ${!0} read positional 1, and the diagnostic arms couldn't name a digit/special head's resolved t.

GNU anchors (subst.c): want_indir (:9920-9922) + VALID_INDIR_PARAM (:122); parameter_brace_expand_indir (:7883-7952) resolves every parameter kind through parameter_brace_find_indir (:7839-7881) — the $# count, $? status, joined positionals, $0 script name — then applies the operator to the parameter t names (:9978-10017).

  • is_valid_indirect_expression: #/?/@/* heads with an operator tail are legal indirections; the tail class is narrowed to what string_extract scans after a !+special head — #%:-=?+/@ (:9844-9860), so ^/, tails on special/digit heads stay bad substitution.
  • indirect_parameter_operator_value: unify special/positional sources through parameter_error_value ("0" -> script name, not $1).
  • has_indirect_parameter_word_operator: a leading #/?/@/* is the source, never a pattern-open.
  • expand_braced_operator_or_array_parameter ? arm: non-posix !+? is an indirect source, not $! under ?.
  • expand_braced_special # arm: ${!#} indirects through the $# value — zero positionals names $0; !+special heads carrying a #%/@/substring tail resynthesize ${t tail} and re-dispatch.
  • indirect_substring_parameter / indirect_replacement_parameter / indirect_parameter_transform: special/digit heads resolve t and re-dispatch ${t<op>} — ${!#:0:1} -> ${2:0:1} -> b, ${!?/a/Q} == ${0/a/Q}, ${!#@Q} -> 'b'.
  • indirect_holder_target_name: # -> positional count, ? -> status, @/* -> joined value, digits -> positional, 0 -> script name.
  • ${0<op>} routes to script_name_value in the replacement and transform digit arms (:9424-9428 name-first lookup).
  • An unset indirect target under @op renders NULL (:8927), not ''.
  • Operator-tail diagnostics resolve t for digit/special heads; bare ${!0} reports <script>: invalid variable name.

Verification

  • errors6.sub byte-identical to GNU bash 5.3.20 (stdout + stderr), including ivar -3 -> -3: invalid variable name and the x=-3/invalid-ident rows.
  • 29-case audit matrix (F1 ^/, errors + F2 / % : :offset @(…) tails + probes) byte-identical to GNU bash 5.3.20 stdout+stderr+rc on macOS arm64.
  • New pin: tests/issue3605_indirect_special_source.rs (18 tests), including script-file form for ${!0}. Regression slices green (issue1147/2608/2649/2712/529/439/1091_1092_1093/1910/1927/3022/3501/843/371/parameter_transform_tests); issue323/issue1566 failures reproduce on the base commit (pre-existing, unrelated).
  • run-errors residuals are independent roots noted on the issue: -c-mode $? init, posix fatal-builtin-error semantics in errors11.sub, ${#array} under set -u, and /bin/sh-bound sh: lines.

Refs #3605

本 PR 删除了什么

  • 无删除项(纯新增语义 + 钉):scan_question_is_error 的间接判定分支、!? 源在 operator 家族的重新切分,以及 tests/issue3605_indirect_special_source.rs 的 21 格钉;未删除任何既有代码路径或测试。

… special sources (Refs #3605)

${!1:-d}, ${!#:-d}, ${!?-d}, ${!@:-d}, ${!*:-d} and friends: GNU
parameter_brace_expand_indir (subst.c:7883-7952) resolves ANY parameter
kind through parameter_brace_find_indir — positional text, the $#
count, the $? status, joined positionals for @/*, the script name for
0 — then applies the operator word to the parameter t names. Only a
valid-identifier source with NO tail earns 'invalid indirect
expansion' (subst.c:7907-7918); an unresolvable tail-less source
proceeds silently; a resolved-but-invalid target reports
'<t>: invalid variable name' (subst.c:7947).

- is_valid_indirect_expression: admit #/?/@/* heads carrying an
  operator tail (want_indir VALID_INDIR_PARAM, subst.c:122/9920).
- indirect_parameter_operator_value: unify #/?/@/* and positional
  sources through parameter_error_value so '0' resolves to the script
  name instead of positional 1.
- has_indirect_parameter_word_operator: a leading #/?/@/* is the
  indirect SOURCE itself, never a pattern-open — ${!#:-d} is
  indirection through $# under :-, not $! minus a prefix.
- expand_braced_operator_or_array_parameter '?' arm: outside posix
  mode '!'+'?' is an indirect source, not $! under '?' — the
  following -/=/+/: split owns that form.
- is_parameter_error_name: admit '!'-led digit and special heads.
- expand_braced_special '#' arm: ${!#} indirects through the $#
  VALUE — with zero positionals t='0' names the script name.
- Operator-tail diagnostics resolve t via parameter_error_value for
  digit/special heads; a bare ${!0} reports the script-name target.

Verified byte-for-byte vs GNU bash 5.3.20 across script and -c modes
(errors6.sub now identical; 13-pin test
issue3605_indirect_special_source). Residuals noted on the issue:
-c-mode $? starts at 1 (separate init gap) and the posix-mode
fatal-builtin-error semantics in errors11.sub (different subsystem).

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@caomengxuan666

Copy link
Copy Markdown
Member Author

【WIN-AGENT-AUDIT】PR #3747 第1轮 — 建议:FAIL
head: 5b49fa1 base(merge-base): 0a405d8 文件: 5 个 +312/-23
关联 issue: #3605(状态:open,伞目录 issue,本轮不关单;我核过的时间:2026-11-16 本地)

机制核查:

  • 主干方向对:${!<src><op>tail} 的 src 可以是 VALID_INDIR_PARAM 特殊参数或位置参数(subst.c:122、subst.c:9920-9922 want_indir),经 parameter_brace_find_indir(subst.c:7839-7881)解析出 t 再让运算符作用在 t 命名的参数上。${!#:-d}→$2、${!?-d}→$0、${!@:-d}→a b: invalid variable name 这些已实现臂与 GNU 一致。
  • 但实现面只覆盖 :- - + = ? 一类运算符,而新谓词 is_valid_indirect_expression(src/executor/parameter_errors.rs:964-969)把 : - + = ? # % / ^ , @ 整段都当成合法尾,于是把一批「GNU 有确定语义、本 PR 没实现」的形状从「bad substitution 报错」变成「静默空串 rc=0」;其中 ^/, 连 GNU 都判 bad substitution。属半成品式修法(规程 4.2(c))。

F 点:

  • F1(回归:GNU 报错 → head 静默空串)${!#^} / ${!#,} / ${!#^2}:GNU 5.3.20 与 base(0a405d8) 均为 bad substitution rc=1,head 输出空串 rc=0。复现:printf '%s\n' 'echo "x${!#^}y"' > case.sh; bash case.sh → case.sh: line 1: x${!#^}y: bad substitution rc=1;target/debug/rubash.exe case.sh → xy rc=0。根因在 is_valid_indirect_expression 把 ^、,(参数 errors.rs:967)列为特殊头合法尾运算符——GNU 的 indir 路径不接受 casemod 尾,直接 bad substitution。
  • F2(半成品:只放行不实现)/、%、:、@(extglob`) 尾:GNU 解析出 t 后把运算符作用在 t 命名参数的值上,head 一律空串 rc=0。逐条(WSL /usr/local/bin/bash 5.3.20(1)-release 对照):
    • set a b; echo "x${!#/a/Q}y" → GNU xby rc=0 / head xy rc=0
    • set a b; echo "x${!#%2}y" → GNU xby / head xy
    • set a b; echo "x${!#:0:1}y" → GNU xby / head xy
    • set a b; echo "x${!#/@(2)/Q}y" → GNU xby / head xy
    • true; echo "x${!?/0/Q}y"、true; echo "x${!?%0}y" → GNU xcase.shy / head xy
    • a=hello b=world; set -- a b; echo ${!@/a/Q} → GNU case.sh: line 1: a b: invalid variable name rc=1 / head 空串 rc=0(连诊断都丢)
      上述形状 base 上是 bad substitution rc=1——即本 PR 把「明确的报错」换成「静默错值」,GNU 一致性没有前进。
  • F3(钉质量,非单独阻断)zero_reports_script_name_as_target 用 -c 形态断言 ${!0} 报 invalid variable name rc=1;这是 rubash 自身 $0=exe 路径的约定,不是 GNU -c 的行为:GNU bash -c 'echo ${!0}' 的 $0=bash(合法名)→ 空输出 rc=0。同一格改成脚本文件形态才与 GNU 同形(实测 GNU 脚本形态 case.sh: line 1: case.sh: invalid variable name rc=1,head 亦同,逐字节一致)。建议钉改用脚本形态,或在注释里写明「按 rubash $0 约定断言」。

腿(逐项给数字与名字):

  • 钉自跑 issue3605_indirect_special_source:13 passed / 0 failed。
  • fail-first:base(0a405d8 src) 上按 block 逐格比 GNU:m3747.sh 29 格里 base 红 19 格(含 c2/c4/c5 三条 argv0 噪声),PR 声称的修复面 ${!#:-d}/${!#-d}/${!#:-d}(3 参)/${!#}/${!?-d}(真/假)/${!@:-d}/${!*:-d}/${!1:-$1}/${!1-d}/${!#:+alt}/${!#+alt}/${!*:-d}(1 参) 均在红名单,判别性成立;m3747b.sh 15 格里 base 红 11 格、head 红 10 格。
  • lib 双边:head 失败名集 {api::consumer_tests::issue2084_session_end_restores_host_process_state} / base 失败名集 {同} / 差集 {}。
  • -D warnings:cargo check --locked --lib --bins clean,0 警告。
  • 卫生:rustfmt --check 5 文件 clean;marker-lint OK (117 registry consts, 268 allowlisted sites);utf8-hygiene clean。
  • CI:红 4 个——Rust tests / Rust tests (macOS) / GNU regression goldens and canaries 三者仅 issue2875_input_procsub_child_runs_as_rubash_shell(基线);niubash builds 为 Session::cwd API ledger 缺口(跨仓漂移基线)。均非本 PR 引入。
  • GNU 对照(WSL /usr/local/bin/bash 5.3.20(1)-release;探针 target/probe/m3747.sh 29 格 + m3747b.sh 15 格 + m3747c.sh 6 格 = 50 格):head 与 GNU 逐字节一致 29 格;红 21 格,其中 6 格是 argv0/$0 约定差异(-c 下 GNU $0=bash vs rubash exe 路径,以及诊断前缀 bash: vs rubash.exe:,非语义),15 格是真实语义分歧,全部落在 F1/F2(${!#^}、${!#,}、${!#^2}、${!#/a/Q}、${!#%2}、${!#:0:1}、${!#/@(2)/Q}、${!?/0/Q}、${!?%0}、${!2/a/Q}、${!#/2/Q}、${!#/2/zz} 等)。

未跑/VOID 的腿:无

处置:不合、不关单,等返工(补 / % : :offset @(...) 尾的 t 后运算符实现,并把 ^/, 从特殊头合法尾里去掉)。

…t ^,

Audit follow-up: is_valid_indirect_expression had admitted the whole
`: - + = ? # % / ^ , @` tail class for `!`+special/digit heads while
only the `:- - + = ?` operators were implemented, turning GNU's
defined semantics (and its bad-substitution errors) into silent
empty output.

- Tail class narrowed to the class string_extract scans after a
  `!`+special head — `#%:-=?+/@` (subst.c:9844-9860). `^`/`,` on
  special/digit heads (`${!#^}`, `${!#,}`, `${!#^2}`) are bad
  substitution again.
- `!`+`#?@*`/digit heads with `/`,`%`,`:`(non-`-=?+`) or `@` tails
  resolve t = the parameter the source VALUE names and re-dispatch
  the operator on t (parameter_brace_find_indir, subst.c:7839-7881,
  feeding parameter ops at :9978-10017):
  - expand_braced_special resynthesizes `${t tail}`;
  - indirect_substring_parameter resolves `:off:len` through t;
  - indirect_replacement_parameter re-dispatches `${t/pat/rep}`;
  - indirect_parameter_transform re-dispatches `${t@op}`;
  - indirect_holder_target_name: `#` -> positional count, `?` ->
    status, `@`/`*` -> joined value, `0` -> script name (not
    positional_window[0]).
- `${0<op>}` routes to script_name_value in the replacement and
  transform digit arms (subst.c:9424-9428 name-first lookup).
- An unset indirect target under `@op` renders NULL (subst.c:8927),
  not the quoted-empty `''` a set-empty cell earns.
- zero_reports_script_name_as_target pin moved to script-file form.

29-case matrix (F1+F2+probes) byte-identical to GNU bash 5.3.20
stdout+stderr+rc; pins 18/18; adjacent slices green; fmt/marker-lint
clean. Refs #3605

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@caomengxuan666

Copy link
Copy Markdown
Member Author

对 FAIL(comment 6914442298)的返工已推:head f6d075fd。

F1(^/, 特殊头尾 → bad substitution) — is_valid_indirect_expression 的尾类已收窄到 string_extract 在 !+special 头之后扫描的 #%:-=?+/@(subst.c:9844-9860),^/, 移出。x${!#^}y / x${!#,}y / x${!#^2}y → bad substitution rc=1,与 GNU 5.3.20 及 base(0a405d8) 逐字节一致。pin hash_caret_tail_is_bad_substitution。

F2(/ % : :off @(...) 尾作用于 resolved-t) — !+#?@*/digit 头带 /、%、:(非 -=?+)或 @ 尾时,现在经 parameter_brace_find_indir 模型(subst.c:7839-7881 → :9978-10017)把 t 解出来后按 ${t<op>} 重新分发:

  • expand_braced_special 对扫描族 resynthesize ${t tail};
  • indirect_substring_parameter 特殊头 :off:len 过 t(${!#:0:1} → ${2:0:1} → b);
  • indirect_replacement_parameter 特殊/digit 头重分发 ${t/pat/rep}(${!?/a/Q} == ${0/a/Q});
  • indirect_parameter_transform 特殊/digit 头重分发 ${t@op}(${!#@Q} → 'b');
  • indirect_holder_target_name:#→位置数、?→状态、@/*→join 值、0→script name(不再读 positional_window[0]);
  • ${0<op>} 在 replacement/transform digit 臂走 script_name_value(subst.c:9424-9428 name-first lookup);
  • unset 间接目标在 @op 下渲 NULL(subst.c:8927),不再产出 ''。

审计全形逐格(GNU /usr/local/bin/bash 5.3.20 对照,macOS arm64)——${!#/a/Q}→b、${!#%2}→b、${!#:0:1}→b、${!#/@(2)/Q}→b、${!?/0/Q}/${!?%0}→case.sh、a=hello b=world; set -- a b; echo ${!@/a/Q}→a b: invalid variable name rc=1、${!2/a/Q}→空、${!#/2/Q}/${!#/2/zz}→b、name 头 x=zzz; ${!x^}/${!x,Q}/${!x@Q}→空 rc=0(name 头 ^/, 是合法 casemod 尾——限制只作用于 special/digit 头):29 格 stdout+stderr+rc 全对 GNU 逐字节一致。新增 pin f2_tails_apply_to_resolved_t_parameter、named_source_tails_follow_the_resolved_target。

F3(钉形态) — zero_reports_script_name_as_target 已改脚本文件形态(temp dir 写 zero_indir.sh 再以脚本路径执行),断言与 GNU 脚本形态同形:zero_indir.sh: zero_indir.sh: invalid variable name 逐字节。

已知残差(非本 PR 面,均未修):rubash startup $?=1 vs GNU 0(F2 钉里用 true; 先落定);issue323_patsub_ansi_c_regressions 在 base(5b49fa1) 上同形复现,环境性既有失败。

腿:pin 18/18 绿;issue1147/2608/2649/2712/529/439/1091_1092_1093/1910/1927/3022/3501/843/371/parameter_transform_tests 全绿;rustfmt/marker-lint(117 consts, 268 sites)净。

@caomengxuan666

Copy link
Copy Markdown
Member Author

【WIN-AGENT-AUDIT】PR #3747 第2轮 — 建议:FAIL
head: f6d075f base(merge-base): 0a405d8 文件: 9 个 +608/-42
关联 issue: #3605(状态:open,我核过的时间:2026-11-16 21:41 CST)

机制核查:

  • 上轮 F1/F2/F3 返工属实:special/digit 头 ^/, 仍 bad substitution;/ % : :off @X 尾对解析出的 t 重派发(GNU 锚点 subst.c:7883-7952 parameter_brace_expand_indir → :9978-10017);$0 走 script_name_value。方向与 GNU 一致。
  • diff 无可疑无关改动;无桥接/翻译层/半成品守卫。
  • 但 ?/:? 尾仍落在「放行未实现」同一缺陷类,见 F1。
  • 正文缺「本 PR 删除了什么」一节(非纯测试 PR);正文自称 29-case 矩阵 byte-identical,但矩阵未覆盖 ? 尾(见 F1)。

腿(逐项数字):

  • 钉自跑:issue3605_indirect_special_source 18 passed / 0 failed
  • fail-first:base 0a405d8 + 钉文件原样 → 6 passed / 12 failed,红名 = {at_default_reports_joined_name, f2_tails_apply_to_resolved_t_parameter, hash_dash_default_resolves_through_count, hash_default_resolves_through_count, hash_empty_resolves_to_script_name, hash_substring_tail_slices_target, named_source_tails_follow_the_resolved_target, question_dash_default_falls_back_when_target_unset, question_dash_default_resolves_through_status, question_patsub_applies_to_resolved_target, star_default_reports_joined_name, zero_reports_script_name_as_target},与 PR 声称修复面一致(钉有效,非废钉)
  • lib 双边(本机 Windows cargo test --lib):head 失败名集 {api::consumer_tests::issue2084_session_end_restores_host_process_state} / base 同名集 / 差集 {}(该子进程 scenario exit 101 为本机环境性失败,两侧同名)
  • -D warnings:CARGO_INCREMENTAL=0 RUSTFLAGS="-D warnings" cargo check --locked --lib --bins → 0 警告
  • 卫生:rustfmt --edition 2021 --check 9 个涉改文件全 OK;python scripts/check-marker-literals.py OK(117 consts, 268 allowlisted);WSL bash scripts/check-utf8-boundary-hygiene.sh clean
  • CI(head f6d075f):GNU regression goldens 红 = {issue_753::case_9_declare_indexed_operand_binds_nothing, upstream_suite_slice_snapshots},与 master c3bf91e 基线 run 43873261247 逐格一致 → 基线;Regression pin stem census 红 90 名 vs master 基线 90 名:head 多出 6 名全在 issue371_assoc_assignment_transform(at_sign_at_a_quoted×4、assoc_member_and_bare_at_a、indexed_star_at_a_quoted、scalar_at_a_at_a_at_q 各档),归因 = merge-base 0a405d8 早于 master 修复 88fd543(Refs [bug] 带引号的 "${a[@]#...}" 单 "" 元素应诊断,rubash 静默(#3501 残差) #3581,quoted-aware list path),属陈旧基线非本 PR 账;master 侧多出 6 名(issue2340/2539/2658×3/3255)为时序性 flaky。Rust tests / Compatibility CLI / Cross-target×2 / Shell functionality / API ledger / niubash builds / Windows compile check 全 pass
  • GNU 对照:WSL GNU bash 5.3.20(/usr/local/bin/bash,owner-compiled),脚本 target/t2-probes/q3747.sh(LF 落盘)。形状:set -- a b c 下 ${!#-v}/${!#:-v} → GNU <c> / head <c> 一致;${!#?v}/${!#:?v} → GNU <c> / head !#: v 致命错误且脚本中止(分歧,见 F1);${!u?v}(u=x、x 未置位)→ GNU 报 x: invalid variable name 并继续后续行 / head !u: v(base 0a405d8 同样 !u: v → name 源为存量缺陷,本 PR 把 special/digit 源新放行进同一错误路径)

F 点:

  • F1: ${!src?word} / ${!src:?word} 族的 ? 判定作用于未解析的 !-indirect 源名,而非 GNU 的解析后目标。复现:set -- a b c; printf '<%s>\n' "${!#?v}" → GNU 5.3.20 输出 <c>(subst.c:7883-7952 parameter_brace_expand_indir 先把 # 解析为 t=3→${3}=c 已置位,:10412-10414 ? 对已置位目标直接取值);head 报 !#: v 并中止整个脚本。同族 ${!u?v}(u=x、x 未置位)GNU 报 x: invalid variable name 继续执行,head/base 均报 !u: v(name 源存量缺陷)。错误名、错误文本、继续/中止语义三处均与 GNU 不符。建议:?/:? 在 indirect 源上先按 parameter_brace_find_indir(subst.c:7839-7881)解析目标名再判定 set/unset(special/digit 头为纯查表,可行);扫描路径(parameter_expansion_error_in_word_context 系)与求值路径需同一口径。

续作记录:本轮为验证轮,未动代码;前轮返工 commit f6d075f 已在远端 head。

未跑/VOID 的腿:无。

@caomengxuan666

Copy link
Copy Markdown
Member Author

【WIN-AGENT-AUDIT】PR #3747 第3轮 — 建议:FAIL(维持第2轮判词,F1 复现确认且范围比审计描述更宽)
head: f6d075f base(merge-base): 0a405d8 文件: 9 个 +608/-42
关联 issue: #3605(状态:open,伞目录,本轮不关单;核于 2026-11-17 本地)

head 与第2轮 FAIL 判定时完全一致(gh api 复核未动),未重跑全腿;F1 用 WSL GNU bash 5.3.20(1)-release(/usr/local/bin/bash,x86_64-pc-linux-gnu)脚本文件对照复现,探针 target/u1-probes/indir3747*.sh(LF 落盘):

机制核查:

  • 维持第2轮结论:F1 属实——?/:? 尾的判定作用于未解析的 !-indirect 源名而非 GNU 的解析后目标(GNU 锚点 subst.c:7883-7952 parameter_brace_expand_indir → parameter_brace_find_indir :7839-7881 先解 t,再由 :10412-10414 判 set/unset)。
  • diff 无可疑无关改动;无桥接/翻译层。

GNU 对照实测矩阵(rubash head f6d075f vs WSL bash 5.3.20,同脚本文件):

形状 GNU rubash head 判定
set -- a b c; ${!#?v} <c> rc=0 继续 !#: v 致命中止 分歧(F1)
set -- a b c; ${!#:?v} <c> rc=0 继续 未到达(前格已中止;同族同病) 分歧(F1)
u=x; x=hello; ${!u?v} <hello> rc=0 继续 !u: v 致命中止 分歧——named 源目标已置位仍误判
u=x; x 未置位; ${!u?v} / ${!u:?v} !u: v 致命 !u: v 致命 一致(表象同文,内因待考)
set -- a b c; ${!2?v} !2: v 致命 !2: v 致命 一致

要点修正第2轮描述:

  1. F1 不止 special/digit 源——named 源在目标已置位时同样误判(u=x, x=hello, ${!u?v}:GNU 解析 u→x→hello 输出值,head 报 !u: v 中止)。
  2. 第2轮称 GNU 对 u=x、x 未置位 报 x: invalid variable name 并继续——本轮 WSL 5.3.20 实测 GNU 报 !u: v 且同样中止(与 head 表象一致);若队长在 macOS bash 上观察到 x: invalid variable name,请复核是否为平台/版本差异,建议钉按脚本文件形态钉 GNU 实际输出。
  3. digit 源 ${!2?v} 两侧同报 !2: v——GNU 对 digit 头的 ? 尾本就不解析(与 special 头 # 不同),修复面应限定 special 源(# ? @ *)+ named 源的置位判定,digit 源维持现状即可。

腿:

  • 钉自跑 / fail-first / lib 双边 / -D warnings / 卫生 / CI:第2轮已在同 head 跑齐(pin 18/18;base 6p/12f 红名与修复面一致;lib 差集 {};warnings 0;fmt/marker/utf8 净;CI 红=基线 goldens 2 + census 陈旧基线),本轮未重复
  • GNU 对照:本轮新增(上表),WSL /usr/local/bin/bash 5.3.20(1)-release;平台为 Linux 对 Linux,结论不依赖 Windows 差异

F 点:

  • F1(维持+扩面):?/:? 尾对 indirect 源的置位判定必须先按 parameter_brace_find_indir 解析目标(special 源 #?@* 与 named 源同);当前对未解析源名判定 → 目标已置位也报 !src: word 中止。复现:u=x; x=hello; printf '<%s>\n' "${!u?v}" → GNU <hello> / head !u: v rc=1;set -- a b c; printf '<%s>\n' "${!#?v}" → GNU <c> / head !#: v rc=1。探针 target/u1-probes/indir3747.sh、indir3747q3.sh、indir3747q3b.sh、indir3747q3c.sh、indir3747q3d.sh。

续作记录:本轮为验证轮,未动代码。
未跑/VOID 的腿:无(全腿沿用第2轮同 head 证据 + 本轮 GNU 复现)

@caomengxuan666

Copy link
Copy Markdown
Member Author

【WIN-AGENT-AUDIT】x3 续作开工

本 lane(x3)接手第3轮 FAIL 的 F1 返工:?/:? 尾对 !-indirect 源须先经 parameter_brace_find_indir 解析出 t,再按 t 的置位状态判定(GNU 锚点 subst.c:7883-7952 parameter_brace_expand_indir → :7839-7881 find_indir → :10412-10414 set/unset 判定)。

计划:checkout devin/indirect-special-source @f6d075fd → WSL 5.3 对照复现 named/digit/special 三源 × ?/:? → 按机制修(resolved-t 判定,非个案补丁)→ 钉补格 → 钉自跑 + fail-first + lib 双边 + 警告门 → push 新 commit(不改写历史)→ REWORK 报告。

…3605)

A `?`/`:?` tail on a `!`-indirect source was adjudicated against the raw
`!src` name, so a set target aborted: `u=x; x=hello; echo ${!u?v}`
reported `!u: v`.  GNU resolves t first — parameter_brace_expand_indir
(subst.c:7883-7952) -> parameter_brace_find_indir (subst.c:7839-7881)
produces the source value, parameter_brace_expand_word(t)
(subst.c:7907) produces the value the operator tests, and only a null
temp takes the report arm, which still names the ORIGINAL expression
(subst.c:10412 parameter_brace_expand_error).

scan_question_is_error now routes `!`-indirect names through
indirect_parameter_operator_value (the same two-step resolution the
`-`/`+`/`=` family already used) before the set/null verdict.

Verified against WSL GNU bash 5.3.20 from script files on 20 shapes
(named/digit/special source x ?/:? x set/unset/empty, plus the
`!?`/`@`/`*` and invalid-target arms); pin
issue3605_indirect_special_source 20/20 (13 red at merge-base).
@caomengxuan666
caomengxuan666 marked this pull request as ready for review November 17, 2026 06:49
… split (Refs #3605)

`${!??v}` / `${!?:?v}`: the first `?` is the indirect SOURCE ($?,
subst.c:122 VALID_INDIR_PARAM / subst.c:9920 want_indir), so the `?`
error operator is the NEXT character. The operator family's
`split_once_outside_subscript(name, '?')` took the source byte for the
operator, leaving subject `!` and returning an empty value: GNU resolves
`$?` -> "0" -> `$0` through parameter_brace_find_indir
(subst.c:7839-7881) + parameter_brace_expand_word(t) (subst.c:7907) and
prints the shell name.

Re-split a `!?`-headed name at the operator `?` and pass the
two-character subject `!?` through parameter_operator_value — the same
two-step resolution `${!?}` (bare) already uses.

Verified against WSL GNU bash 5.3.20 from a script file (22-shape matrix
of named/digit/special sources x ?/:? x set/unset/null) byte-identical
stdout/stderr/rc. Pin issue3605_indirect_special_source 21/21; the new
case is bad substitution at the branch's base commit.
@caomengxuan666

Copy link
Copy Markdown
Member Author

【o1 收网验证 · 建议 PASS】head 3c525fae6(在 x3 lane 的 bd02ca58f 之上叠加 1 个 commit;远端原 head 已前进,未覆盖、只追加)

F1 逐条回应(第3轮 FAIL):

  • F1 已修(机制):?/:? 判定改为对解析后的 t 取值 —— parameter_brace_expand_indir(subst.c:7883-7952)→ parameter_brace_find_indir(subst.c:7839-7881)把源文本解析成 t,parameter_brace_expand_word(t)(subst.c:7907)再取 t 所指参数的值,var_is_set = temp != NULL(subst.c:10133-10140)才是判定;报错名仍是原表达式(subst.c:10412)。scan_question_is_error 经 indirect_parameter_operator_value 走这两步。
  • 本轮补充 1 个真缺口:${!??v} / ${!?:?v} —— 第一个 ? 是间接源($?,subst.c:122 VALID_INDIR_PARAM / :9920 want_indir),运算符是后一个;旧 operator family 在源字节上切分,subject 变成 !,值返回空。新 commit 在 !? 头处按运算符重新切分,subject !? 走 parameter_operator_value(与裸 ${!?} 同一路径),GNU 输出 $?→0→$0 的 shell 名。
  • named 源 u=x; x=hello; echo ${!u?v} → <hello>(GNU 同形);${!#?v}/${!#:?v} → <c>;${!2?v}($2=b,b 未置位)→ !2: v;b 置位 → <zzz>;u=2 二段间接 → <b>;${!u:?v}(y 为 null)→ !u: v。
  • ${!@?v}/${!*?v} 维持 <t>: invalid variable name(t=a b c),与 GNU 同文;posix 模式 ${!?x} 仍是 !: x。

GNU 对照:WSL GNU bash 5.3.20 脚本文件 22 形状矩阵(named/digit/special × ?/:? × set/unset/null,含 !? 源与 invalid-target)stdout+stderr+rc 逐字节一致(路径前缀归一后 diff 为空)。

腿(Windows):

  • 钉 issue3605_indirect_special_source 21/21(20 + 新增 question_source_bang_question_expands_through_status)
  • fail-first:分支 base 0a405d8a + 钉 → 18 red / 7 passed(红名含全部 +${!?} 新格;base 上 ${!??v} 直接 bad substitution)
  • lib 双边:head 1373P/1F、base 1351P/1F(base 树更早),失败名同为 api::consumer_tests::issue2084_session_end_restores_host_process_state(本机 __RUBASH_CURRENT_LINE 注入,环境绑定)
  • 相邻切片全绿:issue1147 2/2、issue2608 5/5、issue2649 12/12、issue2712 11/11、issue439 11/11、issue529 8/8、issue3501 68/68、parameter_transform 18/18
  • RUSTFLAGS=-D warnings cargo check 净;rustfmt 逐文件净
  • CI 归因见上轮同窗口比对(census 86 vs master 90,PR-only=issue1902 flake;goldens 两边同为 issue_753::case_9 + upstream_suite_slice_snapshots);新增 commit 只动 2 文件 + 1 钉

关联 #3605:伞目录,保持 OPEN。未跑腿:WSL Linux 原生构建(本改动非 unix-gated/fd 族)。

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