Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: More about empty-string named references
- X-seq: zsh-workers 53751
- From: Mikael Magnusson <mikachu@xxxxxxxxx>
- To: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- Cc: Zsh hackers list <zsh-workers@xxxxxxx>
- Subject: Re: More about empty-string named references
- Date: Mon, 9 Jun 2025 12:00:24 +0200
- Archived-at: <https://zsh.org/workers/53751>
- In-reply-to: <CAH+w=7aTHd+Zxi9kD7qb7G-pUVJwJN+QQJYFwP7z6YvJeq=RnQ@mail.gmail.com>
- List-id: <zsh-workers.zsh.org>
- References: <CAH+w=7aTHd+Zxi9kD7qb7G-pUVJwJN+QQJYFwP7z6YvJeq=RnQ@mail.gmail.com>
On Mon, Jun 9, 2025 at 7:18 AM Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> > it's already the case that "typeset -a arr=" is not accepted. And rightly so!
> > An empty string is obviously neither an empty array, nor an array that
> > contains just the empty string.
>
> This is true but an array ...
> - can be discarded and replaced with any scalar by simple assignment.
> - can be discarded and replaced by any other type by a new typeset
> - cannot be converted from/to a scalar by typeset -a/+a
>
> None of those hold for a nameref.
I was going to ask why this is fine:
foo=( arr values ); foo=hello
but this is not:
foo=( arr values ); nameref bar=foo; bar=hello
however, I was greeted with this error instead, which I assume is not expected:
zsh -c 'nameref foo=bar; bar=(hi); foo=hello'
1: params.c:1067: BUG: local parameter is not unset
(and once I tried it in a function scope, both actually work fine, i
remembered namerefs
not allowing to change type from array to scalar before, maybe it was
changed recently?)
> > It is detrimental because it implies that a statement like "typeset -nu ref=$1"
> > will not necessarily initialize the reference. Innumerable users will have to
> > figure out why their script exhibits a completely weird behavior
(In my estimation, these users will be quite numerable, or at least
not more innumerable than before).
--
Mikael Magnusson
Messages sorted by:
Reverse Date,
Date,
Thread,
Author