You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
declare -a a=( [-2]=q ) / local -a a=( [-2]=q ) still drop an out-of-range negative subscript (builtin route of #631) #635
The same out-of-range negative subscript that #631 fixes on the assignment
route is still dropped in silence on the builtin route:
$ bash -c 'declare -a a=( [-2]=q ); echo AFTER; declare -p a'bash: line 1: [-2]=q: bad array subscript
$ echo$?1 # no AFTER — the run ends
$ ./rubash -c 'declare -a a=( [-2]=q ); echo AFTER; declare -p a'AFTERdeclare -a a=()
$ echo$?0 # element dropped in silence
Same for local and typeset inside a function:
$ bash -c 'f(){ local -a a=( [-2]=q ); echo IN; }; f; echo AFTER'bash: line 1: [-2]=q: bad array subscript
$ ./rubash -c 'f(){ local -a a=( [-2]=q ); echo IN; }; f; echo AFTER'INAFTER
Also declare -a a; a+=( [-2]=q ).
GNU (the spec)
assign_compound_array_list (third_party/bash/arrayfunc.c:700) computes the
element subscript, counts a negative one back from the end
(array_max_index + 1 + ind, arrayfunc.c:802-803) and, when it is still
below zero, reports err_badarraysub (w) — the whole element word, through report_error (error.c:440; message arrayfunc.c:63) — counts any_failed
and breaks the list (arrayfunc.c:804-809). assign_array_var_from_string
(arrayfunc.c:913-932) then returns NULL, so the assignment fails: bash_variable_assignment_error (subst.c:11169) → exp_jump_to_top_level (DISCARD) (subst.c:11174). The elements inserted before the failing one stay
stored.
Both the assignment route and the builtin route reach the GNU builtin through
the same function, so both must behave identically.
Root cause
src/builtins/declare/storage/array.rs:239 array_assignment_index is a second
implementation of the same resolver, and it has the identical defect fixed for
the executor copy in #631: it returns Option<usize>, so "not a [subscript]
header" and "this subscript resolved out of range" are conflated. The call
sites (:106, :129, :135, :147) then continue via array_assignment_has_subscript(left) and the element vanishes.
The declare-side scan returns Result<String, String> into the declare builtin,
which holds a plain variables map and has no Executor handle, so it
cannot arm the fatal DISCARD jump that the assignment route uses
(raise_evalerror_abort). Fixing it means giving the builtin its own fatal
error channel (a new error variant threaded through the declare/local/ typeset call sites), which is a different design change from #631's ArrayAssignmentIndex fix.
Activity
docs: record the #631 resolution and its sibling divergences
fix(executor): report a bad array subscript in a compound assignment (#…
fix(executor): reject [@]/[*] in compound assignment before arith eval (
fix(executor): contain the assignment DISCARD jump at the eval bounda…
caomengxuan666 commentedon Oct 16, 2026
Fix is up as PR #658 (branch
fix/issue635-builtin-oobond4d8dc4). 3-state resolver + break-with-partial + out-param word chain + Executor-layer abort mirroring the arith_eval_failure precedent; eval containment reuses #637's primitive. Battery 6/20 -> 20/20. Regression filetests/issue635_builtin_oob.rs(10 tests). export/readonly list-abort threading left as documented follow-up.fix(builtins): abort declare/local on out-of-range negative subscripts (
caomengxuan666 commentedon Oct 16, 2026
Landed as #658 (squash-merged 287fbe7). Battery 6/20 -> 20/20. export/readonly list-abort threading left as documented follow-up.
caomengxuan666 commentedon Oct 16, 2026
Export/readonly follow-up cut as PR #677 (branch
fix/issue635-export-abort): mirrors #658 (oob_word threading, operand-loop stop, bare diagnostic, #637 abort). 13 new tests; 18/18 GNU probe matrix. Gate running.fix(executor): thread the list-abort through export/readonly OOB (#635)…
docs: changelog entries for #635-export (#677) and #667 fd race (#676)
fix(executor): consume the arithmetic fatal flag at the triggering co…