Repository navigation
fix(executor): sync typed assoc cell on nameref element assignment (#961) - #962
Merged
Merged
Conversation
…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
force-pushed
the
fix/961-assoc-nameref-sync
branch
from
October 21, 2026 03:42
da6b6e3 to
f342467
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.