about summary refs log tree commit diff
diff options
context:
space:
mode:
authorBart Schaefer <schaefer@zsh.org>2023-02-14 17:54:42 -0800
committerBart Schaefer <schaefer@zsh.org>2023-02-14 17:54:42 -0800
commit32cceefa95903190829af26723b7ad51c163040c (patch)
tree08fb3d46e4ae86001181549988b0fb64256e916c
parent7e0c4406ceba1e021bf37680d6a6b8dcd3dd657f (diff)
downloadzsh-32cceefa95903190829af26723b7ad51c163040c.tar.gz
zsh-32cceefa95903190829af26723b7ad51c163040c.tar.xz
zsh-32cceefa95903190829af26723b7ad51c163040c.zip
51437: Fix incorrectly-passed test case, masked by unrelated bug.
A bug with zmodload when unloading/reloading a static module caused the
state of the shell options to change during K01 test.  Worked around it.
Also changed warnnestedvar messages to look more like other such.
-rw-r--r--ChangeLog5
-rw-r--r--Src/params.c5
-rw-r--r--Test/K01nameref.ztst23
3 files changed, 29 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index b490b0ee8..9e7608293 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2023-02-14  Bart Schaefer  <schaefer@zsh.org>
+
+	* 51437: Src/params.c, Test/K01nameref.ztst: Fix incorrectly-passed
+	test case, masked by unrelated bug.  Improve warnnestedvar message.
+
 2023-02-14  Peter Stephenson  <p.stephenson@samsung.com>
 
 	* 51425: Src/exec.c, Test/E01OPTIONS: $(<...) shouldn't try to
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)