Repository navigation
fix(arith): stamp diagnostics with production-time this_command_name - #3871
Merged
Merged
Conversation
…(Refs #3295) GNU labels arithmetic diagnostics with this_command_name as it stands when the diagnostic is produced (builtins/common.c:85-97 builtin_error_prolog, expr.c:1526-1537 evalerror): execute_arith_command sets "((" for the whole entry including expansion (execute_cmd.c:3903/3931), arith-for :3204/:3231, execute_cond_command "[[" :4164, and parameter_brace_expand sets the parameter name for the ${var:off:len} window (subst.c:9372-9377). The nested windows clear it: arithsub evalexp runs under NULL (subst.c:10871-10878) and array_expand_index likewise (arrayfunc.c:1373-1377). Rubash deferred rendering: ARITH_EVAL_EVENTS accumulated diagnostics and the enclosing boundary stamped one drain-time label, so expansion- time diagnostics inside an outer (( )) inherited "((:". Diagnostics produced inside nested $((...)) or array subscripts must be unlabelled, and ${var:off:len} evalexp must carry the parameter name. Mirror the GNU windows with a thread-local label slot: - ArithEvalEvent::Diag now stores the label captured at record time; drain_arith_eval_events() renders each event's own label. - arith_eval_label_scope installs/restores the label for a lexical evaluation scope (the Rust analogue of GNU's save/restore pairs). - eval_arithmetic_command_value_with_flags scopes the entry label (( / let / unlabeled) over expansion+eval; eval_arithmetic_expansion_ value_window clears it for arithsub (null_window) and inherits it for the substring evalexp via eval_arithmetic_expansion_value_inherit_label. - array_expand_index-shaped call sites (subscript expansion, assign/declare/test/printf index resolution, [[ ]] operands) wrap their evalexp in a NULL scope; conditional.rs wraps [[ operands in Some("[["); parameter_core substring offset/length evaluators scope Some(var_name) per subst.c:9372-9378. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
caomengxuan666
added a commit
that referenced
this pull request
Nov 18, 2026
… the scan can own (Refs #3864) ## Summary Refs #3864. PR #3855 added a `braced_name_is_bad_substitution(inner)` check to the `parameter_expansion_error_in_word_context` pre-scan so a bad substitution inside a ` :?` message word surfaces as the inner error (rubash#3502: `${v:?${-x}}` prints only `${-x}: bad substitution`). The check judges the whole `${...}` inner as a braced name and reports the scan's whole word with status 1 — but the scan may only emit that verdict when it coincides with what the real expansion would report. Where it does not, the scan pre-empts the correct diagnostic: - Compound assignment values (issue3500, whole stem): GNU expands elements individually (`arrayfunc.c:557 expand_compound_array_assignment`) and the diagnostic names the element word (`\\[0\\]=${-x}`); the scan names the raw parenthesised value. - `$'name'` extquote names (issue2650): `subst.c:7583 valid_brace_expansion_word` judges the extracted NAME; the real expansion decodes `$'x1'` to `x1` in a quoted context, where the gate on the raw literal misjudges it. - POSIX fatal class (audit B4-F08): `subst.c:10285-10288` makes a bad substitution FORCE_EOF when POSIX + non-interactive + compat > 43; the scan's status 1 downgrades it to DISCARD. The funsub faces (issue2763/issue2761/issue3092/issue3823, golden_funsub_valsub, the arithmetic-for CLI case) are already fixed by #3869, which exempts funsub bodies at the top of this same scan loop; this PR does not touch that exemption. ## Repair The gate now fires only when the scan's verdict coincides with the real expansion's: it defers (returns nothing, letting the real expansion report) when any of these holds — 1. the scanned word is (or contains) a compound assignment value (parser compound marker, or a leading `(`): GNU's diagnostic is per-element, which the scan's whole-word display cannot name; 2. the span's name head is a `$'...'` literal that `resolve_dollar_quoted_parameter_name` decodes: the gate must judge the decoded name; 3. the POSIX-fatal predicate holds (POSIX mode, non-interactive, `compatibility_level > 43`, mirroring the fatal arm in `command_execute.rs`): the scan's status 1 cannot express FORCE_EOF. Everything else is unchanged: the gate still fires for bare bad names (`${-x}`, `${}`, `${(M)y}`), still pre-empts a later `:?` error left-to-right, and still fires inside `:?`/`:-` operator-word recursions — so all seven #3502 pins and the #3869 funsub pins keep passing by construction. ## What this PR removes Nothing from the product surface: the #3855 gate check stays; only its three over-broad firing slices are deferred to the real expansion. No new diagnostic text, no new error class. ## Validation **UNVERIFIED-BY-CAPTAIN** — no build or test was executed in this lane: the build chain is down (X299 tunnel refused, Simular box wallet empty, local build banned: MemAvailable ~503M, below the 1.5G gate). `cargo test` / `cargo check` / lib+base alignment / `RUSTFLAGS="-D warnings"` check are all parked; the captain re-runs the head census after the chain recovers. - New nails `tests/issue3864_parameter_errors_regression.rs` (11 tests): issue3500 element words (indexed/assoc/nested/valid guard), issue2650 extquote top-level + bare forms, POSIX fatal + compat43 guard, funsub-valsub shapes, #3502 inner-only + pin-7 ordering guards. Written fail-first, before the repair; fail-first is by code analysis, not execution (see above). - GNU oracle probes (local `/bin/bash` 5.2.21; stems already carry 5.3.20 verification): `"[${$'x1'}]"` -> `[hello]`; `a=([0]=${-x})` -> `\\[0\\]=${-x}: bad substitution` rc 1; POSIX `echo ${}` -> fatal, no ALIVE, rc 1; `${v:?${-x}}` -> only `${-x}: bad substitution` rc 1. - `rustfmt --check` clean on both touched files. - Evaluation note: reverting #3855 outright was considered and rejected — it would reopen #3502 (7 pins). The scoped repair keeps #3502 green while clearing the mechanically attributable clusters. Three singles in #3864 (issue2029, issue2771, issue2761 x2) have no `${` span in their scripts that can trip the gate, so no `parameter_errors.rs` change can clear them; they are recorded in the lane REPORT as unattributed (likely census flakes / other-window commits) for the captain's census re-run to confirm. ## Captain review (PASS, merged) Original head 19159b6, captain-extracted from its CI logs: census total 79 (era baseline), issue3500 19/19, own pins issue3864 11/11, goldens exactly the two baseline names; the darwin leg was cancelled with zero steps (never ran, not a red). Merge-shape head 0a73b4f (update-branch over master 0863639; the only master-side touch of parameter_errors.rs since the merge-base was PR #3871's +6/-2 arith-label hunk near line 1417, ~1000 lines from this PR's hunks), captain-extracted: - issue3500 19/19 PASS, issue3864 11/11 PASS, issue2650 10/10, issue2763 6/6, issue201 2/2, issue2771 5/5, audit stems 40/40. - Census total 81, goldens exactly the two baseline names. - Two non-blocking cells, both adjudicated churn: the CLI leg's sole failure is c_command_keeps_named_coproc_output_fds_distinct (2 PASS / 2 FAIL across four era heads, uncorrelated with any diff), and census cell issue2029 head_pipe_fold_leaves_the_remainder is FAIL here but PASS on both the original head and on PR #3870's head (which carries #3855 without this fix) — not owned by this change. Fail-first basis (stated honestly): the lane's 11 pins were written pre-fix but not executed pre-fix (no build route); their fail-first rests on code analysis, corroborated by the tip census showing the same shapes red before this PR and green after. What this removes: the unscoped #3855 gate call in parameter_expansion_error_in_word_context — the scan emitted whole-word status-1 verdicts for compound values, $'...' name heads and the POSIX-fatal class. It is replaced by the deferral-aware gate; each deferral restores the pre-#3855 behavior for that slice. No other behavior is deleted.
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
Fixes #3295 — arithmetic diagnostics produced while expanding inside arithmetic text were mislabeled with the
((:entry tag; GNU labels each diagnostic withthis_command_nameas it stands at production time (builtins/common.c:85-97builtin_error_prolog, expr.c:1526-1537evalerror).execute_arith_commandsetsthis_command_name = "(("for the whole entry including expansion (execute_cmd.c:3903/3931); arith-for :3204/:3231;execute_cond_command"[[":4164;parameter_brace_expandsets the parameter name for the${var:off:len}window (subst.c:9372-9377).array_expand_indexlikewise (arrayfunc.c:1373-1377).Rubash accumulated
ARITH_EVAL_EVENTSand stamped one drain-time label at the boundary, so expansion-time diagnostics inside an outer(( ))inherited((:. This PR mirrors GNU's save/restore windows:ArithEvalEvent::Diagnow carries the label captured at record time;drain_arith_eval_events()renders each event's own label.arith_eval_label_scopeguard installs/restores the label per lexical evaluation scope.((/let/unlabeled command eval,[[operands (Some("[["),${var:off:len}offset/length evalexp (Some(var_name)via neweval_arithmetic_expansion_value_inherit_label).$((...))and legacy$[...]),array_expand_index-shaped call sites (indexed/assoc subscript expansion, declare/printf/test index resolution, arith-for probe in parameter_errors, in-parser subscript/$(( ))nesting in arithmetic/value.rs).Test plan (measured on head
9bf6779e7vs merge-base5f6fb632e)tests/issue3295_arith_diag_entry_label.rs,#![cfg(unix)]) on WSL Linux rustc 1.99.0: head 6/6 PASS; base 3/6 with red = {s4, s6, s7} — fail-first exact./usr/local/bin/bash) vs rubash stderr/stdout/rc on 15 probe scripts covering all six pin shapes plus neighbors (nested$(( )), array subscripts,${v:off:len}arithmetic,$[...], unary/binary diagnostics): all identical after path-prefix normalization; the only residual is s4's unix-onlysetlocale: LC_ALLwarning leg (Windows host cannot emit it).cargo test --test cli_tests: head 468 passed / 15 failed / 3 ignored; base 468/15/3 — identical 15-name failure set (all environmental: examplesNotADirectoryspawn, path-prefix, login-startup noise,type -t, fd-redirect, one timeout). Delta = ∅.cargo test --test regression golden_: head 35/12; base 35/12 — identical failure set. Delta = ∅.cargo test --lib: head 1376 passed / 1 failed / 4 ignored; base identical — sole failureapi::consumer_tests::issue2084_session_end_restores_host_process_state, known baseline.RUSTFLAGS="-D warnings" cargo check --lib --bins: clean, 0 warnings.rustfmt --checkon all 15 touched files: clean;scripts/check-marker-literals.py: OK;check-utf8-boundary-hygiene.sh: clean.Known adjacent residuals (not this PR)
$( (( expr )) )inside arithmetic-expression expansion: the&selfcomsub path strips((...))as wrapping subshell groups (strip_wrapping_subshell_group), so the inner arithmetic command never dispatches — diagnostics come out unlabelled and status diverges (n4/n4b probes). Different root cause (comsub body stripping, not label stamping); needs its own issue.Generated with Devin