Subject: Re: zsh -n does not detect incorrect associative array declaration
From: Bart Schaefer <[email-masked]>
To: Paul Wayper <[email-masked]>
Cc: Zsh hackers list <[email-masked]>
Date: Tue, 22 Mar 2016 17:20:56 -0700
List-Id: Zsh Workers List <zsh-workers.zsh.org>

On Tue, Mar 22, 2016 at 3:14 PM, Paul Wayper <[email-masked]> wrote:
>
> 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.

This is not a bug; it's something that it's impossible to check with
the NO_EXEC option.  Consider:

typeset -a array
typeset -A fn
array=( $(some external command) )
fn=( $array )

With NO_EXEC set, the shell is prohibited from executing the $(some
external command) expression, so there is no way to determine how many
elements would be in $array if execution were allowed, and therefore
no way to determine whether an odd number of elements would be present
in the assignment to fn.

Technically, the shell is ALSO prohibited by NO_EXEC from executing
the "typeset" command, and therefore can't possibly know that "fn"
represents an associative array in the first place.

The NO_EXEC option is only useful for the most rudimentary of syntax
checks.  It cannot detect/predict execution-time inaccuracies.