zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: Zsh hackers list <zsh-workers@zsh.org>
Subject: Is this intentional behavior of typeset -g ?
Date: Fri, 16 Feb 2024 12:09:56 -0800	[thread overview]
Message-ID: <CAH+w=7YVBsN-4-TJaTVzzexyEmBq_1pp810TYe_faZPNVmw5wg@mail.gmail.com> (raw)

Just noticed that this:
  typeset -g foo=global
  local foo=local
changes the scope of "foo" from global** to local, but this:
  local foo=local
  typeset -g foo=global
does NOT assign to "foo" in the global** scope, it just continues to
apply to the local.

** "global" meaning any surrounding dynamic scope possibly up to the top level.

That is, the -g option starts "searching" at the current scope and
stops as soon as it encounters a declaration (even if the name is
unset), rather than (as one might think) starting one level above the
current.  Note prior mention of how ungainly it is to insert new
parameters at a surrounding scope, so I'm pretty sure this has always
been this way.

If this is legitimately the expected behavior (and it seems to be the
historic and possibly necessary behavior) there may be an easy
workaround for the "typeset -n" issue that was reported in
workers/52530 (or maybe this doesn't help at all, I haven't worked
through details yet).

Tangentially, I think there's a regression with "private":

() {
  zmodload zsh/param/private
  private foo=local
  typeset -p foo
}

That now prints nothing, whereas in e.g. 5.7 it would say
  typeset foo=local
which isn't precisely accurate either.


             reply	other threads:[~2024-02-16 20:10 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-16 20:09 Bart Schaefer [this message]
2024-02-17  6:29 ` Regression of typeset output with "private" Bart Schaefer
2024-02-18 19:35   ` Bart Schaefer
2024-02-20  4:54     ` [PATCH] (take 2) Local specials and " Bart Schaefer

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='CAH+w=7YVBsN-4-TJaTVzzexyEmBq_1pp810TYe_faZPNVmw5wg@mail.gmail.com' \
    --to=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).