Zsh Mailing List Archive
Messages sorted by:
Re: zsh -n does not detect incorrect associative array declaration
- X-seq: zsh-workers 38208
- From: Paul Wayper <paulway@xxxxxxxxxx>
- To: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- Subject: Re: zsh -n does not detect incorrect associative array declaration
- Date: Wed, 23 Mar 2016 13:28:47 +1100
- Cc: Zsh hackers list <zsh-workers@xxxxxxx>
- In-reply-to: <CAH+w=7YDbbw_J2G6BJKqi9=MtymqAQo1Zhv-19FGK0RqFnyScA@mail.gmail.com>
- List-help: <mailto:email@example.com>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:firstname.lastname@example.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <56F1C3D7.email@example.com> <CAH+w=7YDbbw_J2G6BJKqi9=MtymqAQo1Zhv-19FGK0RqFnyScA@mail.gmail.com>
On 23/03/16 11:20, Bart Schaefer wrote:
> 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.
I agree that evaluation of external commands and output substitution
into the script is something that can't be checked with NO_EXEC.
Given that situation, should we update the zsh manual to point out that
the -n option cannot check the syntax of commands that are evaluated, so
that this is more explicit? I'd be happy to write such an update and
push it if you'd prefer that.
However, I don't see why you can't at least check that the syntax is
correct for things that don't use evaluation. That by far must be the
majority of such cases.
Hope this helps,
Paul Wayper -- Senior Software Maintenance Engineer -- RHCE
Red Hat -- Australia -- Canberra
Messages sorted by: