Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: nameref binding not finding calling-scope vars?
- X-seq: zsh-workers 53439
- From: Phil Pennock <zsh-workers+phil.pennock@xxxxxxxxxxxx>
- To: Zsh Workers <zsh-workers@xxxxxxx>
- Subject: Re: nameref binding not finding calling-scope vars?
- Date: Wed, 2 Apr 2025 22:36:26 -0400
- Archived-at: <https://zsh.org/workers/53439>
- In-reply-to: <CAH+w=7Y9e=Xmk=0FpC3bq4THeGseYObxOoMcvUG0vPXBE64oWg@mail.gmail.com>
- List-id: <zsh-workers.zsh.org>
- Mail-followup-to: Zsh Workers <zsh-workers@xxxxxxx>
- Openpgp: url=https://www.security.spodhuis.org/PGP/keys/key2020-cv25519.asc
- References: <Z-ee8qMpHlTDQkRh@fullerene.field.pennock-tech.net> <CAH+w=7YBt32KgzYv97op9yGG7SqYhxPiuhpcNAFZNfbdqpJLiw@mail.gmail.com> <CAH+w=7Y9e=Xmk=0FpC3bq4THeGseYObxOoMcvUG0vPXBE64oWg@mail.gmail.com>
On 2025-03-31 at 15:00 -0700, Bart Schaefer wrote:
> Attached patch fixes this. Tests based on this thread included.
These work great, thanks. The only problem now is figuring out which
approach makes the most sense. :)
It feels like `local -un var="$1"` makes the most sense, as it is
explicitly stating that the variable should be found externally.
However, if I use `setopt warn_create_global` then the version where
inner() uses `typeset -ga` is the only one which does not issue a
warning.
A: inner() { local -n var="${1:?}"; var=(alpha beta gamma); }
B: inner() { local -n var="${1:?}"; typeset -ga var=(alpha beta gamma); }
C: inner() { local -un var="${1:?}"; var=(alpha beta gamma); }
Of these three, I would expect A to warn under warn_create_global, but
not B or C. In practice, both A and C do.
Is my thinking here Wrong? It seems like `-un` is being very explicit
that the value should be found in the calling scope, much like the
implicit behaviour of -g when using the nameref, so there's no need for
the warning.
It looks like check_warn_pm tries to avoid warnings for nameref, but of
course that flag isn't set on the basepm which is found by searching, so
doesn't take effect?
> This should work after the attached patch.
Everything I mentioned first time does, so again: thank you. :)
My grotesquely over-engineered custom completion for a special type now
can set vars other than $reply.
-Phil
Messages sorted by:
Reverse Date,
Date,
Thread,
Author