zsh-workers
 help / color / mirror / code / Atom feed
* [bug] errexit and cmdsubst after "else"
@ 2020-02-01 17:56 Stephane Chazelas
  2020-02-01 19:28 ` Peter Stephenson
  0 siblings, 1 reply; 2+ messages in thread
From: Stephane Chazelas @ 2020-02-01 17:56 UTC (permalink / raw)
  To: Zsh hackers list

From
https://unix.stackexchange.com/questions/565158/command-substitution-does-not-respect-err-exit-sometimes

$ zsh -ec 'if false; then;else a=$(false); echo $?; fi'
1

expected no output because of errexit.

That seems to be regression. @Gilles there bisected it to
https://sourceforge.net/p/zsh/code/ci/b581c3fece76c87ed86ae9fc704d0fcf208a79d3/

Which seemed to be a fix for a similar bug or regression:
http://www.zsh.org/cgi-bin/mla/redirect?WORKERNUMBER=36766

https://www.zsh.org/mla/workers/2015/msg02685.html

Possibly incomplete.

-- 
Stephane



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [bug] errexit and cmdsubst after "else"
  2020-02-01 17:56 [bug] errexit and cmdsubst after "else" Stephane Chazelas
@ 2020-02-01 19:28 ` Peter Stephenson
  0 siblings, 0 replies; 2+ messages in thread
From: Peter Stephenson @ 2020-02-01 19:28 UTC (permalink / raw)
  To: zsh-workers

On Sat, 2020-02-01 at 17:56 +0000, Stephane Chazelas wrote:
> From
> https://unix.stackexchange.com/questions/565158/command-substitution-does-not-respect-err-exit-sometimes
> 
> $ zsh -ec 'if false; then;else a=$(false); echo $?; fi'
> 1
> 
> expected no output because of errexit.

The following passes all tests; I hope we've been diligent in adding
test cases for previous failures as bug ping pong is a fairly silly
game...

Obviously, please do run any other tests you feel may be relevant (and I
will add them if we don't have them).

pws


diff --git a/Src/loop.c b/Src/loop.c
index 538afb8dc..01abc6cc9 100644
--- a/Src/loop.c
+++ b/Src/loop.c
@@ -570,7 +570,7 @@ execif(Estate state, int do_exec)
 
     if (run) {
 	/* we need to ignore lastval until we reach execcmd() */
-	if (olderrexit)
+	if (olderrexit || run == 2)
 	    noerrexit = olderrexit;
 	else if (lastval)
 	    noerrexit |= NOERREXIT_EXIT | NOERREXIT_RETURN | NOERREXIT_UNTIL_EXEC;
diff --git a/Test/C03traps.ztst b/Test/C03traps.ztst
index e661aabd5..6f84e5db2 100644
--- a/Test/C03traps.ztst
+++ b/Test/C03traps.ztst
@@ -500,6 +500,15 @@
 >Succeed 2
 >Succeed 3
 
+  (set -e
+   if false; then
+   else
+       a=$(false)
+       print This should not appear
+   fi
+  )
+1:ERREXIT is triggered in an else block after a cmd subst returning false
+
   fn() {
     emulate -L zsh
     setopt errreturn


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-02-01 19:29 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-01 17:56 [bug] errexit and cmdsubst after "else" Stephane Chazelas
2020-02-01 19:28 ` Peter Stephenson

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).