zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: Philippe Altherr <philippe.altherr@gmail.com>
Cc: Zsh hackers list <zsh-workers@zsh.org>
Subject: [PATCH] Even more ERR_EXIT (was Re: More ERR_EXIT Re: Tests RE behavior of ERR_EXIT)
Date: Mon, 14 Nov 2022 23:01:28 -0800	[thread overview]
Message-ID: <CAH+w=7Z9Tw8aiRqhyULw2XxNVYiyPS49bMSpdvm6EDMJ6OBViw@mail.gmail.com> (raw)
In-Reply-To: <CAH+w=7a3W1CdxeKHKC4vEwsW4LUB305f=c1=bzSn5bUYMnX=Ww@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1093 bytes --]

On Mon, Nov 14, 2022 at 5:11 PM Bart Schaefer <schaefer@brasslantern.com> wrote:
>
> [if workers/50929 makes 50897 redundant then] there's no point in
> bashing through if/case/for/while/repeat/select individually -- the
> only case we have to fix is this one:

I was half right.  Fixing that case revealed that it was necessary to
go through the others, because the "redundant" fix is one level too
far up the stack.

Attached patch removes 50929 again, and amends this_noerrexit from
50897 in each of the complex command exec* functions.  Finally it adds
tests to E01options for each of the cases that Philippe previously
outlined, with the exception of "select" which is interactive.

The tests from 50928 still pass with this patch.  I spent a ridiculous
amount of time with every change I made flopping back and forth
between C03 working and the new E01 failing and vice-versa, before
noticing what happened when I nested a brace expression inside another
one.

Also a minor fix for TRAPDEBUG that caused me some confusion earlier
in the process.

Are there more cases that need testing?

[-- Attachment #2: errexit_thirdtime.txt --]
[-- Type: text/plain, Size: 5710 bytes --]

diff --git a/Src/exec.c b/Src/exec.c
index ce0c1f1ad..dc5d5dd23 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -451,7 +451,10 @@ execcursh(Estate state, int do_exec)
     cmdpop();
 
     state->pc = end;
-    this_noerrexit = (WC_SUBLIST_TYPE(*end) != WC_SUBLIST_END);
+    if (WC_SUBLIST_TYPE(*end) != WC_SUBLIST_END)
+	this_noerrexit = noerrexit;
+    else
+	this_noerrexit = 1;
 
     return lastval;
 }
@@ -1442,8 +1445,6 @@ execlist(Estate state, int dont_change_job, int exiting)
 		    execsimple(state);
 		else
 		    execpline(state, code, ltype, (ltype & Z_END) && exiting);
-		if (!locallevel || unset(ERRRETURN))
-		    this_noerrexit = noerrexit;
 		state->pc = next;
 		goto sublist_done;
 		break;
@@ -1536,6 +1537,7 @@ sublist_done:
 	     */
 	    int oerrexit_opt = opts[ERREXIT];
 	    opts[ERREXIT] = 0;
+	    oldnoerrexit = noerrexit;
 	    noerrexit = NOERREXIT_EXIT | NOERREXIT_RETURN;
 	    exiting = donetrap;
 	    ret = lastval;
diff --git a/Src/loop.c b/Src/loop.c
index be5261369..cd2f5340b 100644
--- a/Src/loop.c
+++ b/Src/loop.c
@@ -208,7 +208,10 @@ execfor(Estate state, int do_exec)
     loops--;
     simple_pline = old_simple_pline;
     state->pc = end;
-    this_noerrexit = (WC_SUBLIST_TYPE(*end) != WC_SUBLIST_END);
+    if (WC_SUBLIST_TYPE(*end) != WC_SUBLIST_END)
+	this_noerrexit = noerrexit;
+    else
+	this_noerrexit = 1;
     return lastval;
 }
 
@@ -336,7 +339,10 @@ execselect(Estate state, UNUSED(int do_exec))
     loops--;
     simple_pline = old_simple_pline;
     state->pc = end;
-    this_noerrexit = (WC_SUBLIST_TYPE(*end) != WC_SUBLIST_END);
+    if (WC_SUBLIST_TYPE(*end) != WC_SUBLIST_END)
+	this_noerrexit = noerrexit;
+    else
+	this_noerrexit = 1;
     return lastval;
 }
 
@@ -478,7 +484,10 @@ execwhile(Estate state, UNUSED(int do_exec))
     popheap();
     loops--;
     state->pc = end;
-    this_noerrexit = (WC_SUBLIST_TYPE(*end) != WC_SUBLIST_END);
+    if (WC_SUBLIST_TYPE(*end) != WC_SUBLIST_END)
+	this_noerrexit = noerrexit;
+    else
+	this_noerrexit = 1;
     return lastval;
 }
 
@@ -532,7 +541,10 @@ execrepeat(Estate state, UNUSED(int do_exec))
     loops--;
     simple_pline = old_simple_pline;
     state->pc = end;
-    this_noerrexit = (WC_SUBLIST_TYPE(*end) != WC_SUBLIST_END);
+    if (WC_SUBLIST_TYPE(*end) != WC_SUBLIST_END)
+	this_noerrexit = noerrexit;
+    else
+	this_noerrexit = 1;
     return lastval;
 }
 
@@ -587,7 +599,10 @@ execif(Estate state, int do_exec)
 	    lastval = 0;
     }
     state->pc = end;
-    this_noerrexit = (WC_SUBLIST_TYPE(*end) != WC_SUBLIST_END);
+    if (WC_SUBLIST_TYPE(*end) != WC_SUBLIST_END)
+	this_noerrexit = noerrexit;
+    else
+	this_noerrexit = 1;
 
     return lastval;
 }
@@ -701,7 +716,10 @@ execcase(Estate state, int do_exec)
 
     if (!anypatok)
 	lastval = 0;
-    this_noerrexit = (WC_SUBLIST_TYPE(*end) != WC_SUBLIST_END);
+    if (WC_SUBLIST_TYPE(*end) != WC_SUBLIST_END)
+	this_noerrexit = noerrexit;
+    else
+	this_noerrexit = 1;
 
     return lastval;
 }
diff --git a/Test/E01options.ztst b/Test/E01options.ztst
index d38fbed74..939a11a7a 100644
--- a/Test/E01options.ztst
+++ b/Test/E01options.ztst
@@ -385,6 +385,113 @@
 1:ERR_RETURN with additional levels
 >Executed
 
+  (
+    setopt ERR_EXIT
+    { false } always { print INSIDE: $? }
+    print OUTSIDE
+  )
+1:ERR_EXIT from simple brace expression
+
+  (
+    setopt ERR_EXIT
+    { false && true } always { print INSIDE: $? }
+    print OUTSIDE
+  )
+1:ERR_EXIT from conditional brace expression
+>INSIDE: 1
+
+  (
+    setopt ERR_EXIT
+    { if true; then false; true; fi } always { print INSIDE: $? }
+    print OUTSIDE
+  )
+1:ERR_EXIT from "if" with simple body
+
+  (
+    setopt ERR_EXIT
+    { if true; then false && true; fi } always { print INSIDE: $? }
+    print OUTSIDE
+  )
+1:ERR_EXIT from "if" with conditional body
+>INSIDE: 1
+
+  (
+    setopt ERR_EXIT
+    { if false; then :; else false; true; fi } always { print INSIDE: $? }
+    print OUTSIDE
+  )
+1:ERR_EXIT from "else" with simple body
+
+  (
+    setopt ERR_EXIT
+    { if false; then :; else false && true; fi } always { print INSIDE: $? }
+    print OUTSIDE
+  )
+1:ERR_EXIT from "else" with conditional body
+>INSIDE: 1
+
+  (
+    setopt ERR_EXIT
+    { case x in; (*) false;; esac } always { print INSIDE: $? }
+    print OUTSIDE
+  )
+1:ERR_EXIT from "case" with simple body
+
+  (
+    setopt ERR_EXIT
+    { case x in; (*) false && true;; esac } always { print INSIDE: $? }
+    print OUTSIDE
+  )
+1:ERR_EXIT from "case" with conditional body
+>INSIDE: 1
+
+  (
+    setopt ERR_EXIT
+    { for _ in 1; do false; true; done } always { print INSIDE: $? }
+    print OUTSIDE
+  )
+1:ERR_EXIT from "for" with simple body
+
+  (
+    setopt ERR_EXIT
+    { for _ in 1; do false && true; done } always { print INSIDE: $? }
+    print OUTSIDE
+  )
+1:ERR_EXIT from "for" with conditional body
+>INSIDE: 1
+
+  (
+    setopt ERR_EXIT
+    () { { while ((argv[1]--)); do false; true; done
+         } always { print INSIDE: $? } } 1
+    print OUTSIDE
+  )
+1:ERR_EXIT from "while" with simple body
+
+  (
+    setopt ERR_EXIT
+    () { { while ((argv[1]--)); do false && true; done
+         } always { print INSIDE: $? } } 1
+    print OUTSIDE
+  )
+1:ERR_EXIT from "while" with conditional body
+>INSIDE: 1
+
+  (
+    setopt ERR_EXIT
+    { repeat $; do false; done } always { print INSIDE: $? }
+    print OUTSIDE
+  )
+1:ERR_EXIT from "repeat" with simple body
+
+  (
+    setopt ERR_EXIT
+    { repeat 1; do false && true; done } always { print INSIDE: $? }
+    print OUTSIDE
+  )
+1:ERR_EXIT from "repeat" with conditional body
+>INSIDE: 1
+
   (print before; setopt noexec; print after)
 0:NO_EXEC option
 >before

  reply	other threads:[~2022-11-15  7:02 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-12 22:16 [PATCH] More ERR_EXIT (was " Philippe Altherr
2022-11-13  3:59 ` Philippe Altherr
2022-11-13  4:11   ` Bart Schaefer
2022-11-13 13:55     ` Philippe Altherr
2022-11-13 14:24       ` Philippe Altherr
2022-11-13 15:45         ` Philippe Altherr
2022-11-13 16:52           ` Bart Schaefer
2022-11-13 16:45       ` Bart Schaefer
2022-11-13 16:53         ` Bart Schaefer
2022-11-13 18:37           ` Philippe Altherr
2022-11-13 20:55             ` Philippe Altherr
2022-11-13 22:27               ` Bart Schaefer
2022-11-13 23:10               ` Lawrence Velázquez
2022-11-13 22:12             ` Bart Schaefer
2022-11-15  1:11         ` Bart Schaefer
2022-11-15  7:01           ` Bart Schaefer [this message]
2022-11-15  7:30             ` [PATCH] Even more ERR_EXIT (was Re: More ERR_EXIT " Philippe Altherr
2022-11-15 19:50               ` Philippe Altherr
2022-11-15  7:26           ` [PATCH] More ERR_EXIT (was " Philippe Altherr
2022-11-15 19:18             ` Philippe Altherr
2022-11-15 21:08               ` Bart Schaefer
2022-11-16  2:41               ` Lawrence Velázquez
2022-11-16  6:31                 ` Philippe Altherr
2022-11-16  5:51               ` Bart Schaefer
2022-11-16  7:56                 ` Philippe Altherr
2022-11-16 14:21                   ` Philippe Altherr

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='CAH+w=7Z9Tw8aiRqhyULw2XxNVYiyPS49bMSpdvm6EDMJ6OBViw@mail.gmail.com' \
    --to=schaefer@brasslantern.com \
    --cc=philippe.altherr@gmail.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).