zsh-workers
 help / color / mirror / code / Atom feed
From: Paul Wayper <paulway@redhat.com>
To: Bart Schaefer <schaefer@brasslantern.com>,
	Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: zsh -n does not detect incorrect associative array declaration
Date: Wed, 30 Mar 2016 17:00:46 +1100	[thread overview]
Message-ID: <56FB6B8E.7030707@redhat.com> (raw)
In-Reply-To: <CAH+w=7bkphoEdbFzXbU4_UXNWjr8M1UMUuO0QAiOfh=QR--1Ww@mail.gmail.com>

On 23/03/16 17:40, Bart Schaefer wrote:
> On Tue, Mar 22, 2016 at 7:28 PM, Paul Wayper <paulway@redhat.com> wrote:
>> On 23/03/16 11:20, Bart Schaefer wrote:
>>> 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.
>> 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.
> I don't have a preference here, but I don't think there's any reason
> for the zsh manual to be any more explicit than the manual for any
> other shell; for example bash:
>
>      -n      Read commands but do not execute them.  This may be used
>              to check a shell script  for  syntax  errors.   This  is
>              ignored by interactive shells.

I guess I would change that to read:

"Read commands but do not execute them.  This may be used to check a
shell script for most syntax errors, but cannot check inside evals and
other invocations."

> There's nothing *syntactically* wrong with
>
> fn=(foo_key foo_val bar_key)
>
> Even when executing commands normally, the syntax analyzer does not
> know that the assignment will fail if there are an odd number of
> values in the list.  That's a semantic error discoverable only when
> the assignment is performed.  The shell language is interpreted, not
> truly compiled, so parameter type information is not used in syntax
> analysis.  Plus, you're still ignoring the fact that the shell doesn't
> know "fn" is associative because it was not allowed to interpret the
> foregoing "typeset" command.

I see what you mean.  I would have expected the syntax check depended on
the typeset command, enough that it allows it to execute or stores the
type of the declared variable.  But as you say this is an interpreted
language so typed variables are somewhat bolted-on.

Anyway, I understand the situation now, so I can solve my problem.

Thanks once again,

Paul

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


  parent reply	other threads:[~2016-03-30  6:07 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-22 22:14 Paul Wayper
2016-03-23  0:20 ` Bart Schaefer
2016-03-23  2:28   ` Paul Wayper
2016-03-23  6:40     ` Bart Schaefer
2016-03-23  9:23       ` Peter Stephenson
2016-03-24  2:08         ` Bart Schaefer
2016-03-24  9:46           ` Peter Stephenson
2016-03-24 17:12             ` Bart Schaefer
2016-03-30  6:00       ` Paul Wayper [this message]
2016-04-19 13:50 ` Sebastian Gniazdowski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=56FB6B8E.7030707@redhat.com \
    --to=paulway@redhat.com \
    --cc=schaefer@brasslantern.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).