Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: [BUG] zsh/param/private scoping error
On Wed, Sep 1, 2021 at 10:00 AM Mikael Magnusson <mikachu@xxxxxxxxx> wrote:
>
> Ah, I misinterpreted one of the examples, I thought that this would
> work as you expect:
> () { private foo; () { typeset -g foo=bar } }
> (while this wouldn't:
> () { private foo; () { foo=bar } }
> )
>
> But in both cases it is an error (although only the latter prints a
> message and aborts execution), and foo is not set globally.
Something else has changed since the implementation of private, I
think, because this is not what I expected:
top () { private foo=top; mid }
mid () { typeset -g foo=middle; bot }
bot () { print $foo }
functions -t top
% top
+top:0> private foo=top
+top:0> mid
+mid:0> typeset -g foo=middle
+mid:0> bot
bot: foo: attempt to assign private in nested scope
What makes the expansion of $foo in bot into an assignment?
> In fact a typeset -g is needed on the global level before the function
> using private is called, which seems impossible for the innermost
> function to enforce.
As you can see from the "F:" test Marlon quoted, this is something I
eventually intended to change. It's rather complicated because of the
way locals are implemented as a LIFO at each individual named entry in
the parameter table, rather than a LIFO of parameter tables. Even
without private, "typeset -g" only reaches as far upwards as the most
recent local declaration of the name.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author