about summary refs log tree commit diff
diff options
context:
space:
mode:
authordana <dana@dana.is>2017-12-10 12:17:30 -0600
committerPeter Stephenson <p.stephenson@samsung.com>2018-05-11 09:29:14 +0100
commit805192311f3426b852026b03e8ca4b421189fcf1 (patch)
treee1c82fd71cb3ae4e79cdef83d9653b2484851dbc
parentfa441fa20e6d7d93e613f339d0c67ba8b0ab09c4 (diff)
downloadzsh-805192311f3426b852026b03e8ca4b421189fcf1.tar.gz
zsh-805192311f3426b852026b03e8ca4b421189fcf1.tar.xz
zsh-805192311f3426b852026b03e8ca4b421189fcf1.zip
42101 (tweaked): assigning shell status to array was broken
-rw-r--r--ChangeLog7
-rw-r--r--Src/exec.c8
-rw-r--r--Test/A06assign.ztst35
3 files changed, 48 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index 325638c30..c05b9e06c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2018-05-11  Peter Stephenson  <p.stephenson@samsung.com>
+
+	* 42101 (tweaked): dana: Src/exec.c, Test/A06assign.ztst:
+	assigning shell status to array was broken.
+
+	* Src/exec.c (execcmd_exec): 
+
 2018-05-08  Peter Stephenson  <p.stephenson@samsung.com>
 
 	* 42752: Completion/Unx/Command/_git: better completion
diff --git a/Src/exec.c b/Src/exec.c
index 08c4ea95a..963b0a5c3 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -2750,7 +2750,7 @@ execcmd_exec(Estate state, Execcmd_params eparams,
     char *text;
     int save[10];
     int fil, dfil, is_cursh, do_exec = 0, redir_err = 0, i;
-    int nullexec = 0, magic_assign = 0, forked = 0;
+    int nullexec = 0, magic_assign = 0, forked = 0, old_lastval;
     int is_shfunc = 0, is_builtin = 0, is_exec = 0, use_defpath = 0;
     /* Various flags to the command. */
     int cflags = 0, orig_cflags = 0, checked = 0, oautocont = -1;
@@ -2775,6 +2775,7 @@ execcmd_exec(Estate state, Execcmd_params eparams,
      * If assignment but no command get the status from variable
      * assignment.
      */
+    old_lastval = lastval;
     if (!args && varspc)
 	lastval = errflag ? errflag : cmdoutval;
     /*
@@ -3209,8 +3210,11 @@ execcmd_exec(Estate state, Execcmd_params eparams,
 			return;
 		    }
 		    cmdoutval = use_cmdoutval ? lastval : 0;
-		    if (varspc)
+		    if (varspc) {
+			/* Make sure $? is still correct for assignment */
+			lastval = old_lastval;
 			addvars(state, varspc, 0);
+		    }
 		    if (errflag)
 			lastval = 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
 
+# tests of array assignment using lastval ($?)
+
+  true
+  array=( $? )
+  print $array
+0:Assign $? to array (true)
+>0
+
+  false
+  array=( $? )
+  print $array
+0:Assign $? to array (false)
+>1
+
+  true
+  typeset array=( $? )
+  print $array
+0:Assign $? to array with typeset (true)
+>0
+
+  false
+  typeset array=( $? )
+  print $array
+0:Assign $? to array with typeset (false)
+>1
+
+  array=( )
+  true
+  array+=( $? )
+  false
+  array+=( $? )
+  print $array
+0:Append $? to array (true+false)
+>0 1
+
 # tests of var+=scalar
 
  s+=foo