From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15415 invoked by alias); 26 Jan 2017 19:50:35 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 40422 Received: (qmail 17827 invoked from network); 26 Jan 2017 19:50:35 -0000 X-Qmail-Scanner-Diagnostics: from know-smtprelay-omc-7.server.virginmedia.net by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(80.0.253.71):SA:0(-1.2/5.0):. Processed in 1.066758 secs); 26 Jan 2017 19:50:35 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.2 required=5.0 tests=RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.1 X-Envelope-From: p.w.stephenson@ntlworld.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: pass (ns1.primenet.com.au: SPF record at _smtprelay.virginmedia.com designates 80.0.253.71 as permitted sender) X-Originating-IP: [86.21.219.59] X-Spam: 0 X-Authority: v=2.1 cv=SYcKDalu c=1 sm=1 tr=0 a=utowdAHh8RITBM/6U1BPxA==:117 a=utowdAHh8RITBM/6U1BPxA==:17 a=L9H7d07YOLsA:10 a=9cW_t1CCXrUA:10 a=s5jvgZ67dGcA:10 a=kj9zAlcOel0A:10 a=MWUjAzoEKyAA:10 a=hD80L64hAAAA:8 a=nQ9P1E5h2sR0gL4Y2_8A:9 a=CjuIK1q_8ugA:10 a=ImLYxMjnSFIJI1KS7skI:22 Date: Thu, 26 Jan 2017 19:43:28 +0000 From: Peter Stephenson To: zsh-workers@zsh.org Subject: Re: LOCAL_VARS option ? Message-ID: <20170126194328.5aa3d79d@ntlworld.com> In-Reply-To: <20170125092438.215f5a2c@pwslap01u.europe.root.pri> References: <20170119065408.GA5534@fujitsu.shahaf.local2> <20170119160841.354ec75c@pwslap01u.europe.root.pri> <20170120171922.0e0c370d@pwslap01u.europe.root.pri> <20170122190052.327898df@ntlworld.com> <20170123100914.55675852@pwslap01u.europe.root.pri> <20170123112008.GA8944@fujitsu.shahaf.local2> <20170125055009.GA11466@fujitsu.shahaf.local2> <20170125092438.215f5a2c@pwslap01u.europe.root.pri> X-Mailer: Claws Mail 3.11.1 (GTK+ 2.24.28; x86_64-redhat-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Wed, 25 Jan 2017 09:24:38 +0000 Peter Stephenson wrote: > 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. This wasn't particularly tortuous, simply that when I extended the create warning logic I handled this one rather badly. I'll commit this anyway if the message doesn't get out quickly. pws diff --git a/Src/params.c b/Src/params.c index c38f2e0..45b37cb 100644 --- a/Src/params.c +++ b/Src/params.c @@ -2905,7 +2905,7 @@ assignsparam(char *s, char *val, int flags) char *ss, *copy, *var; size_t lvar; mnumber lhs, rhs; - int sstart; + int sstart, created = 0; if (!isident(s)) { zerr("not an identifier: %s", s); @@ -2916,9 +2916,10 @@ assignsparam(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 { + created = 1; + } else { if (v->pm->node.flags & PM_READONLY) { zerr("read-only variable: %s", v->pm->node.nam); *ss = '['; @@ -2935,18 +2936,18 @@ assignsparam(char *s, char *val, int flags) *ss = '['; v = NULL; } else { - if (!(v = getvalue(&vbuf, &s, 1))) + if (!(v = getvalue(&vbuf, &s, 1))) { createparam(t, PM_SCALAR); - else if ((((v->pm->node.flags & PM_ARRAY) && !(flags & ASSPM_AUGMENT)) || + created = 1; + } else if ((((v->pm->node.flags & PM_ARRAY) && !(flags & ASSPM_AUGMENT)) || (v->pm->node.flags & PM_HASHED)) && !(v->pm->node.flags & (PM_SPECIAL|PM_TIED)) && unset(KSHARRAYS)) { unsetparam(t); createparam(t, PM_SCALAR); + /* not regarded as a new creation */ v = NULL; } - else - flags &= ~ASSPM_WARN_CREATE; } if (!v && !(v = getvalue(&vbuf, &t, 1))) { unqueue_signals(); @@ -2955,7 +2956,7 @@ assignsparam(char *s, char *val, int flags) return NULL; } if (flags & ASSPM_WARN) - check_warn_pm(v->pm, "scalar", flags & ASSPM_WARN_CREATE); + check_warn_pm(v->pm, "scalar", created); if (flags & ASSPM_AUGMENT) { if (v->start == 0 && v->end == -1) { switch (PM_TYPE(v->pm->node.flags)) { diff --git a/Test/E01options.ztst b/Test/E01options.ztst index fd3263a..c265d78 100644 --- a/Test/E01options.ztst +++ b/Test/E01options.ztst @@ -1203,6 +1203,18 @@ >association-local >foo + ( + setopt warnnestedvar + () { + local var=(one two) + () { var=three; } + print $var + } + ) +0:Warn when changing type of nested variable. +?(anon): scalar parameter var set in enclosing scope in function (anon) +>three + # This really just tests if XTRACE is egregiously broken. # To test it properly would need a full set of its own. fn() { print message; }