Repository navigation
WIP: fix nounset pre-scans judging procsub bodies (#1915) - #1929
Merged
Merged
Conversation
…1915) Under `set -u`, `mapfile -t x < <(printf '10\n' | awk '$1 == 10 {print $1}')` died with `$1: unbound variable`: the parent-side nounset pre-scans walked into `<( ... )` / `>( ... )` span text and judged the body's single-quoted `$1` as a live parent reference. GNU never expands a procsub body in the parent: expand_word_internal (subst.c:11366-11385) extracts it verbatim via extract_process_subst (subst.c:1311) and process_substitute (subst.c:6362) hands it to the child shell, whose own parse owns every `$` inside. Fix by mechanism: the pre-scans (simple-command words/assignments in parameter_expansion_error and its pipeline twin, plus the redirect-target gate in redirection.rs) now mask out exactly the process-substitution spans the parser recorded for the command (verbatim child text) before judging. Look-alike `<(...)`-shaped text that is not a recorded span — e.g. inside double quotes, where `$` stays a live parent reference — is still judged in full, and arithmetic text (no spans recorded there) is untouched. Regression tests: tests/issue1915_procsub_nounset_regressions.rs (17 tests, GNU 5.3.20 expectations).
…#1915) The t7 residual of #1915: the simple-command pre-scans masked a command's recorded process-substitution spans, but the [[ ]] operand scans judged the raw word, so [[ -n <(awk '$1' <<< '10') ]] under set -u still died with '$1: unbound variable'. GNU cond_expand_word (cond.c) expands operands through expand_word (subst.c:11229), whose '<'/'>' cases extract the span verbatim (subst.c:1311 extract_process_subst) for process_substitute (subst.c:6362) — the parent never judges the body on this face either. Thread the records the parser already made: ConditionalCommand carries arg_metadata aligned with args, each WordMetadata holding the word's recorded process_substitutions. execute_conditional_command publishes (operand text -> recorded span targets) into Executor::conditional_procsub_span_targets (save/restore), and the two conditional nounset scan points — expand_conditional_word's expansion-error scan and regex_operands_nounset_fatal — mask exactly the spans recorded for the word under scan via the shared mask_recorded_span_targets core. The criterion is unchanged (only parser-recorded child text is masked): a quoted look-alike span in a sibling operand was never recorded for that word, so its $ stays a live parent reference and still fires. No scan predicate, no conditional expansion code changes. Verification (this commit, base master 4987def): regression target 23/23 (6 new conditional pins, GNU 5.3.20 byte-checked expectations); lib 899/1/3 identical to the pristine baseline failure set; diffcorpus 306/306; -D warnings clean; per-file rustfmt clean; CR 0. The differential matrix (original 34 shapes + the t7 group) is byte-SAME except three t7 shapes whose remaining delta is a different, pre-existing mechanism (conditional operands are not materialized to /dev/fd values), recorded in the cluster REPORT S7.
caomengxuan666
force-pushed
the
fix/1915-procsub-setu
branch
from
October 28, 2026 07:43
c4e6baf to
9962fbf
Compare
caomengxuan666
marked this pull request as ready for review
October 28, 2026 07:49
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.
Refs #1915
Under
set -u,mapfile -t x < <(printf '10\n' | awk '$1 == 10 {print $1}')died with$1: unbound variable: the parent-side nounset pre-scans walked into<(...)/>(...)span text and judged the body's single-quoted$1as a live parent reference.GNU never expands a procsub body in the parent: expand_word_internal (subst.c:11366-11385) extracts it verbatim via extract_process_subst (subst.c:1311) and process_substitute (subst.c:6362) hands it to the child shell, whose own parse owns every
$inside.Fix by mechanism: the pre-scans (simple-command words/assignments in
parameter_expansion_errorand its pipeline twin, plus the redirect-target gate inredirection.rs) now mask out exactly the process-substitution spans the parser recorded for the command (verbatim child text) before judging. Look-alike<(...)-shaped text that is not a recorded span — e.g. inside double quotes, where$stays a live parent reference — is still judged in full, and arithmetic text (no spans recorded there) is untouched.Verification (base master 4987def after rebase, heads a4f14dd + 9962fbf):
tests/issue1915_procsub_nounset_regressions.rs: 17/17 pass.cargo test --lib: 899 passed / 1 failed (ownership_unary_operators_check_existing_file, pre-existing on master) / 3 ignored — zero new reds.cargo checkwith-D warningsclean; per-file rustfmt clean; CR count 0.File overlap with perf-f6 (read path): none — this change touches only
src/executor/parameter_errors.rsandsrc/executor/redirection.rs(gate call site).t7 follow-up: the
[[ ]]operand scans (second commit, 9962fbf)The residual recorded in the cluster report:
set -u; [[ -n <(awk '$1' <<< '10') ]]still died with$1: unbound variable— the conditional operand scans are different scan points from the simple-command pre-scan and held no span records. GNU expands[[ ]]operands through cond_expand_word (cond.c) -> expand_word, whose '<'/'>' cases extract the span verbatim exactly as for simple words, so the parent never judges the body on this face either.The parser had the records all along:
ConditionalCommand.arg_metadatais aligned withargs, and eachWordMetadatacarries that word's recordedprocess_substitutions.execute_conditional_commandnow publishes (operand text -> recorded span targets) intoExecutor::conditional_procsub_span_targets(save/restore), and the two conditional nounset scan points —expand_conditional_word's expansion-error scan andregex_operands_nounset_fatal— mask exactly the spans recorded for the word under scan through the sharedmask_recorded_span_targetscore (split out ofmask_recorded_process_substitutions; the simple-command behavior is unchanged). Lookup is by the word's exact text, so the q3 precision holds on this face:[[ -n "<(awk '$NOPE')" ]]and[[ "<(awk '$NOPE')" == <(awk '$NOPE') ]]still raise the GNU fatal.Verification (second commit): regression target 23/23 (6 new conditional pins: span operands for -n/-z/
>(...)/=~RHS pass; bare/quoted/=~-side unbound guards and the beside-a-span guards keep their fatals); lib 899/1/3, failure set identical to the pristine baseline; diffcorpus 306/306;-D warningsclean; per-file rustfmt clean; CR 0.Recorded residuals (different pre-existing mechanisms, NOT nounset scans — see cluster REPORT section 7): on the
[[ ]]face a procsub span used as a comparison VALUE is not materialized to its /dev/fd string (the operand text compares literally), which leaves an observable delta for span subjects of==/=~and for the child-side diagnostic of a body like<(awk "$1" ...); and the conditional parser rejects any suffix after a word-initial span (<(...)x). The nounset dimension of all three shapes is fixed by this PR (no parent fatal, script continues, script rc matches GNU).