summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--Src/params.c19
-rw-r--r--Test/E01options.ztst4
3 files changed, 22 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index f38a5fe12..10b06a9f1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2017-02-01  Daniel Shahaf  <d.s@daniel.shahaf.name>
+
+	* 40460: Src/params.c, Test/E01options.ztst: WARN_NESTED_VAR:
+	Don't warn when assigning to a slice of an existing array
+
 2017-02-01  Jun-ichi Takimoto <takimoto-j@kba.biglobe.ne.jp>
 
 	* 40470: Test/D07multibyte.ztst: make the test work also on
diff --git a/Src/params.c b/Src/params.c
index a8d4f50f4..20abe6aa6 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 343d5a9c1..2bd4fdb1a 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