Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm
Precedence: bulk
X-No-Archive: yes
List-Id: Zsh Workers List <zsh-workers.zsh.org>
List-Post: <mailto:zsh-workers@zsh.org>
List-Help: <mailto:zsh-workers-help@zsh.org>
X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au
X-Spam-Level: 
X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham
	autolearn_force=no version=3.4.1
To: zsh-workers@zsh.org
From: Paul Wayper <paulway@redhat.com>
Subject: zsh -n does not detect incorrect associative array declaration
X-Enigmail-Draft-Status: N1110
Message-ID: <56F1C3D7.6020800@redhat.com>
Date: Wed, 23 Mar 2016 09:14:47 +1100
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101
 Thunderbird/38.3.0
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22
X-Seq: zsh-workers 38206

Hi there!

Sourceforge has pointed me to this list as a way to get a bug fixed in zsh.

I've discovered that an incorrect associative array declaration in zsh
isn't detected via 'zsh -n script.zsh', even though it does get flagged
when the script is executed.  For example:

$ cat zsh_array.zsh 
#!/usr/bin/zsh

typeset -A fn
fn=(foo_key foo_val bar_key bar_val)

printf %s\\n ${fn[foo_key]} ${fn[bar_key]}

$ cat zsh_bad_array.zsh 
#!/usr/bin/zsh

typeset -A fn
fn=(foo_key foo_val bar_key)

printf %s\\n $fn[foo_key] $fn[bar_key]

$ zsh -n zsh_array.zsh && echo $?
0
$ zsh zsh_array.zsh
foo_val bar_val

# And yet:
$ zsh -n zsh_bad_array.zsh && echo $?
0
$ zsh zsh_bad_array.zsh
/tmp/zsh_bad_array.zsh:4: bad set of key/value pairs for associative array


This syntax for associative array declaration is the one documented as
correct:

http://zshwiki.org/home/scripting/array

gives the first example of associative array assignment as:

typeset -A buffer
buffer=( key1 val1 key2 val2 )


Ideally what I'd like is for zsh -n to give the same error message on an
incorrect associative array declaration as zsh gives when executing the
script.

Thanks in advance,

Paul

-- 
Paul Wayper -- Senior Software Maintenance Engineer -- RHCE
Red Hat -- Australia -- Canberra

