Skip to content

WIP: fix(builtin-diag): declare -p conversion, printf 0-flag, arith subscript diag, nested :? (Refs #2335, #2336, #2341, #2343) - #2363

Merged
caomengxuan666 merged 6 commits into
masterfrom
fix/r2-builtin-diag
Oct 31, 2026
Merged

caomengxuan666 merged 6 commits into
masterfrom
fix/r2-builtin-diag

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Cluster R2 — builtin/expansion diagnostics family. Four independent fixes, one commit per issue, Refs-only (issues stay open for the collector):

All expectations probed byte-for-byte against GNU bash 5.3.20 with script files; regression pins per issue included per commit. Local verification: cargo check only (compile rationing) — CI compiles and runs the pins.

…2335)

GNU declare_builtin takes the pflag branch before all making-variables
machinery (builtins/declare.def:389 declare_builtin): with -p, operands
go straight to show_name_attributes, so a type flag riding along on the
query never converts or validates. rubash ran its conversion pre-pass
unconditionally, so `declare -p -A a` on an indexed array errored
"cannot convert indexed to associative array" and printed nothing.
The pre-pass now passes -p operands through untouched (no conversion
rejection, no nameref transformation), matching the display-only law
the neighboring readonly gate already states.

Regression pins: tests/issue2335_declare_p_conversion_regressions.rs
(GNU bash 5.3.20 script-file expectations, incl. the control that
conversion without -p still fails).
The '0' flag is defined only for numeric conversions. GNU hands
%s/%c to libc printf via the PF macro (builtins/printf.def), where
glibc ignores '0' for non-numeric conversions and pads with spaces,
and routes %b/%q/%Q through printstr (printf.def:861 printstr), which
honors only '-' among the flags. rubash's width application applied
zero padding to every conversion, printing `000hi` for `%05s`.
format_value's width_spec adjustments now clear zero_pad for
s/S/c/C/b/q/Q, beside the existing precision/nonfinite clearances;
numeric zero padding is unchanged.

Regression pins: tests/issue2336_printf_zero_flag_string_regressions.rs
(GNU bash 5.3.20 expectations, incl. space/plus flag combinations and
the %c NUL byte case).
…#2341)

GNU's arithmetic assignment of an indexed element whose negative
subscript stays negative after the count-back-from-end wrap fails in
assign_array_element_internal (arrayfunc.c:425-435) with
err_badarraysub(name) (error.c:440) on the full lvalue token as
written -- `a[0-4]` and `a[i]` report their source text -- and stores
nothing. rubash's set_array_element silently dropped the element, so
`(( a[-4] = 9 ))` said nothing at all and `+=`/`++` forms lacked the
second (bind) line next to the read side's bare-name INDEX_ERROR line.

ArithLValue::Indexed now carries bind_display (the name[sub] token
text, the AssocEmptyKey precedent), and set_array_element records
ArithEvalDiag::BadSubscript(bind_display) when the wrap fails to
resolve. The read side is untouched.

Regression pins: tests/issue2341_negative_subscript_arith_assign_regressions.rs
(GNU bash 5.3.20 script-file expectations: = / += / ++ / let forms,
expression and variable subscripts, unset array, in-range controls).
… stays fatal (Refs #2343)

GNU evaluates an operator's word exactly when the operator selects
it, and a :? failure inside that word is fatal and reported for the
innermost variable: parameter_brace_expand_error (subst.c:8216)
expands the message word via expand_string before reporting, so
`${a:?${b:?inner}}` prints `b: inner` and the outer report never
runs; parameter_brace_expand_rhs does the same for the -/+/= words,
so `${a:-${b:?inner}}` aborts instead of yielding "inner" as a value.

The word pre-scan now mirrors that evaluation order: when a :? fires,
its message word is scanned first and a nested verdict pre-empts the
outer one; a new nested_operator_word_error descends into the word of
a -/:-/+/:/:=/= span whenever the operator selects it (operator
identified by the first split whose left side is a valid parameter
reference). Unevaluated words and command-substitution bodies stay
silent/contained, as before.

Regression pins: tests/issue2343_nested_parameter_error_regressions.rs
(GNU bash 5.3.20 script-file expectations: message nesting, default/
assign/alternate selection, lazy-word and comsub containment controls).
…(Refs #2341)

The #2341 bind diagnostic renders the lvalue token as written (GNU
assign_array_element_internal -> err_badarraysub on the token,
arrayfunc.c:425-435; evalerror echoes the expression as written,
expr.c:1526-1535). On the EXP_EXPANDED entries (let, [[) the parser
input is not source text: expand_arith_indexed_subscripts rewrote
a[-4] to a[<0x1e>2d34] (SUBSCRIPT_CARRIER + hex of the subscript
text), and the bind displays built from that input (lvalue.rs
compound bind_display, value.rs resolve_raw_subscript) carried the
encoding into ArithEvalDiag::BadSubscript, which flush_arith_diags
printed verbatim — let "a[-4] = 9" reported a[<0x1e>2d34]. The (( ))
entry never encodes indexed subscripts, so it rendered clean.

Fix at the single rendering point: flush_arith_diags now runs both
diag payloads through parser::de_carrier_arith_text (the #1602
decoder, widened to pub(super)), so no producer — plain or compound
bind, read or bind side, let or (( — can leak the carrier form.
Probe parity vs GNU 5.3.20 (script files): let a[-4]=9, a[-4]+=9,
a[0-4]=9, a[i]=9 (i=-4) all byte-identical. Pins: issue2341 4/4,
issue2335 3/3, issue2336 4/4, issue2343 5/5 (scrubbed-fd runner).
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