From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from primenet.com.au (ns1.primenet.com.au [203.24.36.2]) by inbox.vuxu.org (OpenSMTPD) with ESMTP id b2fae34b for ; Wed, 24 Jul 2019 05:13:18 +0000 (UTC) Received: (qmail 23989 invoked by alias); 24 Jul 2019 05:13:11 -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: List-Unsubscribe: X-Seq: 44568 Received: (qmail 12154 invoked by uid 1010); 24 Jul 2019 05:13:11 -0000 X-Qmail-Scanner-Diagnostics: from mail-wm1-f52.google.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.101.2/25517. spamassassin: 3.4.2. Clear:RC:0(209.85.128.52):SA:0(-2.0/5.0):. Processed in 0.815171 secs); 24 Jul 2019 05:13:11 -0000 X-Envelope-From: stephane.chazelas@gmail.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: pass (ns1.primenet.com.au: SPF record at _netblocks.google.com designates 209.85.128.52 as permitted sender) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:mail-followup-to:references :mime-version:content-disposition:in-reply-to:user-agent; bh=+4M0t/xsF17lYbFidCLtUNUO0zP/ezdpu6o141CVuqY=; b=SfJQvYFfMqBz5mbtgPQAx1+uVLxDc5BF9j2qn/CJa9W0voU58pHQgIkYjrWil1Ggtx BNjC0Dl028lQHAXhvDWu9yfO+06OScOqgg1lLqr8EZevZHtN3ROd8wkJykSLe/9TPWf4 nZd4qlVrHevyrdT47muVvhgNxUAbIZNk7YfIxT4pqqSMzAtr83LhWU+TYIdLU5enF3DD ZaKYlDdJWiwHBQj4muBebaEyT2KPf7dGLRzoadNsig4dmfmk8zSlkdppFTMAZkvgUnRp kS9UkOYU00m4HnTsdNIo1suWBdLc+MipVAS5qUT/r0UjYkQDTsLyQjpbvtDUdSlRVRG+ XzSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id :mail-followup-to:references:mime-version:content-disposition :in-reply-to:user-agent; bh=+4M0t/xsF17lYbFidCLtUNUO0zP/ezdpu6o141CVuqY=; b=GA03Xmbw+YnRD02pVkLHnSaOFRmS5RiXyGtMTYuA17LRnTLqh2PhrwDO3BqYpBM9BJ ISMHXe4MJ/K5izpuaqptUPskGdZYAUt8NQpfgbRlmtCZ9YkQHh5AutOQSzg+f0mgXzrH gDCveGt9npXrOmBnP13LbUee8k6qWQihoVByGVL/39NvnZUkCsgJfLBk9hIDxkfX4Mrm gK+xfXjdQGJwHAqFPgvrpyEP1oTl1c7v/bZH0Sq28LfVSoIjTpQG9lYrIlRtdVnVnpXW 7j50zfAw2mXtq+8lQmejIrxTyYW/Hnp9fM+Tcogd+h0Js+EYkI9W3rw8qff4U7/VaFEw mKoA== X-Gm-Message-State: APjAAAVfYxRuPdv4tXt3PJh7hSzql0IheUxSdHRsvJ0SEYnitJggGlTg yG0sMVCEl+0tAXyrUCngfEs= X-Google-Smtp-Source: APXvYqzZ5ku0+WahH3CWqk3WzPuqr2dVeR9jrZ5tepX+3TpbPsrBPS4OnAfP1NfbhZQ1MCAjNSuMow== X-Received: by 2002:a7b:c106:: with SMTP id w6mr75953894wmi.80.1563945156518; Tue, 23 Jul 2019 22:12:36 -0700 (PDT) Date: Wed, 24 Jul 2019 06:12:34 +0100 From: Stephane Chazelas To: Sebastian Gniazdowski Cc: Zsh hackers list Subject: Re: [bug] Math evaluation done twice in subscript in specific conditions Message-ID: <20190724051234.5yky2pd5pxv5z3lu@chaz.gmail.com> Mail-Followup-To: Sebastian Gniazdowski , Zsh hackers list References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20171215 2019-07-24 01:50:23 +0200, Sebastian Gniazdowski: [...] > idx=0 > a=() > : ${a[++idx]::=$idx} > print -rl $a > -> 1 > : ${a[++idx]::=$idx} > print -rl $a > -> 1 > -> 3 > idx=1 > : ${a[++idx]::=$idx} > print -rl $a > -> 1 > -> 2 > -> 3 > > So apparently the assignment to idx does change something for the > following ::= "call" and makes it work correctly. The second and > following ::= calls cause $idx to increment twice. [...] It is increased by 2 on the first one as well: $ i=0 a=() $ : ${a[++i]::=$i}; echo $i $a 2 1 $ : ${a[++i]::=$i}; echo $i $a 4 1 3 With: $ i='psvar[0`uname>&2`]' $ : ${a[i]} Linux $ : ${a[i]::=} Linux Linux zsh: a: assignment to invalid subscript range So the extra evaluation of the indice is done *before* the assignment it would seem. $ echo ${a[i]:=x} Linux Linux zsh: a: assignment to invalid subscript range It makes more sense in that latter case where I imaging a[i] is dereferenced first to check if it's empty or not, and then the indice is computed again upon assignment. -- Stephane