zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.w.stephenson@ntlworld.com>
To: zsh-workers@zsh.org
Subject: Re: [bug] errexit and cmdsubst after "else"
Date: Sat, 01 Feb 2020 19:28:20 +0000	[thread overview]
Message-ID: <d824a32e18a7d9e8debd789184c8525f0aefc78e.camel@ntlworld.com> (raw)
In-Reply-To: <20200201175636.u4drsthh574p5cia@chazelas.org>

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


      reply	other threads:[~2020-02-01 19:29 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-01 17:56 Stephane Chazelas
2020-02-01 19:28 ` Peter Stephenson [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d824a32e18a7d9e8debd789184c8525f0aefc78e.camel@ntlworld.com \
    --to=p.w.stephenson@ntlworld.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).