From: Daniel Shahaf <d.s@daniel.shahaf.name>
To: zsh-workers@zsh.org
Subject: Re: LOCAL_VARS option ?
Date: Sun, 29 Jan 2017 21:21:36 +0000 [thread overview]
Message-ID: <20170129212136.GA14893@fujitsu.shahaf.local2> (raw)
In-Reply-To: <alpine.LRH.2.00.1701251347410.4560@toltec.zanshin.com>
[-- Attachment #1: Type: text/plain, Size: 494 bytes --]
Bart Schaefer wrote on Wed, Jan 25, 2017 at 13:50:06 -0800:
> On Wed, 25 Jan 2017, Daniel Shahaf wrote:
>
> > It does warn if the inner function assigns «var[3]=(three)». I suppose
> > it shouldn't, for the same reason as the above case?
>
> It warns in that instance because inserting a slice into an array goes
> through the same code branch as assigning to the array as a whole (IIRC).
> It is probably not possible to selectively suppress this warning.
Patch attached.
Cheers,
Daniel
[-- Attachment #2: 0001-WARN_NESTED_VAR-Don-t-warn-when-assigning-to-a-slice.patch --]
[-- Type: text/x-diff, Size: 3264 bytes --]
>From a97270dbee2e2169ddf99aeb7fc8ac902263a944 Mon Sep 17 00:00:00 2001
From: Daniel Shahaf <d.s@daniel.shahaf.name>
Date: Sun, 29 Jan 2017 21:17:48 +0000
Subject: [PATCH] WARN_NESTED_VAR: Don't warn when assigning to a slice of an
existing array
---
Src/params.c | 19 +++++++++++++------
Test/E01options.ztst | 4 ++++
2 files changed, 17 insertions(+), 6 deletions(-)
diff --git a/Src/params.c b/Src/params.c
index a8d4f50..20abe6a 100644
--- a/Src/params.c
+++ b/Src/params.c
@@ -2866,10 +2866,14 @@ gethkparam(char *s)
/**/
static void
-check_warn_pm(Param pm, const char *pmtype, int created)
+check_warn_pm(Param pm, const char *pmtype, int created,
+ int may_warn_about_nested_vars)
{
Funcstack i;
+ if (!may_warn_about_nested_vars && !created)
+ return;
+
if (created && isset(WARNCREATEGLOBAL)) {
if (locallevel <= forklevel || pm->level != 0)
return;
@@ -2956,7 +2960,7 @@ assignsparam(char *s, char *val, int flags)
return NULL;
}
if (flags & ASSPM_WARN)
- check_warn_pm(v->pm, "scalar", created);
+ check_warn_pm(v->pm, "scalar", created, 1);
if (flags & ASSPM_AUGMENT) {
if (v->start == 0 && v->end == -1) {
switch (PM_TYPE(v->pm->node.flags)) {
@@ -3049,6 +3053,7 @@ assignaparam(char *s, char **val, int flags)
char *t = s;
char *ss;
int created = 0;
+ int may_warn_about_nested_vars = 1;
if (!isident(s)) {
zerr("not an identifier: %s", s);
@@ -3062,6 +3067,8 @@ assignaparam(char *s, char **val, int flags)
if (!(v = getvalue(&vbuf, &s, 1))) {
createparam(t, PM_ARRAY);
created = 1;
+ } else {
+ may_warn_about_nested_vars = 0;
}
*ss = '[';
if (v && PM_TYPE(v->pm->node.flags) == PM_HASHED) {
@@ -3105,7 +3112,7 @@ assignaparam(char *s, char **val, int flags)
}
if (flags & ASSPM_WARN)
- check_warn_pm(v->pm, "array", created);
+ check_warn_pm(v->pm, "array", created, may_warn_about_nested_vars);
if (flags & ASSPM_AUGMENT) {
if (v->start == 0 && v->end == -1) {
if (PM_TYPE(v->pm->node.flags) & PM_ARRAY) {
@@ -3176,7 +3183,7 @@ sethparam(char *s, char **val)
/* errflag |= ERRFLAG_ERROR; */
return NULL;
}
- check_warn_pm(v->pm, "associative array", checkcreate);
+ check_warn_pm(v->pm, "associative array", checkcreate, 1);
setarrvalue(v, val);
unqueue_signals();
return v->pm;
@@ -3241,9 +3248,9 @@ setnparam(char *s, mnumber val)
unqueue_signals();
return NULL;
}
- check_warn_pm(v->pm, "numeric", !was_unset);
+ check_warn_pm(v->pm, "numeric", !was_unset, 1);
} else {
- check_warn_pm(v->pm, "numeric", 0);
+ check_warn_pm(v->pm, "numeric", 0, 1);
}
setnumvalue(v, val);
unqueue_signals();
diff --git a/Test/E01options.ztst b/Test/E01options.ztst
index 343d5a9..2bd4fdb 100644
--- a/Test/E01options.ztst
+++ b/Test/E01options.ztst
@@ -1137,6 +1137,8 @@
(
foo1=global1 foo2=global2 foo3=global3 foo4=global4
integer foo5=5
+ # skip foo6, defined in fn_wnv
+ foo7=(one two)
fn_wnv() {
# warns
foo1=bar1
@@ -1161,6 +1163,8 @@
integer foo6=9
# doesn't warn
(( foo6=10 ))
+ foo7[3]=three
+ foo7[4]=(four)
}
print option off >&2
fn_wnv
next prev parent reply other threads:[~2017-01-29 21:25 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 [this message]
2017-01-26 19:43 ` Peter Stephenson
2017-01-26 20:04 ` Peter Stephenson
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=20170129212136.GA14893@fujitsu.shahaf.local2 \
--to=d.s@daniel.shahaf.name \
--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).