zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.w.stephenson@ntlworld.com>
To: zsh-workers@zsh.org
Subject: Re: LOCAL_VARS option ?
Date: Thu, 26 Jan 2017 20:04:58 +0000	[thread overview]
Message-ID: <20170126200458.259122e2@ntlworld.com> (raw)
In-Reply-To: <20170126194328.5aa3d79d@ntlworld.com>

On Thu, 26 Jan 2017 19:43:28 +0000
Peter Stephenson <p.w.stephenson@ntlworld.com> wrote:
> This wasn't particularly tortuous, simply that when I extended the
> create warning logic I handled this one rather badly.

There's more!

diff --git a/Src/params.c b/Src/params.c
index 45b37cb..a8d4f50 100644
--- a/Src/params.c
+++ b/Src/params.c
@@ -3048,6 +3048,7 @@ assignaparam(char *s, char **val, int flags)
     Value v;
     char *t = s;
     char *ss;
+    int created = 0;
 
     if (!isident(s)) {
 	zerr("not an identifier: %s", s);
@@ -3058,10 +3059,10 @@ assignaparam(char *s, char **val, int flags)
     queue_signals();
     if ((ss = strchr(s, '['))) {
 	*ss = '\0';
-	if (!(v = getvalue(&vbuf, &s, 1)))
+	if (!(v = getvalue(&vbuf, &s, 1))) {
 	    createparam(t, PM_ARRAY);
-	else
-	    flags &= ~ASSPM_WARN_CREATE;
+	    created = 1;
+	}
 	*ss = '[';
 	if (v && PM_TYPE(v->pm->node.flags) == PM_HASHED) {
 	    unqueue_signals();
@@ -3073,9 +3074,10 @@ assignaparam(char *s, char **val, int flags)
 	}
 	v = NULL;
     } else {
-	if (!(v = fetchvalue(&vbuf, &s, 1, SCANPM_ASSIGNING)))
+	if (!(v = fetchvalue(&vbuf, &s, 1, SCANPM_ASSIGNING))) {
 	    createparam(t, PM_ARRAY);
-	else if (!(PM_TYPE(v->pm->node.flags) & (PM_ARRAY|PM_HASHED)) &&
+	    created = 1;
+	} else if (!(PM_TYPE(v->pm->node.flags) & (PM_ARRAY|PM_HASHED)) &&
 		 !(v->pm->node.flags & (PM_SPECIAL|PM_TIED))) {
 	    int uniq = v->pm->node.flags & PM_UNIQUE;
 	    if (flags & ASSPM_AUGMENT) {
@@ -3093,8 +3095,6 @@ assignaparam(char *s, char **val, int flags)
 	    createparam(t, PM_ARRAY | uniq);
 	    v = NULL;
 	}
-	else
-	    flags &= ~ASSPM_WARN_CREATE;
     }
     if (!v)
 	if (!(v = fetchvalue(&vbuf, &t, 1, SCANPM_ASSIGNING))) {
@@ -3105,7 +3105,7 @@ assignaparam(char *s, char **val, int flags)
 	}
 
     if (flags & ASSPM_WARN)
-	check_warn_pm(v->pm, "array", flags & ASSPM_WARN_CREATE);
+	check_warn_pm(v->pm, "array", created);
     if (flags & ASSPM_AUGMENT) {
     	if (v->start == 0 && v->end == -1) {
 	    if (PM_TYPE(v->pm->node.flags) & PM_ARRAY) {
diff --git a/Test/E01options.ztst b/Test/E01options.ztst
index c265d78..343d5a9 100644
--- a/Test/E01options.ztst
+++ b/Test/E01options.ztst
@@ -1211,10 +1211,22 @@
       print $var
     }
   )
-0:Warn when changing type of nested variable.
+0:Warn when changing type of nested variable: array to scalar.
 ?(anon): scalar parameter var set in enclosing scope in function (anon)
 >three
 
+  (
+    setopt warnnestedvar
+    () {
+      local var=three
+      () { var=(one two); }
+      print $var
+    }
+  )
+0:Warn when changing type of nested variable: scalar to array.
+?(anon): array parameter var set in enclosing scope in function (anon)
+>one two
+
 # This really just tests if XTRACE is egregiously broken.
 # To test it properly would need a full set of its own.
   fn() { print message; }


      reply	other threads:[~2017-01-26 20:05 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20170119070023epcas3p17d787fb31e7c04d5bcf2231020769b5f@epcas3p1.samsung.com>
2017-01-19  6:54 ` Daniel Shahaf
2017-01-19  9:43   ` Jens Elkner
2017-01-19  9:45   ` Peter Stephenson
2017-01-19 15:47   ` Bart Schaefer
2017-01-19 16:08     ` Peter Stephenson
2017-01-20  5:01       ` Bart Schaefer
2017-01-20 17:19         ` Peter Stephenson
2017-01-22 18:45           ` Bart Schaefer
2017-01-22 19:00             ` Peter Stephenson
2017-01-23 10:09               ` Peter Stephenson
2017-01-23 11:20                 ` Daniel Shahaf
2017-01-23 11:37                   ` Peter Stephenson
2017-01-25  5:50                   ` Daniel Shahaf
2017-01-25  9:24                     ` Peter Stephenson
2017-01-25 19:32                       ` Daniel Shahaf
2017-01-25 21:50                         ` Bart Schaefer
2017-01-29 21:21                           ` Daniel Shahaf
2017-01-26 19:43                       ` Peter Stephenson
2017-01-26 20:04                         ` Peter Stephenson [this message]

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=20170126200458.259122e2@ntlworld.com \
    --to=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).