Skip to content

arith: paren operand after </> is not a procsub; subscript errors surface (A1 group) - #3132

Merged
caomengxuan666 merged 9 commits into
masterfrom
fix/A1-wave1
Nov 10, 2026
Merged

caomengxuan666 merged 9 commits into
masterfrom
fix/A1-wave1

Conversation

@caomengxuan666

@caomengxuan666 caomengxuan666 commented Nov 8, 2026 •

Copy link
Copy Markdown
Member

概要

180 单令第一波 A1 组(算术展开族两单):

  • [upstream] Arithmetic expansion: parenthesised operand after </> inside $(( )) is also executed as a command #2648:$(( 4>(2+3) ? 1 : 32)) 里 >/< 后的括号操作数被额外当作进程替换执行(2+3: command not found;赋值形还把 /dev/fd/N 拼进算术文本)。根因:parser 的 raw 词进程替换扫描不跳过 $((...)) 等 $ 引入的成组跨度。GNU subst.c:10915/10926 在 expand_word_internal 的 $ 臂整段提取算术跨度,其字符永不到达 subst.c:11365-11378 的 </> 臂。修法:三处 raw 扫描(embedded 提取 / has 判定 / verbatim 定位)在未引号状态下遇到 $(/${/$[ 时整组跳过(复用 lexer 的 dollar_word_group_len,与 P_ARITH walker 同规则)。
  • [upstream] Arithmetic: error inside an array subscript is silently swallowed (missing diagnostic) #2654:((array[$index]++))(index='0],b[1')静默 rc 1,丢 GNU 的下标诊断。根因:(( ))/$(( )) 的 expand=true 求值管线漏了 indexed 下标的成组展开 pass——展开后的文本被整串拼接,下标在值自带的 ] 处被截断,余下文本重词法成合法逗号表达式。GNU subst.c:11107 expand_array_subscript 把下标成组展开并以 abstab([/]/$/反引号/~,subst.c:11120-11122)反斜杠引用后拼接;本仓的等价 pass(expand_arith_indexed_subscripts)此前只接在 let/[[ 路径上。修法:两个 expand 入口(eval_arithmetic_command_value_with_flags 的 expand 臂、eval_arithmetic_expansion_value 的展开路线)同样接上该 pass。

本 PR 删除了什么

无删除。三处修法均为既有机制的接线/补全:#2648 给三处 raw 扫描补上「$ 成组跨度不透明」这一既有 GNU 不变量(删除的是扫描对算术跨度内部字符的误读路径,无代码行删除);#2654 把既有的 indexed 下标 pass 接到两个此前漏接的求值入口,并让 nounset 名称扫描透视该 pass 的下标编码(纯增行)。净行数以 diff 为准。

验证(全部数字来自落盘日志,详见车道 REPORT)

  • 钉(头树):issue2648 11 过/0 败;issue2654 11 过/0 败。
  • fail-first(真基底 88047f5,钉移植):issue2648 4 过/7 败(7 败全为机制格,签名逐字吻合;4 过为真 procsub/>=/(( )) 对照格);issue2654 8 过/3 败(败格 = (( )) 机制格、$(( )) 机制格、let nounset 格)。
  • lib 双边:头 1206/0/4 = 基底 1206/0/4。邻居 14 stem:13 绿,issue1555 一格红与基底同格同败(既存)。-D warnings rc 0;fmt --check rc 0;marker-lint OK。GNU 探针矩阵:[upstream] Arithmetic expansion: parenthesised operand after </> inside $(( )) is also executed as a command #2648 全 13 形、[upstream] Arithmetic: error inside an array subscript is silently swallowed (missing diagnostic) #2654 全形 SAME。
  • 钉期望订正(提交 6af1bd6):issue2654 原钉期望失败构造后 echo rc=$? 打印 rc=1;GNU 5.3.20 逐字实测为算术语法错误中止整个非交互脚本(空 stdout、rc 1),产品与 GNU 一致、是钉写错,已按 oracle 订正。
  • 回归修复(提交 4461157):接线 indexed pass 使下标标识符被 hex 编码,nounset 文本扫描(arithmetic_unbound_variable)看不见——set -u; (( b[undef]++ )) 在基底本有陷阱、接线后变静默。修法:扫描遇载体标记就地解码并同规则递归扫描;关联键在 name[ 分支整段跳过不受影响。此修复同时治好 let 入口的同款既存静默。回归钉格已补入 issue2654 stem。
  • 残差两条(证据全在 REPORT):(1) (( )) 入口下标内 $undef 形的 nounset 静默——基底同形为另一种错形、非本组改坏,机制在算术 $-展开层,建议单独立案;(2) 元素值递归求值的 nounset((( b[i]++ )) 元素值 y)基底/头树同分歧,既存、与本组无关。

未含:#2685(同组第三单,队长注意)

#2685(嵌套算术展开 52 层失败)的根因已确诊:embedded 参数 walker 的线程局部递归守卫 MAX_EXPAND_DEPTH=50(src/executor/embedded_parameters.rs:81)到限后原样返回词面,最内层 $((...)) 以字面文本进入算术 parser 报 operand expected。GNU 无此固定上限(subst.c:10915/10926 在 C 栈上递归)。该守卫所在文件是 在飞 PR #3113 的活文件,按车道简报面核纪律本车道停手不硬改——钉已写好并 fail-first 验证(基底 1 过/4 红),存于车道工作区 issue2685_pin.rs,请队长在 #3113 合入后排修(或裁定守卫面上调/栈增长方案)。

Refs #2648
Refs #2654
Refs #2685

…must not execute as process substitution

GNU subst.c:10915/10926 extracts a $((...)) span whole in
expand_word_internal's $ arm; its characters never reach the
</> process-substitution arms (subst.c:11365-11378). The pin's
defect cells fail on the base tree (8 red); the real-procsub and
>= controls pass.
…e GNU's diagnostic

GNU subst.c:11107 expand_array_subscript expands the subscript as
a unit and backslash-quotes the bracket/dollar/backtick/tilde
class (subst.c:11120-11122) before splicing, so expansion-produced
brackets cannot re-lex; the subscript then fails in its own
evalexp frame (arrayfunc.c:1368, expr.c:1524-1535). The pin's
defect cells fail on the base tree (4 red); both controls pass.
The raw-word process substitution scans did not know that a `>(` or
`<( `shape inside a `$((...))` arithmetic expansion is a comparison
operator with a parenthesised operand, not a process substitution.
GNU consumes the whole arithmetic span first: expand_word_internal's
`$` arm routes `((` to extract_arithmetic_subst (subst.c:10915) and
expand_arith_string (subst.c:10926); the `<`/`>` process substitution
arms (subst.c:11365-11378) never see the inside of the span.

All three raw scans in process_substitution.rs
(embedded_process_substitutions_in_raw,
raw_word_has_unquoted_process_substitution,
verbatim_process_substitution_span) now skip a balanced `$(...)`
group via a new dollar_group_end helper built on
lexer::dollar_word_group_len — the same group walker the expansion
engine uses — matching the balanced-span consumption the dedicated
procsub word walkers in this file already perform for their own
paren tracking. An unbalanced group falls through to the previous
behaviour. Quoted contexts are untouched (the skip is gated on the
existing !single && !double state).

(+ pin-file cargo fmt touch in the same commit.)

Refs #2648
…)) (#2654)

GNU expands an indexed array subscript as a unit before evaluating
the enclosing arithmetic: expand_word_internal's `[` arm under
Q_ARITH (subst.c:11395-11405) calls expand_array_subscript
(subst.c:11107), which expands the subscript and re-quotes it with
sh_backslash_quote (abstab `[`, `]`, `$`, backtick, `~`;
subst.c:11120-11122). The subscript is then evaluated in its own
frame (array_expand_index, arrayfunc.c:1368-1378) and an error is
reported under the subscript's own text (evalerror, expr.c:1524).

rubash had the equivalent pass — expand_arith_indexed_subscripts,
which marker-encodes the subscript via
encode_arithmetic_assoc_key so the parser's eval_subscript_index
decodes and evaluates it as a unit — but it was only wired into the
let and [[ ... ]] paths. The two general arithmetic entries spliced
subscript text raw, so a subscript whose expansion contained `]`
(for example from an unbound comma expression under nounset) was
cut at the wrong bracket and destructured into a valid-looking
comma expression, failing silently instead of raising GNU's
"arithmetic syntax error" diagnostic.

Wire the indexed pass into eval_arithmetic_command_value_with_flags'
expansion branch and into eval_arithmetic_expansion_value's
expansion route, right after the existing assoc pass and before the
whole-string expansion — the same position the assoc pass already
occupies. The quote-removal route is unchanged (its subscripts are
already unit-scoped expansions). No diagnostic text is created
here: the failing frame already produces GNU's message and names
the subscript text once the subscript is evaluated as a unit.

(+ pin-file cargo fmt touch in the same commit.)

Refs #2654
The four defect cells expected the trailing `echo rc=$?` to print
after the failing construct. GNU bash 5.3.20, run on the exact pin
scripts, produces NO stdout and exits 1: an arithmetic syntax error
aborts the whole non-interactive script, so the trailing echo never
runs. The head product already matches GNU byte-for-byte (empty
stdout, rc 1, and the subscript diagnostic on stderr); the pin was
written against a wrong continuation assumption.

Expected stdout for the four cells is now empty, and the helper
also asserts the script exit code is 1. The fail-first property is
unchanged: on the defective tree the same scripts exit 1 with an
EMPTY stderr, so the diagnostic (NEEDLE) assertion is what fails
there — the silence is the defect (subst.c:11107 /
arrayfunc.c:1368-1378 / expr.c:1524-1535, as cited in the pin).

Refs #2654
…#2654)

Wiring expand_arith_indexed_subscripts into the arithmetic command
entry (previous commit) regressed the nounset trap for identifiers
inside indexed subscripts: `set -u; (( b[undef]++ ))` went silent.
The pass hex-encodes the expanded subscript behind
ARITH_ASSOC_KEY_MARKER (encode_arithmetic_assoc_key), and
arithmetic_unbound_variable — the text scan every arithmetic entry
runs before evaluation — then sees only hex digits where the
identifier stood.

GNU evaluates an indexed subscript in its own evalexp frame
(arrayfunc.c:1368-1378 array_expand_index), where expr_streval
(expr.c:1190-1216) traps an unset read exactly as at the top level.
Make the scan decode a carrier payload in place and scan the
decoded subscript text with the same rules (assignment-target
exemptions included). Associative keys are unaffected: the scan
skips an associative subscript whole at its `name[` branch, so key
text stays data, as in GNU.

This also repairs the same silence on the `let` entry, whose
EXP_EXPANDED route has run the encoding pass all along
(`let 'b[undef]++'` was silent on the base tree too).

Refs #2654
@caomengxuan666 caomengxuan666 changed the title fix(arith): paren operand after </> is not a procsub; subscript errors surface (A1 group) arith: paren operand after </> is not a procsub; subscript errors surface (A1 group) Nov 10, 2026
@caomengxuan666
caomengxuan666 marked this pull request as ready for review November 10, 2026 03:56
@caomengxuan666
caomengxuan666 merged commit d65441d into master Nov 10, 2026
11 checks passed
caomengxuan666 added a commit that referenced this pull request Nov 10, 2026
…3221)

The output process-substitution spawn carries fd>=3 through the __RUBASH_FD_* env channel as inheritable dups delivered AT their stamped numbers; the child's init restores the stamped handle instead of adopting whatever descriptor sits at slot fd. Without this declaration the consumer adopted the inherited outer file at slot 3 (direct-test6: tap.log 7 lines, comsub empty, INNER-RC=1). GNU anchor: subst.c:6362 process_substitute forks the consumer at expansion time inheriting the expansion-time table, which is what the stamped handle carries.

The comsub-nesting attribution half of this shape is already in master via #3132 (dollar_group_end opacity, d65441d): a span inside $(...) belongs to the comsub child, so the clone's stage machinery materializes it via this stamped spawn route. This commit carries the stamped-delivery half plus the pin that proves the combination.

Verified on the Simular box (run6, pre-rebase tree): fail-first pin 3 passed / 2 failed; head pin 5 passed / 0 failed; probe-adopt, V1, V2, V3 all pass; direct-test6 INNER-RC=0; RUSTFLAGS="-D warnings" cargo check rc=0; fmt rc=0; marker-lint rc=0; lib head 1207 passed / 0 failed, failure name set empty. Re-verification on the rebased head (run7) follows.

Refs #3221
caomengxuan666 added a commit that referenced this pull request Nov 10, 2026
…3221)

The output process-substitution spawn carries fd>=3 through the __RUBASH_FD_* env channel as inheritable dups delivered AT their stamped numbers; the child's init restores the stamped handle instead of adopting whatever descriptor sits at slot fd. Without this declaration the consumer adopted the inherited outer file at slot 3 (direct-test6: tap.log 7 lines, comsub empty, INNER-RC=1). GNU anchor: subst.c:6362 process_substitute forks the consumer at expansion time inheriting the expansion-time table, which is what the stamped handle carries.

The comsub-nesting attribution half of this shape is already in master via #3132 (dollar_group_end opacity, d65441d): a span inside $(...) belongs to the comsub child, so the clone's stage machinery materializes it via this stamped spawn route. This commit carries the stamped-delivery half plus the pin that proves the combination.

Verified on the Simular box. run6 (pre-rebase tree): fail-first pin 3 passed / 2 failed (cells 04/05 red); head pin 5 passed / 0 failed; probe-adopt, V1, V2, V3 all pass; direct-test6 INNER-RC=0; RUSTFLAGS="-D warnings" cargo check rc=0; fmt rc=0; marker-lint rc=0; lib head 1207 passed / 0 failed, failure name set empty. run7 (rebased head, box pid 718998): Phase A on pure master d7a3725 — pin 5/0 and probe-adopt PASS without this PR (#3132 + #3234 already fix the reduced shapes); Phase B on the head — probe-adopt, V1, V2, V3 pass, pin 5/0, direct-test6 INNER-RC=0, -D warnings/fmt/marker-lint rc=0, lib head 1230 passed / 0 failed / 4 ignored, failure names none. run8 (discrimination, 917870f binary, box pid 721997): direct-test6 INNER-RC=1 with the byte-identical leak and pin 5/0 — #3266 exonerated, and the stamped insert is what fixes the real bats shape (the reduced pin passes on master without it; the full shape is guarded by the direct-test6 box leg). Adjacent gap, out of scope: the backquote shape (out=`exec 3<&1; ...`) still fails on the head (BQ-FAIL: log non-empty) — #3132's rule covers only $-groups; GNU expects OUT hello twice, log empty.

Refs #3221
caomengxuan666 added a commit that referenced this pull request Nov 12, 2026
#3337) (#3351)

## 概要

命令替换的 backquote 形态下,组内的进程替换被外层词的 raw 扫描误认领:赋值材料化在外层先把组内的 `>(...)` 生成出来,消费者在外层上下文运行——此时 backquote 本体内 `exec 3<&1` 的 fd 3 重绑定尚未发生,fd 3 是环境 fd(外层 `exec 3>tap.log` 的 TAP 文件),hello 落进日志而非 comsub 捕获管道。

`$(...)` 同形已由 #3221 一线处理:parser 的三处 raw 词扫描(embedded 提取、has-unquoted 判定、verbatim 跨度定位,`src/parser/process_substitution.rs`)在 #3132 时补上了「`$` 引入的成组跨度不透明」(`dollar_group_end`)。本 PR 给同一组扫描补上 backquote 跨度的不透明臂(`backquote_group_end`,复用 lexer 的 `skip_backtick_corrected`,与 tokenizer 同一 walker)。GNU 分工:`expand_word_internal`(subst.c:11572 backquote 臂)以 `string_extract` 整段取走组体交 `command_substitute`(subst.c:7143)作内层命令文本执行,组内的 `<`/`>` 永远到不了本词层面的进程替换臂(subst.c:11364-11378);backquote 在双引号内仍然有效(只有 `<`/`>` 臂被 `Q_DOUBLE_QUOTES` 抑制),故跳过臂只以 `!single` 为门。

回归钉:`tests/issue3337_backquote_procsub_opacity.rs`(8 格)——01 立案原形、02 嵌词形、03 双引号内、04 参数词、05 体内输入跨度、06 消费者 fd 3 读回判别、07/08 守卫格。队长复核卷宗见 review-3351(钉双边、探针矩阵、lib 名集与卫生腿均独立复跑)。

Fixes #3337
Refs #3353
Refs #3354

## 本 PR 删除了什么

无删除。产品改动为纯新增:`src/parser/process_substitution.rs` 新增一个内部助手函数并给三处 raw 扫描各补一个与既有 `$` 臂同形的 backquote 跳过臂(+50/−0);回归钉为新增文件(+289)。
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