Repository navigation
fix(arithmetic): normalize assoc subscripts on the ((...))/let entry (rubash#828) - #839
Conversation
|
CR verdict: REQUEST-CHANGES (1 blocker; independent review of ee8cf9b vs 992d5c5, GNU oracle = WSL bash 5.3.0, own worktree + own binary builds) Verified good
BLOCKER1. New GNU-parity regression on the very entry this PR fixes: a
Same root, second symptom: Fix: track single- and double-quote state in Non-blocking
No merge until the blocker lands; happy to re-review the quote-tracking delta alone. |
…(rubash#828)
The fourth write entry — arithmetic ((...)) assignments and their let
"A[...]=v" form — stored the raw $'...' spelling instead of the decoded
key: ((A[$'x\ty']=1)) kept 24 27 78 5c 74 79 27 where GNU bash 5.3.0
stores 780979 and ${A[$k]} reads [1].
The assoc subscript of an arithmetic expression is expanded once by
expand_arithmetic_assoc_subscripts (arithmetic/mod.rs) before the parser
sees it, and that pass never touched the ANSI-C spans. GNU reaches
expand_subscript_string from this entry with the raw spelling, and the
runtime pass behaves differently per caller:
- ((...))/$((...))/nested-subscript readers: expand_word_internal's
ANSI-C arm decodes the span with the product quoted, so decoded bytes
ride as data and decoded backslashes survive (((D[$'a\\b']=2))
stores 61 5c 62; the ${} reader keeps its pinned write/read
asymmetry).
- let: the operand was word-expanded once (let.def passes EXP_EXPANDED),
so $' is NOT re-recognized as ANSI-C — the $ stays literal data, the
span quotes drop as shell quotes and the raw spelling rides verbatim
(let "B[$'x\ty']=1" stores $x\ty = 24 78 5c 74 79). GNU's own
scrambled-key quirk, pinned as parity.
expand_assoc_subscript_once now rewrites literal $'...' spans per entry
(ArithAnsiSpanMode::Decode / ::LetOperand — transform_arith_ansi_c_spans,
carrier-marked so the embedded walker expands only the text outside the
spans). Bare (non-$') spellings are deliberately untouched: the (( ))
body reaches the evaluator after the lexer's own escape pass, so the
bare-escape product stays as recorded in assoc corpus rows.
Known divergences that stay (probed 2026-10-13, pre-existing on master):
- bare escapes inside arithmetic subscripts keep one more backslash than
GNU (((G[a\\b]=2)) second cell: x\ty vs xty);
- the unset operand that decodes to a stored key still deletes where GNU
keeps the cell (CR Nit 2 — pinned in the new suite as the documented
divergence for the parked unset-operand follow-up).
Tests: tests/issue828_arith_let_assoc_ansic_subscript_regressions.rs —
22 tests encoding the GNU-verified rows (storage bytes, cross-entry
reads, ++/command-read forms, let dq/sq operand forms, declare -p
rendering, membership, unset, array_expand_once boundary). GPL
discipline: behavior implemented from WSL GNU 5.3.0 probes; vendored
source used as semantic reference only.
cr-839 round 1 (BLOCKER): the span scanner now tracks single/double quote
state (mirroring #822 decode_ansi_c_spans� in_single discipline and
extending it with in_double — arithmetic subscript text carries live
dollar-quote-blind double-quoted segments). A $�...� span only opens
outside both quotes: ((E3["pre$�x�post"]=1)) stores the raw spelling
pre$�x�post (70 72 65 24 27 78 27 70 6f 73 74, GNU/master parity — was
prexpost), and �a$�b�c� sits back on the master-known raw shape
�27 61 24 27 62 27 63 27� (was abc, losing the dollar bytes). Three new
pins (both CR shapes + the let-entry forms through the shared scanner)
and an E3 row in the issue-828 catalogue case. Serial
(--test-threads=1) full-suite bidirectional comparison vs master
992d5c5: failure sets identical (38 vs 40; outliers are the known
signal-timing/path-cache env flakes, green in isolation on both sides —
issue526 fails 2/7 identically on master and this branch).
ee8cf9b to
540c933
Compare
|
CR round 1 addressed on the new head 540c933 (force-pushed over ee8cf9b). BLOCKER fixed:
Pins added: 3 new tests ( Out-of-scope note (E3b, the #822 scanner's dquote blind spot on master): untouched here per your triage — confirmed pre-existing on 992d5c5, left for your ticket. Re-verification on the new head: the full probe battery re-run against the WSL GNU 5.3.0 oracle — all previously-green rows still byte-identical; the only remaining diffs are the documented families (bare-escape r08/r09/r11, unset-operand u1/u2/u3, the a9 lexer shape identical to master). Serial |
Closes #828 (the fourth write entry left out of #734/#822's two-entry scope, per the cr-822 Nit 1 annotation).
Root cause
Both arithmetic assignment entries —
((A[sub]=v))and itslet "A[sub]=v"form — expand the associative subscript throughexpand_assoc_subscript_once(arithmetic/mod.rs) before the parser sees it, and that pass never touched the literal$'...'spans: the RAW spelling (24 27 78 5c 74 79 27for$'x\ty') became the stored key, so${A[$k]}printed empty where GNU prints[1]. GNU reachesexpand_subscript_stringfrom this entry too, but the runtime pass behaves differently per caller, and the two let/arithmetic shapes sit on OPPOSITE sides of the line:((...))/$((...))/ nested-subscript readers: the raw spelling reachesexpand_subscript_string, whoseexpand_word_internalarm ANSI-C-decodes the span with the product quoted — decoded bytes ride as DATA and decoded backslashes survive (((D[$'a\\b']=2))stores61 5c 62). This is the same assignment-entry semantics fix(executor): normalize assoc subscripts so ANSI-C spellings match variable lookups (#734) #822 gave the two word entries; the arithmetic entries now share it (ArithAnsiSpanMode::Decode).let: the operand was word-expanded once (let.def passesEXP_EXPANDED), and GNU does NOT re-recognize$'as ANSI-C there — the$stays literal data, the span quotes drop as shell quotes and the raw spelling rides verbatim:let "B[$'x\ty']=1"stores the scrambled key$x\ty(24 78 5c 74 79), which onlylet's own reader hits. GNU's own self-scrambling quirk — pinned as parity (ArithAnsiSpanMode::LetOperand), per the ticket's "let 双引号形态 GNU 亦自乱……按 parity 固定".Bare (non-
$') spellings are deliberately untouched: the(( ))body reaches the evaluator after the lexer's own escape pass, so the bare-escape product stays as the assoc corpus rows recorded (re-processing it would eat one backslash too many).Fix (
src/executor/subscript_expansion.rs+ callers)transform_arith_ansi_c_spansrewrites each literal$'...'span of an arithmetic assoc subscript into carrier-marked data (no live\$/quote/backslash inside a span product; scanning mirrorsdecode_ansi_c_spans), per entry mode;expand_arithmetic_assoc_subscriptsthreads the mode from the((``))/letflag (expr.c:340,368 EXP_EXPANDED), with the reader-family call sites ($(( )), nested subscript scan, substring offsets) hard-wired toDecode. Theshopt -s array_expand_onceAV_NOEXPAND verbatim branch is unchanged (GNU stores the spelling verbatim there too).GNU differential evidence (GNU bash 5.3.0, WSL, script files; byte-verified 2026-10-13; all rows byte-identical after the fix)
((A[$'x\ty']=1))key bytes7809792427785c747927780979${A[$k]}[1][][1]$((A[$'x\\ty']))11(raw self-hit)1declare -p([$'x\\ty']="1" )(raw-spelling row)([$'x\\ty']="1" )((D[$'a\\\\b']=2))key bytes615c622427615c5c6227615c62${D[$'a\\\\b']}2/[](pinned${}asymmetry)2/[]2/[]((F[$'p\\q']=1))key bytes + arith self-read705c71/12427705c7127/1705c71/1((A[$'x\\ty']++))780979,${A[$k]}=[1][]780979,[1](( z = A[$'x\\ty'] ))after clean write11(raw self-hit)1A[$k]=1→$((A[$'x\\ty']))101$'x\\ty'+ dq-literal-tab writes via((...))$'\\uE401'key via((...))(#735 interplay)ee9081ee9081let "B[$'x\\ty']=1"key bytes24785c7479($x\\ty)2427785c74792724785c7479${B[$k]}[][][]let "v=B[$'x\\ty']"[1][1][1]declare -p([\"\\$x\\\\ty\"]="1" )([\"\\$x\\\\ty\"]="1" )let 'B[$'"'"'x\\ty'"'"']=1'(sq operand)24785c747924785c7479let "O[$'a\\\\b']=2"(CR Nit 1 row)24615c62($a\\b)2427615c622724615c62let 'O2[$'"'"'a\\\\b'"'"']=2'(both backslashes kept)24615c5c6224615c5c62M[$'x\\ty'post],P[pre$'x\\ty'])24785c7479706f7374/70726524785c7479let "J[$k]=9"/let "K[x<TAB>y]=7"(guard)780979/780979780979/780979780979/780979$(( ))read of a let-scrambled cell0/01/10/0${I[$k]+x}/[[ -v ]]/${I[$'x\\ty']+x})unset "A[$k]"on an arith-written cellA=()A=()shopt -s array_expand_once+ let / +((...))780979780979CR Nit 2 data point (pinned divergence, deliberately not fixed here):
unset 'A[$'"'"'x\\ty'"'"']'afterA[$'x\\ty']=1(any write entry) — GNU's unset does not ANSI-C-decode the operand and KEEPS the cell (declare -A A=([$'x\\ty']="1" )); rubash decodes it and DELETES (A=()). Pre-existing on master, both sides of this PR; pinned in the new suite (unset_ansi_c_operand_spelling_divergence_pinned) as the documented divergence for the parked unset-operand follow-up ticket.Other pre-existing divergences left untouched (out of scope, noted for the record): bare escapes inside arithmetic subscripts keep one more backslash than GNU (
((G[a\\\\b]=2))second cellx\\tyvsxty); the indexed-array path's error text for(( y = undeclared[$'x\\ty'] )); the issue-734 catalogue row still readsdivergesthough its case now matches on master (stale row, pre-existing — PROMOTE pending, unrelated to this fix).Tests
tests/issue828_arith_let_assoc_ansic_subscript_regressions.rs— 22 tests: the ticket's headline rows, the CR table rows (r13-r19), storage bytes, cross-entry reads,++/command-read forms,declare -prendering, membership, unset controls, the Nit 2 pinned divergence, and thearray_expand_onceboundary. All expectations byte-verified against the GNU oracle.scripts/regression-catalog/cases/issue-828.sh+manifest.tsvrow (must-match) — the case body is byte-identical between the GNU oracle and rubash.Suite impact
Full
cargo test --no-fail-faston this branch (ee8cf9b, rebased over master 992d5c5) vs baseline 992d5c5, run side by side: failure sets identical (41 vs 43 raw rows — all 8 differing tests green in isolation on BOTH sides; they are the known env/concurrency-flakyexecutor::path/wait_n/fixturefamilies that flaked because the two full suites ran concurrently on one machine, same shape as the #822 suite-impact note). Zero new failures, zero flips in either direction.cargo fmt --checkclean;scripts/check-utf8-boundary-hygiene.shclean.GPL
Behavior implemented from WSL GNU bash 5.3.0 probes; the vendored submodule was consulted for semantics only. Citations in comments are traceability pointers (PROVENANCE §4).