Repository navigation
fix(executor): nounset scan sees :=/= binds in left-to-right order (Refs unixwin/niubash#993 §1) - #3710
Merged
Conversation
…(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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
set -u,echo "a=${X:=v} b=$X"aborted withX: unbound variable; GNU expands one left-to-right walk andparameter_brace_expand_rhs(subst.c:7966) binds=/:=fragments as it reaches them.:?adjudication; the plain nounset walk (nounset_unbound_parameter->nounset_braced_parameter_is_unbound) never consulted it. Both nounset walks now record each:=/=fragment viascan_record_assignment, and boundness verdicts (nounset_variable_bound, array-element arms, nameref target, operator-word subject) answer from the simulated table first.[[ =~ ]]operand scan begin a fresh context —"${X:?boom}" "${X:=v}"still reportsX: boom.GNU anchors
subst.c:13219expand_word_list_internal (per-word in-order driver)subst.c:7966parameter_brace_expand_rhs (=/:=binds as it goes)subst.c:10170-10180unbound check per fragmentsubst.c:7787-7790/variables.celement-0 scalar read (${a[0]:=el}->$abound)Verification
$( )/ nested operators x spacing, plus control cells (:-non-binding, colon-less=non-rebind,:?-first fires).tests/niubash993_nounset_assign_visibility.rs: 17/17 green.Generated with Devin