Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: zsh -n does not detect incorrect associative array declaration



On Tue, 22 Mar 2016 23:40:54 -0700
Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> Contrast this with ksh where associative array assignments look like
> 
> fn=( [foo_key]=foo_val [bar_key]= )
> 
> There the parser doesn't need to know the type of fn because the
> association is explicit in the format of the parenthesized list.  If
> we ever get around to implementing that bit of ksh syntax your
> assertion would become valid.  (But in that case the assignment
> forcibly changes the type of "fn" to become an associative array so
> the typeset is irrelevant.)

Off the original topic, but actually it doesn't, at least not in bash.

$ a=(1 2 3)
$ echo ${a[2]}
3
$ a=([one]=1 [two]=2)
$ echo ${a[*]}
2

This has been interpreted as a[one]=1 then a[two]=2 with "a" still an
array, so "one" and "two" are treated as 0.  This version was quite old
(4.1.7).

pws



Messages sorted by: Reverse Date, Date, Thread, Author