From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1397 invoked by alias); 25 Jun 2015 15:39:54 -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: 35604 Received: (qmail 17065 invoked from network); 25 Jun 2015 15:39:52 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS autolearn=ham autolearn_force=no version=3.4.0 X-AuditID: cbfec7f5-f794b6d000001495-5f-558c20c38b95 Date: Thu, 25 Jun 2015 16:39:32 +0100 From: Peter Stephenson To: Zsh Hackers' List Subject: Re: Typeset with array Message-id: <20150625163932.0ca086c8@pwslap01u.europe.root.pri> In-reply-to: <150625081653.ZM20153@torch.brasslantern.com> References: <5578996E.3080700@thequod.de> <150610191427.ZM30841@torch.brasslantern.com> <5579C247.1060800@thequod.de> <150611183639.ZM32247@torch.brasslantern.com> <20150612094237.338f79d5@pwslap01u.europe.root.pri> <20150619123930.2688d9e3@pwslap01u.europe.root.pri> <7337.1434735386@thecus.kiddle.eu> <20150625102923.1dc227ff@pwslap01u.europe.root.pri> <150625081653.ZM20153@torch.brasslantern.com> Organization: Samsung Cambridge Solution Centre X-Mailer: Claws Mail 3.7.9 (GTK+ 2.22.0; i386-redhat-linux-gnu) MIME-version: 1.0 Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrMLMWRmVeSWpSXmKPExsVy+t/xK7qHFXpCDXbsN7U42PyQyYHRY9XB D0wBjFFcNimpOZllqUX6dglcGbsnTmMumC5Ucev2EZYGxqu8XYycHBICJhJPp3xghbDFJC7c W88GYgsJLGWUuLDStouRC8iewSRxef9iZghnG6PE3u417CBVLAKqEl9+TmIBsdkEDCWmbprN 2MXIwSEioC3R/lEMJCwsIC+x++R+ZhCbV8BeYtbVXrBlnAJWEg0felkgZs5jlph+cinYHH4B fYmrfz8xQVxkLzHzyhlGiGZBiR+T74HVMAtoSWze1sQKYctLbF7zlhnianWJG3d3s09gFJqF pGUWkpZZSFoWMDKvYhRNLU0uKE5KzzXSK07MLS7NS9dLzs/dxAgJ2q87GJceszrEKMDBqMTD W2HbHSrEmlhWXJl7iFGCg1lJhHexeE+oEG9KYmVValF+fFFpTmrxIUZpDhYlcd6Zu96HCAmk J5akZqemFqQWwWSZODilGhinPfjBV6OaKLvCb7vv7sNedSabf/xkLTOOEnsmcdbj/A6vP8d5 Dh90XbnL4FGOYelr7e66j+/swo8/Cr1uwPt5qvuVyXXHU+e8yFz7vSb90kEp4+lHuN/a/A6/ wrHro45W6psTCzvu6xyWaT18J3vfv9uPZVJfy1upLQiWDuOvk8/oUC15Ma1PiaU4I9FQi7mo OBEATRhrNVYCAAA= On Thu, 25 Jun 2015 08:16:53 -0700 > Some quick tests: > > torch% typeset var var[2]=two > torch% typeset -p var > typeset var=two That's correct: var is created then manipulated as a scalar. Apart from localness this is the same effect as var= var[2]=two > torch% typeset -a array array[2]=two > typeset: array[2]: inconsistent type for assignment > torch% typeset -p array > typeset -a array > array=() That's also correct. typeset -a creates arrays, so "array" is successfully created; however, array[2] is a scalar with a scalar assignment, so that's an error with the "-a". (However, if you think you can work out how to relax the test to allow array elements without the whole thing blowing up in your face, be my guest...) > torch% typeset newarray=() newarray[2]=two That's the right way to mix arrays and scalars... > zsh: segmentation fault (core dumped) Src/zsh -f ..so, as it happens, that's not correct. That reminds me of something else I meant to test... diff --git a/Src/exec.c b/Src/exec.c index 57e8f63..50a11eb 100644 --- a/Src/exec.c +++ b/Src/exec.c @@ -3583,15 +3583,18 @@ execcmd(Estate state, int input, int output, int how, int last1) asg->value.array = ecgetlist(state, WC_ASSIGN_NUM(ac), EC_DUPTOK, &htok); - prefork(asg->value.array, PREFORK_ASSIGN); - if (errflag) { - state->pc = opc; - break; - } - globlist(asg->value.array, 0); - if (errflag) { - state->pc = opc; - break; + if (asg->value.array) + { + prefork(asg->value.array, PREFORK_ASSIGN); + if (errflag) { + state->pc = opc; + break; + } + globlist(asg->value.array, 0); + if (errflag) { + state->pc = opc; + break; + } } } diff --git a/Test/B02typeset.ztst b/Test/B02typeset.ztst index e6285bc..1548b81 100644 --- a/Test/B02typeset.ztst +++ b/Test/B02typeset.ztst @@ -663,3 +663,16 @@ >fn2 () { > typeset assignfirst=(why not) >} + + fn() { + typeset array=() + print ${(t)array} ${#array} + typeset gnothergarray=() gnothergarray[1]=yes gnothergarray[2]=no + print -l ${(t)gnothergarray} $gnothergarray + } + fn +0:can set empty array +>array-local 0 +>array-local +>yes +>no