diff options
author | Peter Stephenson <p.w.stephenson@ntlworld.com> | 2017-01-26 20:07:51 +0000 |
---|---|---|
committer | Peter Stephenson <p.w.stephenson@ntlworld.com> | 2017-01-26 20:07:51 +0000 |
commit | 1633b2800d3679e3b89a34bcafa03956ed310b61 (patch) | |
tree | 659a062a025de5c72af269f3e86d9a8015afeab4 | |
parent | 80e47a9a5d0db57dfbf90af6d2b892c8a1b0d36b (diff) | |
download | zsh-1633b2800d3679e3b89a34bcafa03956ed310b61.tar.gz zsh-1633b2800d3679e3b89a34bcafa03956ed310b61.tar.xz zsh-1633b2800d3679e3b89a34bcafa03956ed310b61.zip |
40423: WARN_NESTED_VARS, conversion the other way
-rw-r--r-- | ChangeLog | 3 | ||||
-rw-r--r-- | Src/params.c | 16 | ||||
-rw-r--r-- | Test/E01options.ztst | 14 |
3 files changed, 24 insertions, 9 deletions
diff --git a/ChangeLog b/ChangeLog index feff6f349..272311ca3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2017-01-26 Peter Stephenson <p.w.stephenson@ntlworld.com> + * 40423: Src/params.c, Test/E01options.ztst: similar for type + conversion the other way. + * 40422: Src/params.c, Test/E01options.ztst: more WARN_NESTED_VAR cases that were broken in the original patch. diff --git a/Src/params.c b/Src/params.c index 45b37cb4f..a8d4f50f4 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 c265d78d8..343d5a9c1 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; } |