Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: `return` does not behave properly under `!`



> On 07/12/2022 17:06 Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> On Wed, Dec 7, 2022 at 8:17 AM Peter Stephenson
> <p.w.stephenson@xxxxxxxxxxxx> wrote:
> >
> > I agree with Michael's argument that shows that logically it
> > can't have an effect on the status, whatever you want.
> 
> That's going to be ugly, because "return" is implemented as a builtin
> that propagates lastval.  One level out, at the WC_SUBLIST_NOT
> implementation, it has no idea that lastval came from "return" rather
> than from any arbitrary sublist.

Not particularly, though I'm not actually that fussed, since I can't
really see the use of this beyond a bit of somewhat arbitrary state
purity.

pws

diff --git a/Src/exec.c b/Src/exec.c
index 1810fca5e..7049710c3 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -1961,7 +1961,7 @@ execpline(Estate state, wordcode slcode, int how, int last1)
 	}
 	else
 	    unqueue_signals();
-	if ((slflags & WC_SUBLIST_NOT) && !errflag)
+	if ((slflags & WC_SUBLIST_NOT) && !errflag && !retflag)
 	    lastval = !lastval;
     }
     if (!pline_level)
diff --git a/Test/A01grammar.ztst b/Test/A01grammar.ztst
index 0312fe94e..b3aea1055 100644
--- a/Test/A01grammar.ztst
+++ b/Test/A01grammar.ztst
@@ -970,3 +970,15 @@ F:its expectations.
 0:Non-interactive shell command input is line buffered
 >Value is first
 >Value is second
+
+ fn() {
+   ! false
+ }
+0:! inverts the status of implicit return
+
+ fn () {
+   false
+   ! return
+ }
+ fn
+1:! does not affect return status of explicit return




Messages sorted by: Reverse Date, Date, Thread, Author