From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19977 invoked by alias); 27 Nov 2014 23:01:33 -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: 33816 Received: (qmail 16303 invoked from network); 27 Nov 2014 23:01:32 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 X-CMAE-Score: 0 X-CMAE-Analysis: v=2.1 cv=F/vgrRlI c=1 sm=1 tr=0 a=FT8er97JFeGWzr5TCOCO5w==:117 a=kj9zAlcOel0A:10 a=q2GGsy2AAAAA:8 a=oR5dmqMzAAAA:8 a=-9mUelKeXuEA:10 a=5y4faFyK3SkA:10 a=Rs4y4ZB2V-HGKyUWdscA:9 a=Jl4F-C7anqAnI8PS:21 a=_1jwf65xDnCaFTQ_:21 a=CjuIK1q_8ugA:10 From: Bart Schaefer Message-id: <141127150036.ZM5089@torch.brasslantern.com> Date: Thu, 27 Nov 2014 15:00:36 -0800 In-reply-to: <141127133833.ZM6853@torch.brasslantern.com> Comments: In reply to Bart Schaefer "Re: Inconsistency of GLOB_ASSIGN" (Nov 27, 1:38pm) References: <141126215725.ZM13054@torch.brasslantern.com> <20141127204349.036d3807@pws-pc.ntlworld.com> <141127133833.ZM6853@torch.brasslantern.com> X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: zsh-workers@zsh.org Subject: Re: Inconsistency of GLOB_ASSIGN MIME-version: 1.0 Content-type: text/plain; charset=us-ascii NOTE: The two patches included in this message are mutually exclusive. Do not attempt to apply both of them on top of one another. On Nov 27, 1:38pm, Bart Schaefer wrote: } } On Nov 27, 8:43pm, Peter Stephenson wrote: } } } } It would be neater always to do an array assignment, in fact, but } } the traditional behaviour is that if there was only one result the } } assignment is scalar } } That's too bad, because making it always be an array assignment is a } lot simpler than figuring out whether the glob expanded to something. So in actuality, not too much different. Below are two patches, pick one ... both need the haswilds() test to preserve the behavior of assigning a non-glob-string-that-looks-like-math to an integer/float. Here is the patch for making the assigment always be an array: --- 8< --- snip --- 8< --- diff --git a/Src/exec.c b/Src/exec.c index 02a8fe3..702b731 100644 --- a/Src/exec.c +++ b/Src/exec.c @@ -2243,8 +2243,11 @@ addvars(Estate state, Wordcode pc, int addflags) state->pc = opc; return; } - if (isset(GLOBASSIGN) || !isstr) + if (!isstr || (isset(GLOBASSIGN) && + haswilds((char *)getdata(firstnode(vl))))) { globlist(vl, 0); + isstr = 0; + } if (errflag) { state->pc = opc; return; --- >8 --- snip --- >8 --- And here is the patch for making the type scalar or array based on how many results got returned: --- 8< --- snip --- 8< --- diff --git a/Src/exec.c b/Src/exec.c index 02a8fe3..2b7c55f 100644 --- a/Src/exec.c +++ b/Src/exec.c @@ -2243,8 +2243,16 @@ addvars(Estate state, Wordcode pc, int addflags) state->pc = opc; return; } - if (isset(GLOBASSIGN) || !isstr) + if (!isstr || (isset(GLOBASSIGN) && + haswilds((char *)getdata(firstnode(vl))))) { globlist(vl, 0); + /* Unset the parameter to force it to be recreated + * as either scalar or array depending on how many + * matches were found for the glob. + */ + if (isset(GLOBASSIGN)) + unsetparam(name); + } if (errflag) { state->pc = opc; return; --- >8 --- snip --- >8 --- All tests (except X02zlevi some of the time) still pass with either of the above, but there may be hidden consequences of each.