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

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



On Tue, Mar 22, 2016 at 3:14 PM, Paul Wayper <paulway@xxxxxxxxxx> 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.



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