Skip to content

[compat] local/declare shadowing a readonly outer-scope var spuriously reports readonly variable #3609

Closed

Description

@caomengxuan666

Reproducer:

ccc(){ local x=(7 8 9); echo "ccc ${x[*]}"; }
ddd(){ local -r x='0'; ccc; }
x=zzz; ddd

GNU bash 5.3.20: ddd 0 then ccc 7 8 9 — silent.
rubash: same output plus spurious case.sh: line 2: x: readonly variable.

Root cause: the nested_readonly check in the declare-local operand binding consults the flat READONLY_VARS name mark without regard to whether the operand creates a FRESH local (locally_scoped). GNU make_local_variable (declare.def:929+, variables.c:5524+) binds the new mutable local instance; an outer-scope readonly mark on the same name must not fire. Same leakage made the readonly check reachable for the export/readonly family inside functions (those always bind the inherited global).

Refs #2666 (varenv19.sub).

Activity

  1. added
    bug
    gnu-baseline
    area:builtins
    on Nov 14, 2026
  2. added this to the 1.5.1 milestone on Nov 14, 2026
  3. caomengxuan666 commented on Nov 16, 2026

    @caomengxuan666
    MemberAuthor

    已由 PR #3610 squash 合入 master:841e125(完整 oid 841e125)。回归钉 issue3609_local_readonly_shadow(5 格:1 格 headline 判别 + 4 格守卫)。

  4. added a commit that references this issue on Nov 17, 2026
    841e125
  5. added a commit that references this issue on Nov 17, 2026
    8a85f33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

area:builtinsbuggnu-baseline

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions