zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.stephenson@samsung.com>
To: zsh-workers@zsh.org
Subject: Re: err_exit/err_return regression
Date: Thu, 09 Jul 2015 14:38:23 +0100	[thread overview]
Message-ID: <20150709143823.184fb4e1@pwslap01u.europe.root.pri> (raw)
In-Reply-To: <CAOCbtnsTgLStbfjKF9AfF61z_WWniKOKurSEdB1iy5cHjbbvrw@mail.gmail.com>

On Thu, 9 Jul 2015 13:33:09 +0200
jsks <js.shirin@gmail.com> wrote:
> Since patch 34065, with either err_exit or err_return set, zsh does
> not exit/return given a nonzero exist status of a command following
> 'else'.

Hmm, this code is quite hairy and is crying out to be a bit more
structured (it's not lonely in that respect).  But the test suite says
the following is good enough for now.

diff --git a/Src/exec.c b/Src/exec.c
index 960601f..4eee82b 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -1351,7 +1351,13 @@ execlist(Estate state, int dont_change_job, int exiting)
 	state->pc--;
 sublist_done:
 
-	noerrexit = oldnoerrexit;
+	/*
+	 * See hairy code near the end of execif() for the
+	 * following.  "noerrexit == 2" only applies until
+	 * we hit execcmd on the way down.  We're now
+	 * on the way back up, so don't restore it.
+	 */
+	noerrexit = (oldnoerrexit == 2) ? 0 : oldnoerrexit;
 
 	if (sigtrapped[SIGDEBUG] && !isset(DEBUGBEFORECMD) && !donedebug) {
 	    /*
diff --git a/Test/C03traps.ztst b/Test/C03traps.ztst
index 757f75c..4e23388 100644
--- a/Test/C03traps.ztst
+++ b/Test/C03traps.ztst
@@ -399,6 +399,46 @@
    )
 1:ERREXIT in loop with simple commands
 
+  fn() {
+    emulate -L zsh
+    setopt errreturn
+    if false; then
+      false
+      print No.
+    else
+      print Oh, yes
+    fi
+  }
+  fn
+0:ERRRETURN not triggered in if condition
+>Oh, yes
+
+  fn() {
+    emulate -L zsh
+    setopt errreturn
+    if true; then
+      false
+      print No.
+    else
+      print No, no.
+    fi
+  }
+  fn
+1:ERRRETURN in "if"
+
+  fn() {
+    emulate -L zsh
+    setopt errreturn
+    if false; then
+      print No.
+    else
+      false
+      print No, no.
+    fi
+  }
+  fn
+1:ERRRETURN in "else" branch (regression test)
+
 %clean
 
   rm -f TRAPEXIT


  reply	other threads:[~2015-07-09 13:38 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-09 11:33 jsks
2015-07-09 13:38 ` Peter Stephenson [this message]
2015-09-29 15:43   ` Joshua Krusell
2015-09-29 18:54     ` Peter Stephenson
2015-09-29 20:52       ` Joshua Krusell
2015-09-30  1:09         ` Bart Schaefer
2015-10-01 20:32           ` Joshua Krusell
2015-10-04  0:26             ` Bart Schaefer
2015-10-04  2:58               ` Bart Schaefer

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=20150709143823.184fb4e1@pwslap01u.europe.root.pri \
    --to=p.stephenson@samsung.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).