Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: BUG: Initializations of named references with an empty string should trigger an error
On Wed, May 21, 2025 at 2:10 AM Philippe Altherr
<philippe.altherr@xxxxxxxxx> wrote:
>
> Here is what ksh does:
>
> $ f ""
> ksh: f: line 4: : invalid variable name
>
> I think that this is much better and that Zsh should do the same,
We discussed this during past development of the nameref feature. The
decision was to implement it as currently documented, for the
following reasons:
1) Long-standing zsh practice is that "typedef name" always
initializes name to a default value based on its type flags (or lack
of them). Scalars are empty string, integers are 0, etc. This also
led to the introduction of the new TYPESET_TO_UNSET option, which when
set does not initialize in this way.
2) Zsh has the ability to promote and demote scalars to/from nameref.
% typeset ref=str str=XX
% typeset -n ref
% print $ref
XX
% typeset +n ref
% print $ref
str
%
I believe ksh can do the scalar-to-nameref promotion which is where
this feature originated. Anyway, combining these features means a
nameref initialized to the empty string should not be an error.
This is also a reason that namerefs shouldn't be reset to nothing when
returning from function scope.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author