zsh-workers
 help / color / mirror / code / Atom feed
From: Stephane Chazelas <stephane@chazelas.org>
To: Bart Schaefer <schaefer@brasslantern.com>
Cc: Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: [PATCH] Fix crash on unset-through-nameref
Date: Wed, 6 Mar 2024 18:21:08 +0000	[thread overview]
Message-ID: <20240306182108.tf7qmtcdiykej4uv@chazelas.org> (raw)
In-Reply-To: <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


  reply	other threads:[~2024-03-06 18:21 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-04  5:37 Bart Schaefer
2024-03-04  6:29 ` Stephane Chazelas
2024-03-04  8:39   ` Bart Schaefer
2024-03-04 19:34     ` Stephane Chazelas
2024-03-04 19:36       ` Stephane Chazelas
2024-03-04 23:50         ` Bart Schaefer
2024-03-05  8:36           ` Stephane Chazelas
2024-03-04 23:18       ` Bart Schaefer
2024-03-05  8:18         ` Stephane Chazelas
2024-03-05 18:42           ` Bart Schaefer
2024-03-05 19:38             ` Stephane Chazelas
2024-03-05 23:16               ` Bart Schaefer
2024-03-06 18:21                 ` Stephane Chazelas [this message]
2024-03-06 19:17                   ` Bart Schaefer
2024-03-06 19:37                     ` Bart Schaefer
2024-03-05 19:48             ` unset, POSIX and the export attribute (Was: [PATCH] Fix crash on unset-through-nameref) Stephane Chazelas
2024-03-05 19:51             ` [PATCH] Fix crash on unset-through-nameref Stephane Chazelas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240306182108.tf7qmtcdiykej4uv@chazelas.org \
    --to=stephane@chazelas.org \
    --cc=schaefer@brasslantern.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).