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

Re: [bug] zcompile failes to compile



On Sun, 13 Jun 2010 12:36:26 +0000 (UTC)
JÃrg Sommer <joerg@xxxxxxxxxxxx> wrote:
> % cat /tmp/test.sh
> #  -*- mode: sh -*-
> 
> echo $ZSH_VERSION
> 
> # with this line zcompile works
> # alias ag=true
> # but with this line zcompile fails
> alias ag='LC_ALL=C true'
> 
> if false
> then
>     agd()
>     {
>         true
>     }
> else
>     alias agd=ag
> fi
> 
> zcompile $0
> 
> % zsh-beta -f /tmp/test.sh
> 4.3.10-dev-1-cvs0603
> /tmp/test.sh:12: parse error near `()'
> /tmp/test.sh:zcompile:20: can't read file: /tmp/test.sh

The short answer is you should be using "zcompile -U" to compile without
expanding already defined aliases as your script is compiled.  I suppose
if you're compiling functions rather than scripts it's natural that
that's not on by default, since the presence or absence of the -U flag
matches what autoload would do.  In your case as it's a script you'd
probably never want alias expansion during compilation, so -U is always
going to be correct (and like you I'd probably never have thought of
it).

Here's the long answer.

When the script is invoked, ag becomes an alias for "LC_ALL=C true".
Than agd becomes an alias for "ag".

When zcompile is invoked without the -U, the agd function definition
during the parsing of the file for compilation is alias-expanded in two
steps to

  LC_ALL=C true()
  {
      true
  }

(It's never going to be executed in that particular test code but this
is just the parsing phase.)

In older shells parsing this didn't give an error---but I'm pretty sure
it's not what you wanted it do anyway.

In the current shell it does give an error.  This was deliberate (and
almost a year ago---it's high time I made a new release):

2009-07-17  Peter Stephenson  <p.w.stephenson@xxxxxxxxxxxx>

	* users/14240: Src/parse.c: assignment before a function
	definition should be an error, in common with other complex
	functions and as documented.

Seeing what you've got, I think that new error is actually useful for
you, too.

-- 
Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/



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