1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-09-16 02:32:11 +02:00

40423: WARN_NESTED_VARS, conversion the other way

This commit is contained in:
Peter Stephenson 2017-01-26 20:07:51 +00:00
parent 80e47a9a5d
commit 1633b2800d
3 changed files with 24 additions and 9 deletions

View file

@ -1,5 +1,8 @@
2017-01-26 Peter Stephenson <p.w.stephenson@ntlworld.com> 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 * 40422: Src/params.c, Test/E01options.ztst: more
WARN_NESTED_VAR cases that were broken in the original patch. WARN_NESTED_VAR cases that were broken in the original patch.

View file

@ -3048,6 +3048,7 @@ assignaparam(char *s, char **val, int flags)
Value v; Value v;
char *t = s; char *t = s;
char *ss; char *ss;
int created = 0;
if (!isident(s)) { if (!isident(s)) {
zerr("not an identifier: %s", s); zerr("not an identifier: %s", s);
@ -3058,10 +3059,10 @@ assignaparam(char *s, char **val, int flags)
queue_signals(); queue_signals();
if ((ss = strchr(s, '['))) { if ((ss = strchr(s, '['))) {
*ss = '\0'; *ss = '\0';
if (!(v = getvalue(&vbuf, &s, 1))) if (!(v = getvalue(&vbuf, &s, 1))) {
createparam(t, PM_ARRAY); createparam(t, PM_ARRAY);
else created = 1;
flags &= ~ASSPM_WARN_CREATE; }
*ss = '['; *ss = '[';
if (v && PM_TYPE(v->pm->node.flags) == PM_HASHED) { if (v && PM_TYPE(v->pm->node.flags) == PM_HASHED) {
unqueue_signals(); unqueue_signals();
@ -3073,9 +3074,10 @@ assignaparam(char *s, char **val, int flags)
} }
v = NULL; v = NULL;
} else { } else {
if (!(v = fetchvalue(&vbuf, &s, 1, SCANPM_ASSIGNING))) if (!(v = fetchvalue(&vbuf, &s, 1, SCANPM_ASSIGNING))) {
createparam(t, PM_ARRAY); 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))) { !(v->pm->node.flags & (PM_SPECIAL|PM_TIED))) {
int uniq = v->pm->node.flags & PM_UNIQUE; int uniq = v->pm->node.flags & PM_UNIQUE;
if (flags & ASSPM_AUGMENT) { if (flags & ASSPM_AUGMENT) {
@ -3093,8 +3095,6 @@ assignaparam(char *s, char **val, int flags)
createparam(t, PM_ARRAY | uniq); createparam(t, PM_ARRAY | uniq);
v = NULL; v = NULL;
} }
else
flags &= ~ASSPM_WARN_CREATE;
} }
if (!v) if (!v)
if (!(v = fetchvalue(&vbuf, &t, 1, SCANPM_ASSIGNING))) { if (!(v = fetchvalue(&vbuf, &t, 1, SCANPM_ASSIGNING))) {
@ -3105,7 +3105,7 @@ assignaparam(char *s, char **val, int flags)
} }
if (flags & ASSPM_WARN) 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 (flags & ASSPM_AUGMENT) {
if (v->start == 0 && v->end == -1) { if (v->start == 0 && v->end == -1) {
if (PM_TYPE(v->pm->node.flags) & PM_ARRAY) { if (PM_TYPE(v->pm->node.flags) & PM_ARRAY) {

View file

@ -1211,10 +1211,22 @@
print $var 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) ?(anon): scalar parameter var set in enclosing scope in function (anon)
>three >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. # This really just tests if XTRACE is egregiously broken.
# To test it properly would need a full set of its own. # To test it properly would need a full set of its own.
fn() { print message; } fn() { print message; }