Skip to content

[bug] set -a marks a flagless declare compound assignment inside a function (top-level quirk does not apply there) #2964

Closed

Description

@caomengxuan666

Summary

Under set -a, a flagless declare arr=(1 2) INSIDE a function is marked -x by rubash but not by GNU. The top-level twin of this form is a genuine GNU quirk that must keep the mark (see below), so the gap is specific to the function context. Found while probing the r79 batch (Refs #2945); the batch preserves the top-level quirk with a control pin, and this function-context form is filed separately rather than folded in.

Reproduction (master 4f74741)

set -a; f(){ declare arr=(1 2); declare -p arr; }; f
  • GNU bash 5.3.20: declare -a arr=([0]="1" [1]="2")
  • rubash: declare -ax arr=([0]="1" [1]="2")

Control shapes:

  • Top level, both shells AGREE: set -a; declare arr=(1 2); declare -p arr → declare -ax on both. At top level GNU's valued declare word creates the name through bind_variable (ASS_FORCE) before the compound conversion, and that creation bind applies the mark_modified_vars mark (variables.c:3211-3212). This quirk is pinned as a control in the r79 batch and must not regress.
  • In-function SCALAR declare, both shells AGREE: set -a; f(){ declare z=9; declare -p z; }; f → declare -x z="9" on both (the local value bind is bind_variable_value, variables.c:3366-3367, which marks).

GNU semantics

Inside a function, declare_internal runs with the local context: a compound operand is created through the local array machinery and converted via do_compound_assignment (subst.c:3441) — neither applies the export mark — and the top-level ASS_FORCE creation pre-bind that produces the quirk does not occur. Rubash's declare allexport post-pass (the #538 emulation in execute_declare) marks every valued operand uniformly, with no function-context distinction for compound values, so the in-function compound form inherits a mark GNU never sets.

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

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions