From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28466 invoked by alias); 23 Mar 2016 02:28:57 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 38208 Received: (qmail 29416 invoked from network); 23 Mar 2016 02:28:56 -0000 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 Subject: Re: zsh -n does not detect incorrect associative array declaration To: Bart Schaefer References: <56F1C3D7.6020800@redhat.com> Cc: Zsh hackers list From: Paul Wayper Message-ID: <56F1FF5F.6060907@redhat.com> Date: Wed, 23 Mar 2016 13:28:47 +1100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 On 23/03/16 11:20, Bart Schaefer wrote: > On Tue, Mar 22, 2016 at 3:14 PM, Paul Wayper 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 -- Paul Wayper -- Senior Software Maintenance Engineer -- RHCE Red Hat -- Australia -- Canberra