Repository navigation
fix6 expand-param slice: substring/positional/array-operator/eager-binding expansion fixes (#1588, #1597, #1598, #1600, #1601) - #1701
Conversation
…sh#1600) The substring error pre-scan rejected a negative length whenever the parameter NAME ended in [@]/[*], but GNU get_var_and_type (subst.c, parameter_brace_substring) classifies the operand by the base variable's TYPE: a scalar base is VT_VARIABLE, so verify_substring_values (subst.c:8395) adjusts the negative length by the string length exactly like the bare-name form. Only VT_POSPARMS (@/*) and a real array base (VT_ARRAYVAR) error unconditionally, and an unset base or an element-less array takes the early NULL return and never errors. - parameter_errors.rs: the pre-check now branches on the operand's actual kind (posparms / array variable with elements / scalar rule over the base's own value / unset = silent). - array_subscript_range_values now takes the signed length (Option<isize>): the scalar branch consumes it directly (the string slice GNU applies, subst.c:9083-9099), the array branches keep treating a negative length as "no length" (that case is the scan's error). All call sites pass the length through instead of dropping it via usize::try_from; the two compound-assignment slice arms route scalar bases through the same helper. Regression tests: tests/issue1600_scalar_at_substring_negative_length.rs (10 tests, expectations verified against GNU bash 5.3.20).
…bash#1601)
`${@: -3:2}` with two parameters returned empty: the slice resolved
negative offsets against the real parameters only. GNU pos_params
(subst.c:3745) builds the virtual list [$0, $1..$n] for every
${@:...}/${*:...} slice, and verify_substring_values (subst.c:8395)
resolves a negative offset against nargs+1, so $0 occupies virtual
index 0 and a start resolved outside the list is a silent empty
result.
positional_parameter_substring_with_zero now always prepends $0 and
slices the virtual list (the plain helper's convention — offset 1 =
first element, negative counts from the end — matches it exactly
once a non-negative offset is shifted by one). All callers (whole
word, embedded segments, assignment lists) already passed the script
name expecting this model.
Regression tests: tests/issue1601_positional_slice_includes_zero.rs
(8 tests, expectations verified against GNU bash 5.3.20).
…bases (rubash#1597)
Two roots in the gen-corpus R6 family (~38 cases).
(1) `=`/`:=` through the all-elements spelling on an unset, scalar,
or indexed-array base silently bound nothing. GNU
parameter_brace_expand's `case '='` (subst.c:10346) hands the RHS to
parameter_brace_expand_rhs (subst.c:8096) with the subscript text
still attached, and the bind fails with `name[@]: bad array
subscript`, EX_BADUSAGE (status 2) in every command position; the one
legal base is an associative array, where "@" / "*" is just a key.
- New shared scan bad_array_subscript_assignment_in_word: a
triggered assignment (the operator's own joined-elements null
test) whose [@]/[*] base is not associative reports the class.
Consulted by the simple-command pre-scan
(parameter_assignment_error_in_word) and by the word scan behind
for-list / case / [[ ]] positions
(parameter_expansion_error_in_word_context, status 2).
- The three scan consumers now map "bad array subscript" to status
2 like the readonly class (was 1).
- raise_word_expansion_error: non-FATAL classes all take the
ExpansionFailure (discard-list) vehicle — status 2 previously fell
into the FATAL-shaped ExitCode branch and aborted the whole script
from compound positions.
- Apply-path guard (reject_bad_array_subscript_assignment) for
positions no textual scan covers: prints the diagnostic and
latches the EX_BADUSAGE discard. The assoc case never reaches it —
apply_array_element_parameter_assignment claims it first.
(2) The error operators on a BARE array name read the raw storage
string: an assoc without key "0" or a sparse indexed array without
element 0 wrongly passed `${name:?}`. parameter_error_value's
fallback now reduces an array variable through
scalar_parameter_value (variables.c get_string_value element-0
semantics), matching what shell_variable_value already did for the
main operator arms.
Regression tests: tests/issue1597_at_star_assignment_bad_subscript.rs
(14 tests, expectations verified against GNU bash 5.3.20).
…bash#1598)
In an unquoted whole-word position, the `-`/`:-` result on a
list-valued operand kept its element boundaries: braced_alternate_
word_values returned the elements (or the [*] join) as FINAL fields.
GNU expand_word_internal subjects the unquoted result to field
splitting — each [@] element re-splits on IFS and empty results
vanish, and the [*] joined string splits as one string — exactly
what the plain ${a[@]} path already did via
field_split_array_values_with_ifs (gen-corpus R7, ~35 cases).
The list-operand interception in braced_alternate_word_values now
applies field_split_array_values_with_ifs when the site is unquoted
(was_quoted from the storage prefix), covering command words and
for-list words alike; the quoted form keeps one word per element.
Verified sub-roots: `:=`/`=`/`+` families and the patsub/trim/
case-mod forms already split correctly through the string paths —
only the `-` family interception was wrong.
Regression tests: tests/issue1598_list_operator_result_field_splitting.rs
(9 tests, expectations verified against GNU bash 5.3.20).
…s (rubash#1588)
A `${name:=word}` / `${name=word}` nested in an EAGER secondary
text of another expansion — the leading name's subscript, a
substring's offset/length texts, a patsub's pattern or replacement,
a case-modification or trim pattern, or $((...)) arithmetic text —
produced the right VALUE but the binding was silently dropped: those
texts expand through &self paths (expand_subscript_string,
eval_parameter_substring_offset, the pattern expanders), while
&mut side effects live only in the word pre-scan, which applied a
fragment solely when its OWN top-level operator was `:=`/`=` (the
mirror image of rubash#1564).
- The pre-scan now walks each fragment's eager secondary texts
before its own operator and applies nested fragments recursively
in textual order. Extraction (secondary_assignment_texts) mirrors
the value side's own parsers — split_top_level_colon,
parse_parameter_replacement, parse_parameter_case_mod, the
operator splits — so the apply view cannot drift from the value
view. Operator WORDS are not descended into (#1564 discipline
intact: an unselected word still binds nothing).
- The #1169 freeze now also covers targets bound through secondary
texts, since the pre-scan applies them before the word's real pass.
- Arithmetic entry (expand_arithmetic_expression_mut) runs the
pre-scan over the expression text: the word-level scan treats
$((...)) as a command-substitution frame and skips it, and this is
the one &mut pass arithmetic text goes through. Re-application on
later evaluations is inert (the arms re-test the operator).
Regression tests: tests/issue1588_secondary_text_assignment_binding.rs
(12 tests, expectations verified against GNU bash 5.3.20).
2d95db0 to
838d6ff
Compare
Integration verification (fix6/slice-expand-param)Landed tree: master 2157a3a + the 5 cluster commits (cherry-picked cleanly, no conflicts). All gates run under the build slot, purified env (JARVIS_* stripped),
Master advanced by PR #1670 (history-eng) while this slice waited on the build slot. That delta touches 8 files (history_exec.rs, job_builtins.rs, history.rs, script_driver.rs + 4 history test files) — zero overlap with this slice's 15 files, disjoint semantic domain, and #1670 was itself gated green before merging. The branch was rebased onto 38062f5 conflict-free (new head 838d6ff). Three attempts to re-run the full gate suite on the rebased tree were killed/starved by repeated VM reboots and a 50+-deep build-slot queue; the combined tree will be re-verified post-merge as confirmation and any surprise reported immediately. |
fix6 expand-param slice — parameter-expansion fixes
Five fixes from the fix6 expand-param cluster, one commit each, cherry-picked onto current master (2157a3a). Cluster-level verification before integration: 53/53 new regression tests, lib 771/1/1 (only allowed failure
ownership_unary_operators_check_existing_file), 50-case differential matrix vs GNU bash 5.3.20 went from 36 divergences to 0, gen-corpus fingerprint representatives (29 cases) 0 divergences.${var:off:-len}is classified by operand type: a scalar base under[@]form takes the string-slice adjustment; unset/empty arrays no longer error. The slice helper now threads a signed length end-to-end.${@: -3:2}is no longer empty.=/:=applied to[@]/[*]on a non-assoc base reportsbad array subscriptwith EX_BADUSAGE status 2 consistently in all positions (scan layer + three consumers + raise tail + apply fallback); (2) bare-name:?reduces with element-0 semantics, so an assoc without a "0" key / a sparse array without element 0 no longer passes silently.-/:-family only: list results in unquoted context were missing field splitting; addedfield_split_array_values_with_ifs. Quoted context and the other operator families are untouched.$(( ))text), applying nested binds recursively in text order. The operator WORD itself is not descended into ([bug] 并发管道 spec 推测展开的赋值副作用泄漏进父 env(元素子体隔离缺失) #1564 discipline intact); the [bug] :- sees later := assignment in the same word (eval-order leak) #1169 freeze sync is extended alongside.Fixes #1588
Fixes #1597
Fixes #1598
Fixes #1600
Fixes #1601
Out of scope (reported by the cluster, not fixed here, no new issues filed)
${m[@]}join order: GNU hash order vs rubash insertion order (pre-existing).declare -A m=([k]="")): GNU triggers neither:=nor:-; rubash's joined-null model treats it as empty. The divergence also exists on the pre-existing:-value path; it is outside the gen-corpus fingerprint scope (representative cases were unset/scalar/indexed bases).-cvs script-file exit status for bad subscript (1 vs 2): per repo convention the script-file form is authoritative.Integration verification on the landed tree follows in PR comments; merge only when all gates are green.