zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: Peter Stephenson <p.w.stephenson@ntlworld.com>
Cc: Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: [PATCH] Named reference typos & misc.
Date: Tue, 14 Feb 2023 17:39:54 -0800	[thread overview]
Message-ID: <CAH+w=7Yp3O+n5M_G5JkdUBXegz_EpzjCXe54rWoqUv+++xL84A@mail.gmail.com> (raw)
In-Reply-To: <CAH+w=7aRann+SXDjNwQP3dh=_-e9etrhms5cL-MQp-03KWtp1Q@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 600 bytes --]

On Tue, Feb 14, 2023 at 12:00 PM Bart Schaefer
<schaefer@brasslantern.com> wrote:
>
> +typesettounset        off
>
> By binary search, I found the option state changes for me after this test:

It has something to do with un-/auto-loading zsh/parameter, the option
state flips after that test (not after the one I initially thought).

Does that give anyone a clue?  I have the modules statically linked, by the way.

There was in fact a more fundamental problem being masked by this weirdness.

I took the opportunity to make the warnnestedvar output look more like
what happens with other variables.

[-- Attachment #2: nameref-testfails.txt --]
[-- Type: text/plain, Size: 2244 bytes --]

diff --git a/Src/params.c b/Src/params.c
index 92cbecf63..e940d7995 100644
--- a/Src/params.c
+++ b/Src/params.c
@@ -3068,7 +3068,7 @@ check_warn_pm(Param pm, const char *pmtype, int created,
     } else
 	return;
 
-    if (pm->node.flags & PM_SPECIAL)
+    if (pm->node.flags & (PM_SPECIAL|PM_NAMEREF))
 	return;
 
     for (i = funcstack; i; i = i->prev) {
@@ -6181,6 +6181,7 @@ setloopvar(char *name, char *value)
   if (pm && (pm->node.flags & PM_NAMEREF)) {
       pm->base = pm->width = 0;
       pm->u.str = ztrdup(value);
+      pm->node.flags &= ~PM_UNSET;
       pm->node.flags |= PM_NEWREF;
       setscope(pm);
       pm->node.flags &= ~PM_NEWREF;
@@ -6248,7 +6249,7 @@ setscope(Param pm)
 		      pm->node.nam);
 		unsetparam_pm(pm, 0, 1);
 	    } else if (isset(WARNNESTEDVAR))
-		zwarn("%s: global reference to local variable: %s",
+		zwarn("reference %s in enclosing scope set to local variable %s",
 		      pm->node.nam, pm->u.str);
 	}
 	if (pm->u.str && upscope(pm, pm->base) == pm &&
diff --git a/Test/K01nameref.ztst b/Test/K01nameref.ztst
index d240e4917..6a5e767df 100644
--- a/Test/K01nameref.ztst
+++ b/Test/K01nameref.ztst
@@ -532,6 +532,13 @@ F:Same test, should part 5 output look like this?
 >nameref-local-nameref-local
 >typeset parameters
 
+ if [[ $options[typesettounset] != on ]]; then
+   ZTST_skip='Ignoring zmodload bug that resets TYPESET_TO_UNSET'
+   setopt typesettounset
+ fi
+0:options reloaded
+F:Checking for a bug in zmodload that affects later tests
+
  typeset ptr2=var2
  typeset var2=GLOBAL
  () {
@@ -541,7 +548,7 @@ F:Same test, should part 5 output look like this?
    typeset var2=VAR2
    print -r -- ${(P)ptr1}
  }
-0:
+0:Order of evaluation with ${(P)...}
 >VAR2
 
  ary=(one two three four)
@@ -666,7 +673,19 @@ F:Same test, should part 5 output look like this?
 >
 >scalar-local
 >
-*?*ref: global reference to local variable: one
+*?*reference ref*to local variable one
+
+ unset -n ref
+ typeset -n ref
+ () {
+   setopt localoptions warn_nested_var
+   typeset inner
+   ref=inner
+ }
+ typeset -p ref
+0:Global variable is a reference, warning
+>typeset -n ref=inner
+*?*reference ref*to local variable inner
 
  typeset -n ptr='ary[$(echo 2)]'
  typeset -a ary=(one two three)

  reply	other threads:[~2023-02-15  1:40 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-14  2:08 Bart Schaefer
2023-02-14 14:46 ` Peter Stephenson
2023-02-14 16:14   ` Bart Schaefer
2023-02-14 16:36     ` Peter Stephenson
2023-02-14 20:00       ` Bart Schaefer
2023-02-15  1:39         ` Bart Schaefer [this message]
2023-02-16 15:29           ` zmodload (-u?) changing options (was Re: [PATCH] Named reference typos & misc.) Bart Schaefer
2023-02-16 15:52             ` Peter Stephenson
2023-02-16 18:17               ` Bart Schaefer
2023-02-16 19:28                 ` Bart Schaefer
2023-02-16 23:10                 ` Bart Schaefer
2023-02-21 11:47                 ` Peter Stephenson
2023-02-21 12:11                   ` Peter Stephenson
2023-02-21 15:57                     ` Bart Schaefer
2023-02-15 10:12         ` [PATCH] Named reference typos & misc Peter Stephenson
2023-02-15 10:36           ` Peter Stephenson
2023-02-15 14:58             ` 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=7Yp3O+n5M_G5JkdUBXegz_EpzjCXe54rWoqUv+++xL84A@mail.gmail.com' \
    --to=schaefer@brasslantern.com \
    --cc=p.w.stephenson@ntlworld.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).