* [bug] zcompile failes to compile
@ 2010-06-13 12:36 Jörg Sommer
2010-06-13 16:42 ` Peter Stephenson
0 siblings, 1 reply; 2+ messages in thread
From: Jörg Sommer @ 2010-06-13 12:36 UTC (permalink / raw)
To: zsh-workers
Hi,
% 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 -f /tmp/test.sh
4.3.10
% 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
Removing the LC_ALL=C from the alias ag or running zcompile at the
beginnig of the file works, but not the file above.
Bye, Jörg
--
Angenehme Worte sind nie wahr,
wahre Worte sind nie angenehm.
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [bug] zcompile failes to compile
2010-06-13 12:36 [bug] zcompile failes to compile Jörg Sommer
@ 2010-06-13 16:42 ` Peter Stephenson
0 siblings, 0 replies; 2+ messages in thread
From: Peter Stephenson @ 2010-06-13 16:42 UTC (permalink / raw)
To: zsh-workers
On Sun, 13 Jun 2010 12:36:26 +0000 (UTC)
Jörg Sommer <joerg@alea.gnuu.de> 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@ntlworld.com>
* 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@ntlworld.com>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2010-06-13 17:39 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-06-13 12:36 [bug] zcompile failes to compile Jörg Sommer
2010-06-13 16:42 ` Peter Stephenson
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).