Skip to content

fix(executor): nounset scan sees :=/= binds in left-to-right order (Refs unixwin/niubash#993 §1) - #3710

Merged
caomengxuan666 merged 1 commit into
masterfrom
fix/993-1
Nov 15, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
fix/993-1

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Summary

  • Under set -u, echo "a=${X:=v} b=$X" aborted with X: unbound variable; GNU expands one left-to-right walk and parameter_brace_expand_rhs (subst.c:7966) binds =/:= fragments as it reaches them.
  • The rubash#2762 simulated-binding table fed only the :? adjudication; the plain nounset walk (nounset_unbound_parameter -> nounset_braced_parameter_is_unbound) never consulted it. Both nounset walks now record each :=/= fragment via scan_record_assignment, and boundness verdicts (nounset_variable_bound, array-element arms, nameref target, operator-word subject) answer from the simulated table first.
  • Ordering stays strictly left-to-right: word-context nounset records are private to that pass (snapshot/restore), the command pre-scan clears the table between its nounset pass and the per-word error walk, and the admission probe + [[ =~ ]] operand scan begin a fresh context — "${X:?boom}" "${X:=v}" still reports X: boom.

GNU anchors

  • subst.c:13219 expand_word_list_internal (per-word in-order driver)
  • subst.c:7966 parameter_brace_expand_rhs (=/:= binds as it goes)
  • subst.c:10170-10180 unbound check per fragment
  • subst.c:7787-7790 / variables.c element-0 scalar read (${a[0]:=el} -> $a bound)

Verification

  • 36-case diff matrix vs WSL GNU bash 5.3.20 (script files): byte-identical — argument / assignment-RHS x literal / variable / $( ) / nested operators x spacing, plus control cells (:- non-binding, colon-less = non-rebind, :?-first fires).
  • tests/niubash993_nounset_assign_visibility.rs: 17/17 green.
  • Nounset regression suites (issue319/535/638/639/705/1130/1709/1915/1930/2486/2762/3199/3200/3251/3429/3454/3540-3541): all green except 4 failures reproduced identically on clean master — issue1915 redirect-word containment, issue1930 script-path prefix, issue3429 x2, lib issue2084 env journaling (baseline reds, not from this change).

Generated with Devin

…(Refs unixwin/niubash#993 §1)

Under `set -u`, `echo "a=${X:=v} b=$X"` died with `X: unbound variable`:
the nounset pre-scan judged every `$name` against the pre-command
environment, while GNU's single expansion walk binds each `=`/`:=`
fragment as it reaches it (subst.c:13219 expand_word_list_internal ->
subst.c:11229 expand_word_internal -> subst.c:7966
parameter_brace_expand_rhs; the unbound check at subst.c:10170-10180
runs per fragment against the evolved state).

The rubash#2762 simulated-binding table already modeled this for the
`:?` adjudication; the plain nounset walk never consulted it. Now both
nounset walks (nounset_unbound_parameter and its _with_comsubs twin)
record each `:=`/`=` fragment they pass via scan_record_assignment, and
the boundness verdicts (nounset_variable_bound, the array-element arms,
the nameref target arm, the operator-word subject test) answer from the
simulated table first. Ordering stays strictly left-to-right: the
word-context nounset pass keeps its records private to itself
(scan_sim_snapshot/restore) so the `${...}` error walk re-records every
fragment in order; the simple-command pre-scan clears the table between
its nounset pass and the per-word error walk; the pipeline-admission
probe and the `[[ =~ ]]` operand scan begin a fresh context.

Set-unknown simulations settle the `:`-less operator-word tests
outright; colon forms scan nothing on an inexact simulation (a false
skip heals at the real expansion, a false scan is a fatal GNU never
raises). `${a[0]:=el}` binds the element for both `${a[0]}` and the
bare `$a` scalar read.

Verified: 36-case diff matrix vs WSL GNU bash 5.3.20 byte-identical
(argument/assignment-RHS x literal/variable/substitution x spacing);
new tests/niubash993_nounset_assign_visibility.rs 17/17; nounset
regression suites green except four failures that reproduce identically
on clean master (issue1915 redirect-word containment, issue1930 path
prefix, issue3429 x2, lib issue2084 env journaling).

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

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@caomengxuan666
caomengxuan666 merged commit d6e4ade into master Nov 15, 2026
7 of 11 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/993-1 branch November 15, 2026 17:04
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