From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28997 invoked by alias); 10 Dec 2017 18:17:42 -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: 42101 Received: (qmail 1094 invoked by uid 1010); 10 Dec 2017 18:17:42 -0000 X-Qmail-Scanner-Diagnostics: from mail-it0-f48.google.com 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(209.85.214.48):SA:0(-1.9/5.0):. Processed in 6.837881 secs); 10 Dec 2017 18:17:42 -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.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_PASS,T_DKIM_INVALID autolearn=ham autolearn_force=no version=3.4.1 X-Envelope-From: dana@dana.is X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dana-is.20150623.gappssmtp.com; s=20150623; h=from:content-transfer-encoding:mime-version:subject:message-id:date :to; bh=vWN1ksuqVkSOpoCdrqXOU8nFZsXpzJZvvODnnEBs1qU=; b=NN7+csTZR9lWuWSQ8+Xg6n89/8mLYMhPWZPKNq1HSburjD3u6urwxOCVnPHN7JIiIY m2Asp/TiEza3Ohv+61Fhj11WPVP0c1+cxq8G3IU3/vh9iV4BvSIDxAJI99RviIgprBwD QzO1me8QLAAwr+5GCXLIJjfaNe7gm+Y4BD5+y8PYbm2eCbfbYOc41DvX+vGPPI/wfphd vrJ1DibpOYe8d9/RpYlwVYFB5oXrAwb1mOlbwxuXe3u3d9QMpi+ADIiKrviF2P7m+DW8 Kazex+dbbpNyHoHuVdJ43GKTTkzVJyzpHeSW+YCiuKjzHqKAUtLS4Zi1ozg3wY+cDIMT qsxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:content-transfer-encoding:mime-version :subject:message-id:date:to; bh=vWN1ksuqVkSOpoCdrqXOU8nFZsXpzJZvvODnnEBs1qU=; b=g11tG5YmlQ7lUuL5T9Zy753JHa5lEQhJDi+E08Ngrtb/PwN62VaNmURnL/FV5U02+P 8GVLUBwOlYDZ0tmheJ089ptcCnG+jbLJtWJtfIUXq0+ggDIfUwMgGx7RUuGUnr6Np/mH ms1SRK6ney32JItlY+a0o0GzzjpFD6pthix67xt955BV9go3RL+LIhrKeJfXr0XosS1J da8+fgHLHZtMysffbPgvIasvkl99QI0vaojMjupKeDegZ+LtKn37qIeUiU52imFc/kcF amMMTcOT9Vj+f7JtRTI3OL+ZjsOLpAjwWOYDPDiqXDjH+/rWiwvidhfRPxLspATbzCmh cOfw== X-Gm-Message-State: AKGB3mJIB5eMBLQkuHacPcaUX8KRaqbngkyNYY3OiwQlD/3tNmtepaZL F71LJ4w338WMxDH8tq7/5OpbvbzAlh0= X-Google-Smtp-Source: AGs4zMbsQ24ob30XIAyh32jwaAMZpQ5kkvFQ8KhSWSQQNNnoGy2kB3VHcRHLaCXQ2XLQnX9fHG/4mA== X-Received: by 10.107.18.168 with SMTP id 40mr27990074ios.55.1512929851763; Sun, 10 Dec 2017 10:17:31 -0800 (PST) From: dana Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 (Mac OS X Mail 10.3 \(3273\)) Subject: [PATCH] Fix value of $? when used in array assignment Message-Id: <5AC56AD0-5C94-4218-BCFA-A57C84A054BF@dana.is> Date: Sun, 10 Dec 2017 12:17:30 -0600 To: zsh-workers@zsh.org X-Mailer: Apple Mail (2.3273) Hi again. Daniel discovered the following behaviour: % false; arr=3D( $? ); typeset -p arr typeset -a arr=3D( 0 ) It seems that lastval is discarded before an assignment of this sort is = actually executed. Not sure if it's the most elegant way, but the attached patch fixes it, = and all of the tests pass. I also added some regression tests. dana diff --git a/Src/exec.c b/Src/exec.c index fc6d02dc3..7d94d2cd7 100644 --- a/Src/exec.c +++ b/Src/exec.c @@ -2722,7 +2722,7 @@ execcmd_exec(Estate state, Execcmd_params eparams, char *text; int save[10]; int fil, dfil, is_cursh, do_exec =3D 0, redir_err =3D 0, i; - int nullexec =3D 0, magic_assign =3D 0, forked =3D 0; + int nullexec =3D 0, magic_assign =3D 0, forked =3D 0, old_lastval; int is_shfunc =3D 0, is_builtin =3D 0, is_exec =3D 0, use_defpath =3D= 0; /* Various flags to the command. */ int cflags =3D 0, orig_cflags =3D 0, checked =3D 0, oautocont =3D = -1; @@ -2747,8 +2747,10 @@ execcmd_exec(Estate state, Execcmd_params = eparams, * If assignment but no command get the status from variable * assignment. */ - if (!args && varspc) + if (!args && varspc) { + old_lastval =3D lastval; lastval =3D errflag ? errflag : cmdoutval; + } /* * If there are arguments, we should reset the status for the * command before execution---unless we are using the result of a @@ -3146,8 +3148,11 @@ execcmd_exec(Estate state, Execcmd_params = eparams, return; } cmdoutval =3D use_cmdoutval ? lastval : 0; - if (varspc) + if (varspc) { + /* Make sure $? is still correct for assignment = */ + lastval =3D old_lastval; addvars(state, varspc, 0); + } if (errflag) lastval =3D 1; else diff --git a/Test/A06assign.ztst b/Test/A06assign.ztst index fd2b4177c..f89edb888 100644 --- a/Test/A06assign.ztst +++ b/Test/A06assign.ztst @@ -199,6 +199,41 @@ >a 1 2 3 >a 1 2 3 =20 +# tests of array assignment using lastval ($?) + + true + array=3D( $? ) + print $array +0:Assign $? to array (true) +>0 + + false + array=3D( $? ) + print $array +0:Assign $? to array (false) +>1 + + true + typeset array=3D( $? ) + print $array +0:Assign $? to array with typeset (true) +>0 + + false + typeset array=3D( $? ) + print $array +0:Assign $? to array with typeset (false) +>1 + + array=3D( ) + true + array+=3D( $? ) + false + array+=3D( $? ) + print $array +0:Append $? to array (true+false) +>0 1 + # tests of var+=3Dscalar =20 s+=3Dfoo