Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: [bug] Math evaluation done twice in subscript in specific conditions
- X-seq: zsh-workers 44568
- From: Stephane Chazelas <stephane.chazelas@xxxxxxxxx>
- To: Sebastian Gniazdowski <sgniazdowski@xxxxxxxxx>
- Subject: Re: [bug] Math evaluation done twice in subscript in specific conditions
- Date: Wed, 24 Jul 2019 06:12:34 +0100
- Cc: Zsh hackers list <zsh-workers@xxxxxxx>
- 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==
- In-reply-to: <CAKc7PVBZa=G0D1v4u9=257O20N85r26HWmjtpxVrNvfoUp-PSQ@mail.gmail.com>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- List-unsubscribe: <mailto:zsh-workers-unsubscribe@zsh.org>
- Mail-followup-to: Sebastian Gniazdowski <sgniazdowski@xxxxxxxxx>, Zsh hackers list <zsh-workers@xxxxxxx>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <CAKc7PVBZa=G0D1v4u9=257O20N85r26HWmjtpxVrNvfoUp-PSQ@mail.gmail.com>
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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author