I don't know if this makes consistency easier or harder, but there is
currently code to handle `declare' with -[iluc] early [1]. As a result, a
combination of localvar_inherit and the use of one of those options when
declaring a local variable allows (correctly or not) for associative arrays
to inherit their previous value and have elements inserted at the same time:

    $ declare -A A; A[X]=X
    $ f() { local -u A+=([Y]=Y); declare -p A; }; f
    declare -Au A=([X]="X" [Y]="Y" )
    $ f() { local -u +u A+=([Y]=Y); declare -p A; }; f
    declare -A A=([X]="X" [Y]="Y" )
    $ f() { local A+=([Y]=Y); declare -p A; }; f
    -bash: warning: A: cannot inherit value from incompatible type

[1]
https://git.savannah.gnu.org/cgit/bash.git/tree/subst.c?h=devel&id=057a9fbdb4d9ad01b000743fcea9918b80823afc#n11199

Reply via email to