Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: LOCAL_VARS option ?
On Thu, 26 Jan 2017 19:43:28 +0000
Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx> 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; }
Messages sorted by:
Reverse Date,
Date,
Thread,
Author