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 Sun, Jun 8, 2025 at 3:21 PM Philippe Altherr
<philippe.altherr@xxxxxxxxx> wrote:
>
> Bart, you say "as things stand "typeset -n ref=" is a necessity.". I really don't see why?

I was going to demonstrate, but instead I just demonstrated what I
think may be a bug.

typeset -n ref=var
typeset -n ref

does not reset the state of ref to being a placeholder.  It's still
got var as referent.

typeset -n ref=var
typeset -n ref=

does so, which is why I consider it necessary.  However ...

typeset -n ref=var
unset -n ref

also sort of does so, in that re-assigning or re-declaring ref revives
it.  I think this is actually a bug -- "unset -n ref" should cause ref
to cease to be a named reference at all, as explained by this bit of
doc:

  Thus to remove a named reference, use either 'unset -n PNAME'
  (preferred) or one of:

       typeset -n PNAME=
       typeset +n PNAME

  followed by

       unset PNAME

My original point was going to be that

  typeset -n ref=var
  typeset -n ref=
  typeset -i ref

is intentionally an error ("can't change type of a named reference") whereas

  typeset -n ref=var
  unset -n ref
  typeset -i ref

should work (but doesn't), and therefore ref= is a distinct,
necessary, operation.

Aside, note that

  setopt typesettounset
  typeset -n ref
  unset ref

does not work, because ref is already unset so unsetting it again is a
no-op.  You must use the incantations in that doc excerpt.

Regarding "<null>", we had a long discussion around the time of the
implementation of typesettounset and eventually rejected the idea of
having an out-of-band value representing a null parameter.  I would
rather not revisit that at this point, but if others feel as strongly
as Philippe does about declaring empty-value namerefs, then I suggest
we use "." (dot) instead of something like "<null>".  In which case I
believe declaring

  unsetopt typesettounset
  typeset -n ref
  typeset -p ref

ought to print

  typeset -n ref=.

the way that integers are initialized to 0, etc.  Please note,
however, that fundamentally I would prefer NOT to introduce this.

It's becoming unhelpful for just Philippe and I to keep batting these
points back and forth, it's not building any kind of consensus.




Messages sorted by: Reverse Date, Date, Thread, Author