about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Stephenson <p.stephenson@samsung.com>2021-05-06 10:03:27 +0100
committerPeter Stephenson <p.stephenson@samsung.com>2021-05-06 10:03:27 +0100
commit9e38ab81785c4ac755a7e78d2fe7a7db92bdf375 (patch)
tree6b9bbcb6fbfd2f987656d837b3f338037086436f
parentc1f932d66896753eb118003b7c1b1139bc6c8725 (diff)
downloadzsh-9e38ab81785c4ac755a7e78d2fe7a7db92bdf375.tar.gz
zsh-9e38ab81785c4ac755a7e78d2fe7a7db92bdf375.tar.xz
zsh-9e38ab81785c4ac755a7e78d2fe7a7db92bdf375.zip
48787: Fix command status after failed if
If "if" had a hard error in the condition, and there was no
else clause, the command status was incorrectly cleared to zero.

Add test.
-rw-r--r--ChangeLog5
-rw-r--r--Src/loop.c2
-rw-r--r--Test/A01grammar.ztst5
3 files changed, 11 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 7dc9cbc6d..9392e39d9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2021-05-06  Peter Stephenson  <p.stephenson@samsung.com>
+
+	* 48787: Src/loop.c, Test/A01grammar.ztst: status was incorrect
+	on hard error flagged by condition in "if" without "else".
+
 2021-05-03  dana  <dana@dana.is>
 
 	* unposted (see 48613): Etc/FAQ.yo: Move section 3.31 to 2.8
diff --git a/Src/loop.c b/Src/loop.c
index 41b2e5627..aa733a2cb 100644
--- a/Src/loop.c
+++ b/Src/loop.c
@@ -583,7 +583,7 @@ execif(Estate state, int do_exec)
 	cmdpop();
     } else {
 	noerrexit = olderrexit;
-	if (!retflag)
+	if (!retflag && !errflag)
 	    lastval = 0;
     }
     state->pc = end;
diff --git a/Test/A01grammar.ztst b/Test/A01grammar.ztst
index 35a04e7d5..88fc8606e 100644
--- a/Test/A01grammar.ztst
+++ b/Test/A01grammar.ztst
@@ -939,3 +939,8 @@ F:Note that the behaviour of 'exit' inside try-list inside a function is unspeci
  $ZTST_testdir/../Src/zsh -fc '{ ( ) } always { echo foo }'
 0:exec last command optimization inhibited for try/always
 >foo
+
+ a='${'
+ if : ${(e)a}; then echo x; fi
+1:Status on bad substitution in if without else
+?(eval):2: bad substitution