Skip to content

fix(executor): function-name prolog for readonly -a/-A nested declare replays (Refs #2658) - #3698

Merged
caomengxuan666 merged 1 commit into
masterfrom
fix/2658-readonly-array-diag
Nov 15, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
fix/2658-readonly-array-diag

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Summary

Residual cells of issue2658_readonly_compound_function_abort (3 red):
GNU reports f: r: readonly variable (enclosing function name) when a
readonly -a/readonly -A/export -a/export -A compound operand fails
the readonly check inside a function; rubash printed the bare r: form.

Root cause: setattr.def:231-251 replays readonly -a r=(6) as nested
declare -gra r (subst.c:12949 expand_declaration_argument →
subst.c:12792 make_internal_declare), so the refusal is declare's own
sh_readonly (declare.def:876) via builtin_error
(builtins/common.c:83-105) — this_command_name is the enclosing
function name because the builtin name is installed only after
expand_words (execute_cmd.c:4800). Flagless readonly r=(4) reduces to
scope-only declare -g r which succeeds, so its refusal is the bind
layer's err_readonly (error.c:453 report_error) — bare name.

The prolog class now covers declare/typeset/local always and
readonly/export only under -a/-A replay. DISCARD (subst.c:13033
exp_jump_to_top_level) still applies to the special builtins.

Legs

  • pin: issue2658_readonly_compound_function_abort 6/6 green (was 3/6),
    issue2658_readonly_compound_abort 12/12 green — WSL, cargo test
  • GNU 5.3.20 script-file diff: byte-identical on a 4-function matrix
    (declare/readonly/local/export × -a/-A × in/out of function)
  • adjacent pins green: issue1317 (7), issue1318 (5), issue1366 (2),
    issue0077_declare_regressions (1), issue1471_local_global (1)
  • cargo build --locked, cargo fmt --check, RUSTFLAGS=-D warnings cargo check all clean

Test plan

  • pin stems green on WSL
  • GNU oracle byte-identical
  • adjacent declare/readonly pins green

… replays (Refs #2658)

setattr.def:231-251 turns `readonly -a r=(6)` / `export -A m=(x)` into a
nested `declare -gra`/`declare -grA` replay, so the readonly refusal is
declare's own sh_readonly (declare.def:876) reported through
builtin_error — whose this_command_name at expansion time is the
enclosing function name (builtins/common.c:83-105; the builtin name is
installed only after expand_words, execute_cmd.c:4800). Flagless
`readonly r=(4)` reduces to a scope-only `declare -g r` that succeeds, so
its refusal arrives later from the bind layer's err_readonly
(error.c:453) and stays bare.

The compound-operand path now picks the function-prefixed prolog when the
builtin is declare/typeset/local OR when -a/-A hints mark an attribute
replay; flagless readonly/export keep the bare diagnostic. DISCARD
(subst.c:13033) still applies to the special builtins.
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.

1 participant