Skip to content

fix(executor): sync typed assoc cell on nameref element assignment (#961) - #962

Merged
caomengxuan666 merged 1 commit into
masterfrom
fix/961-assoc-nameref-sync
Oct 21, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
fix/961-assoc-nameref-sync

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Fixes #961. The assoc leg of apply_nameref_array_element_assignment wrote the mirror without syncing the typed cell (indexed leg already had sync from #914), so the typed-cell fast read returned a stale value (debug assert / silent wrong value in release). Mirror the indexed leg: sync_typed_assoc_array + clear dirty, preserving complete-or-absent. GNU variables.c find_variable_nameref_for_assignment / assoc.c assoc_insert. Repro now byte-identical to bash 5.3.20 in debug and release.

…ubash#961)

apply_nameref_array_element_assignment's assoc leg wrote the rendered assoc
mirror into env_vars but never synced shell_state.variables, so the
structured ShellValue::AssociativeArray cell kept the pre-assignment value
and shadowed the mirror. The indexed leg already syncs
(sync_typed_indexed_array + clear_array_cells_dirty); make the assoc leg
symmetric with sync_typed_assoc_array + clear_array_cells_dirty.

GNU has ONE owner for an assoc element: variables.c:3266-3267 bind_variable
(nameref cell -> assign_array_element) -> arrayfunc.c:262
bind_array_variable -> assoc.c:68 assoc_insert overwrites the key in place.
The complete-or-absent invariant is what lets the typed-cell read fast path
(executor/arrays/executor.rs:194, GNU assoc.c:120 assoc_reference) trust the
cell.

Repro (matches GNU bash 5.3.20):
  declare -A A=(['K']=val); declare -n ref='A["K"]'; ref='val2'; echo "$ref"
  debug  (pre):  panic at executor.rs:207
                 "typed assoc cell disagrees with mirror for A[K]" (val vs val2)
  release(pre):  prints val (declare -p shows val2 — mirror/cell diverged)
  post   :       prints val2 in both profiles

Verification:
  cargo test --locked --test oils_spec_assoc_append_regressions  -> 50 passed
  cargo test --locked --lib                                     -> 669 passed
  oracle matrix vs GNU bash 5.3.20 (quoted/unquoted subscript cell,
  append, -Ai integer, new key, subscript-var cell) byte-for-byte.

Refs #961
@caomengxuan666
caomengxuan666 force-pushed the fix/961-assoc-nameref-sync branch from da6b6e3 to f342467 Compare October 21, 2026 03:42
@caomengxuan666
caomengxuan666 merged commit 8d9a518 into master Oct 21, 2026
6 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/961-assoc-nameref-sync branch October 21, 2026 08:01
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.

assoc nameref scalar write updates mirror but not typed cell: debug_assert panic (executor.rs:207) / silent wrong value in release

1 participant