Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Is this intentional behavior of typeset -g ?



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.




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