Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: [PATCH] Fix crash on unset-through-nameref
- X-seq: zsh-workers 52694
- From: Stephane Chazelas <stephane@xxxxxxxxxxxx>
- To: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- Cc: Zsh hackers list <zsh-workers@xxxxxxx>
- Subject: Re: [PATCH] Fix crash on unset-through-nameref
- Date: Wed, 6 Mar 2024 18:21:08 +0000
- Archived-at: <https://zsh.org/workers/52694>
- In-reply-to: <CAH+w=7ZXDHJSLrLa-dmR0egOZkbnp9RKm1FC0oHBPG3Ne5NfKQ@mail.gmail.com>
- List-id: <zsh-workers.zsh.org>
- Mail-followup-to: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>, Zsh hackers list <zsh-workers@xxxxxxx>
- References: <CAH+w=7ayqWoufueuaHiCzjmzgHtv6VV0m7mEXoHn5nGq4pNOzg@mail.gmail.com> <20240304062914.kn6wquvgog3lefom@chazelas.org> <CAH+w=7b9dcQ4f=71rFZSWBVEJ4bzj7NxzD2-zoj2TkpaCkaCjw@mail.gmail.com> <20240304193409.lv725ah6eifiazzx@chazelas.org> <CAH+w=7ZiTe_hPoBRtHBsRHRvifkiaCJPOCzRSpz0H=XHV8rNbw@mail.gmail.com> <20240305081859.r3qwiyduk2wgkdby@chazelas.org> <CAH+w=7bJsoJcDz0aNr9G11On4a_fssw3QJHTrtzQnT75n8A-Hw@mail.gmail.com> <20240305193840.vvixetyn6vfnbir2@chazelas.org> <CAH+w=7ZXDHJSLrLa-dmR0egOZkbnp9RKm1FC0oHBPG3Ne5NfKQ@mail.gmail.com>
2024-03-05 15:16:25 -0800, Bart Schaefer:
[...]
> Sorry, your example is confusing me. "nameref" is only available when
> the zsh/ksh93 module is loaded. What's actually happening here, and
> why do you never use -fc to prevent dotfiles from being read?
I hadn't realised -f also skipped ~/.zshenv, I thought that one
like /etc/zshenv could not be skipped (and why I always leave it
empty as it also affects scripts).
Should we also use
#! /bin/zsh -f-
shebangs in scripts?
> I think you're referring to the difference between
> var=0; f
> and simply
> f
> In the latter case, "the scope where it completed the resolve" is the
> local scope because no parameter in a surrounding scope exists. If
> you assign to such a nameref, it "goes first to that scope", and if it
> still finds nothing, climbs up to global scope (because implicitly
> "finds nothing" at any local scope means there can't be that name at
> global scope).
>
> It's consistent with how $var / var=x would work if you never declared
> anything, and consistent with ${(P)ptr} / ${(P)ptr::=x} when ptr is a
> plain scalar. The difference is when the ref has already found
> something, which seems like the intended difference if you're using a
> reference in the first place.
My point is that if it means the:
assign() {
typeset -n var=$1
local value=$2
var=$value
}
doesn't work for
assign var value
or
assign value something
And we need to work around it by doing:
assign() {
typeset -n _assign_var=$1
local _assign_value=$2
_assign_var=$_assign_value
}
(Yes, I know we can always fo assign() eval -- $1=\$2)
Like we do in bash/mksh or when using (P) or eval... then
there's little point trying to be smarter in the
var=; assign var value
value=; assign value something
cases. You may say there's no harm in doing so, I'd agree
there's little harm except
- it makes it a bit inconsistent
- it may trick users into thinking they can get away without
using namespacing.
In any case, I'm not against being smart in the second case, I
just wish we could get away without the namespacing (like in the
zslurp case which started that whole discussion).
--
Stephane
Messages sorted by:
Reverse Date,
Date,
Thread,
Author