Skip to content

WIP: fix #2527 #2528 expansion fetch/status - #2554

Merged
caomengxuan666 merged 3 commits into
masterfrom
fix/2527-single-fetch
Nov 2, 2026
Merged

caomengxuan666 merged 3 commits into
masterfrom
fix/2527-single-fetch

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Refs #2527
Refs #2528

…2527)

GNU parameter_brace_expand (subst.c:9777) fetches the parameter exactly
once: array_value_internal evaluates the subscript inside that fetch and
prints err_badarraysub there, and the operator arms test and use the one
result (subst.c:8096 parameter_brace_expand_rhs). Rubash's layered error
pre-scan fetched subscripted operator left-hand sides a second time:
nested_operator_word_error called the evaluating fetcher outside any
memo scope, so the subscript ran twice (index++ side effects applied
twice, values diverged) and the bad-subscript diagnostic printed twice,
once in the scan and once in the real expansion.

The pre-scan now derives its set/null verdict without evaluating a
subscript (pre_scan_operator_value): plain names and the [@]/[*] joins
keep their pure reads; element references are answered from the same
storage/dynamic sources the fetch's own legs read, only for subscripts
whose evaluation is provably side-effect-free (clean integer literals,
expansion-free assoc keys); anything else is left undecided and the real
expansion's single fetch adjudicates it. The substring negative-length
arm of the same scan gets the same discipline. No diagnostic dedup and
no subscript special-casing in the expansion arms.

Verified: issue1555 stem 12/12, issue614 stem 5/5, probes byte-identical
to the GNU 5.3.20 oracle; guards issue2343/issue1600 green.
…es (rubash#2528)

A failed ${name[@]:=word} bind pre-sets EX_BADUSAGE (subst.c:8164) and
throws DISCARD; the script reader_loop (eval.c:111-118) preserves the 2,
while a parse_and_execute catch (evalstring.c:423-450 — eval, comsub
bodies, the -c driver's run_one_command frame) folds it to
EXECUTION_FAILURE 1. Matched-harness oracle probes (GNU 5.3.20) show
rubash already implements that split for simple commands (file 2, -c 1);
the issue's five failing pins are a harness artifact (expectations taken
from script files, harness runs -c) — see the cluster report.

The genuine defect in the same surface: the builtin/function pipeline
stage harvests folded the element clone's ExpansionFailure(2) only
inside a command-substitution body (discard_fold_frame), so an element
whose bind failed kept status 2 under -c and inside eval where GNU
gives 1. Both harvests now fold on
discard_fold_frame() || in_parse_and_execute_frame(), the condition
param_assign_discard_status already used. Compound-stage harvests are
unchanged (GNU does not fold compound elements). Function-element
shape verified against the oracle (file 2, -c 2->1); the inline
echo/printf slot route keeps its own status assembly and is reported
as a residual in the cluster report.

Verified: issue1597 stem unchanged at 9/14 (only the five PIN-wrong rc
pins red); guards issue1318/issue1542/issue1563/issue2369/issue2439/
issue720 green.
Captain pin repair on top of the #2527/#2528 fixes. The five
simple-command pins asserted rc=2, the script-file value: GNU
pre-sets EX_BADUSAGE (subst.c:8164) and the reader_loop preserves
it (eval.c:111-118), but this harness runs -c, whose
parse_and_execute catch (builtins/evalstring.c:423-450) folds it
to 1. The product matches GNU in both modes (oracle matrix in the
W5 investigation); the pins now assert the -c values, the header
documents the split, and the pipeline pin carries a note tying
its ps=2 to the inline slot-route fold residual (#2556).
@caomengxuan666

Copy link
Copy Markdown
Member Author

[win-acceptance] #2554 PASS — new pin issue1597_at_star_assignment_bad_subscript 14/14 ×2 on Windows. Combined issue-repro A/B vs WSL GNU 5.3.20 (script files) also byte-identical: #2527 operator-arm single-fetch face a=(one two three); index=1; echo ${a[index++]:-fallback} → v=[two] index=2 (subscript side effect evaluated exactly once) and #2528 minimal echo ${never_set_xyz[@]:=dv} → diagnostic never_set_xyz[@]: bad array subscript + rc2=2 (EX_BADUSAGE, was 1). Probes: D:/repo/win-accept/wave3/probes/p2527.*. No BLOCKER.

Environment: Windows 10 19045 real machine, MSVC Rust debug build of master b41e8b6 (contains this merge), oracle wsl /usr/local/bin/bash 5.3.20. Logs: D:/repo/win-accept/wave3/logs/issue1597_at_star_assignment_bad_subscript.r{1,2}.log.

caomengxuan666 added a commit that referenced this pull request Nov 2, 2026
…#2556)

The stage gates in execute_pipeline_stage_inner return the
parameter-expansion gate's status unfolded: a := bad-subscript bind
(EX_BADUSAGE 2, subst.c:8164) in a pipeline element's own words kept
2 under -c and inside eval, where GNU's parse_and_execute catch
folds the DISCARD to EXECUTION_FAILURE (builtins/evalstring.c:423-450;
the script reader_loop, eval.c:111-118, preserves 2). The gate
returns before the stage runs, so the stage wrapper's latch tail —
which already folds this bind class through
param_assign_discard_status — never sees it. Fold status 2 through
that same function at both gates (word + heredoc/here-string); other
gate statuses are frame-independent and untouched. Oracle-verified
across inline, builtin, and external routes: file 2 / -c 1.

The issue1597 pipeline pin flips ps=2 to ps=1 in the same commit:
its harness runs -c, so 1 is the GNU value there (the five
simple-command rc pins keep their file-mode values; their -c
correction rides with PR #2554).
caomengxuan666 added a commit that referenced this pull request Nov 2, 2026
…#2556)

The stage gates in execute_pipeline_stage_inner return the
parameter-expansion gate's status unfolded: a := bad-subscript bind
(EX_BADUSAGE 2, subst.c:8164) in a pipeline element's own words kept
2 under -c and inside eval, where GNU's parse_and_execute catch
folds the DISCARD to EXECUTION_FAILURE (builtins/evalstring.c:423-450;
the script reader_loop, eval.c:111-118, preserves 2). The gate
returns before the stage runs, so the stage wrapper's latch tail —
which already folds this bind class through
param_assign_discard_status — never sees it. Fold status 2 through
that same function at both gates (word + heredoc/here-string); other
gate statuses are frame-independent and untouched. Oracle-verified
across inline, builtin, and external routes: file 2 / -c 1.

The issue1597 pipeline pin flips ps=2 to ps=1 in the same commit:
its harness runs -c, so 1 is the GNU value there (the five
simple-command rc pins keep their file-mode values; their -c
correction rides with PR #2554).
@caomengxuan666
caomengxuan666 deleted the fix/2527-single-fetch branch November 3, 2026 09:06
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