Re: delcare -a on a nameref in a function modifies nameref instead of target

2018-07-26 Thread Chet Ramey
On 7/25/18 4:27 PM, Grisha Levit wrote:
> In the latest devel this issue is fixed for the case that the local nameref
> points to a non-existent variable but there is still a bug if the variable
> pointed to by a local nameref already exists.  

Thanks for the report. The original fix was too conservative.


-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRUc...@case.eduhttp://tiswww.cwru.edu/~chet/



Re: segfault w/ localvar_inherit and associative array insert

2018-07-26 Thread Chet Ramey
On 7/25/18 5:37 PM, Grisha Levit wrote:
> shopt -s localvar_inherit
> declare -A var
> f() { declare var+=([0]=X); }; f

This should be an error due to mismatched array types.  The local variable
is an indexed array; the global variable is an associative array (though
it is unset). You can't inherit that value.

Chet

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRUc...@case.eduhttp://tiswww.cwru.edu/~chet/



Re: segfault w/ localvar_inherit and associative array insert

2018-07-26 Thread Grisha Levit
It seems that in general the array type is inherited just fine, there is an
issue only in the case that:
   * the `A' attribute is inherited but not explicitly supplied
   * we are creating the local variable with the `declare' command
 (i.e. it is not already an existing local variable)
   * we are performing a compound assignment/append operation in the
 same declare command

For example, given:

shopt -s localvar_inherit
declare -A var=([X]=X)

These all work smoothly:

## no explicit `-A', no assignment in `declare':

f() { declare var; declare -p var; }; f
# declare -A var=([X]="X" )

f() { declare var; var=([Y]=Y); declare -p var; }; f
# declare -A var=([Y]="Y" )

f() { declare var; var+=([Y]=Y); declare -p var; }; f
# declare -A var=([X]="X" [Y]="Y" )

## explicit `-A', assignment in `declare':

f() { declare -A var=([Y]=Y); declare -p var; }; f
# declare -A var=([Y]="Y" )

f() { declare -A var+=([Y]=Y); declare -p var; }; f
# declare -A var=([X]="X" [Y]="Y" )

## non-compound assignment:

f() { declare var[Y]=Y; declare -p var; }; f
declare -A var=([X]="X" [Y]="Y" )

But here we have some issues:

## no explicit `-A', assignment in `declare':

f() { declare var=([Y]=Y); declare -p var; }; f
# Segmentation fault: 11

f() { declare var+=([Y]=Y); declare -p var; }; f
# Segmentation fault: 11

f() { declare var+=(); declare -p var; }; f
# declare -aA var=()

f() { declare var=(); declare -p var; }; f
declare -aA var=()