Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: LOCAL_VARS option ?
On Wed, 25 Jan 2017 05:50:09 +0000
Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx> wrote:
> This case seems to be a false positive:
>
> % () { typeset -A a; : ${a[hello world]::=foo} }
> (anon): scalar parameter hello world set in enclosing scope in function (anon)
There's a bogus parameter created for assistance in this case. I didn't
see what was going on so I didn't turn off the new warning.
By the way, you won't get a warning in a case like this:
() {
local var=(one two)
() { var[3]=three; }
print $var
}
which is probably OK because setting an element of something already
presupposes it exists. The WARN_CREATE_GLOBAL equivalent does operate
here, so you're protected if it doesn't exist. You also get a warning
if you trash the whole array:
() {
local var=(one two)
() { var=(three); }
print $var
}
However, you don't get a warning if you change the array to something
else:
() {
local var=(one two)
() { var=three; }
print $var
}
That's a crucial case for protecting against problems and needs looking
at in the tortuous type conversion logic.
pws
diff --git a/Src/params.c b/Src/params.c
index ebdd252..a629cf4 100644
--- a/Src/params.c
+++ b/Src/params.c
@@ -2926,7 +2926,11 @@ assignsparam(char *s, char *val, int flags)
unqueue_signals();
return NULL;
}
- flags &= ~ASSPM_WARN_CREATE;
+ /*
+ * Parameter defined here is a temporary bogus one.
+ * Don't warn about anything.
+ */
+ flags &= ~ASSPM_WARN;
}
*ss = '[';
v = NULL;
diff --git a/Test/E01options.ztst b/Test/E01options.ztst
index bcd89f7..fd3263a 100644
--- a/Test/E01options.ztst
+++ b/Test/E01options.ztst
@@ -1188,6 +1188,21 @@
?fn_wnv:20: numeric parameter foo5 set in enclosing scope in function fn_wnv
?all off again
+
+ (
+ setopt warnnestedvar
+ () {
+ typeset -A a
+ : ${a[hello world]::=foo}
+ print ${(t)a}
+ key="hello world"
+ print $a[$key]
+ }
+ )
+0:No false positive on parameter used with subscripted assignment
+>association-local
+>foo
+
# 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