Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
[BUG] zsh/param/private scoping error
- X-seq: zsh-workers 49346
- From: Marlon Richert <marlon.richert@xxxxxxxxx>
- To: Zsh hackers list <zsh-workers@xxxxxxx>
- Subject: [BUG] zsh/param/private scoping error
- Date: Wed, 1 Sep 2021 14:49:58 +0300
- Archived-at: <https://zsh.org/workers/49346>
- List-id: <zsh-workers.zsh.org>
The following two functions are normally equivalent:
() { typeset -g tst }
() { tst= }
Both result in a global variable 'tst' being created. However when the
second function is called from a function that happens to declare a
private variable with the same name, it no longer creates a global
variable but instead aborts with an error:
% () { private tst; () { tst= } }
(anon):1: tst: attempt to assign private in nested scope
%
This is not how one would expect private variables to behave. Inside
the inner function, the private variable should be completely out of
scope and the `tst=` statement should result in the creation of a
global variable.
Note that the error above does not happens when there already exists a
global variable with the same name:
% typeset -g tst
% () { private tst; () { tst= } }
%
Messages sorted by:
Reverse Date,
Date,
Thread,
Author