Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: `return` does not behave properly under `!`
- X-seq: zsh-workers 51125
- From: Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Cc: Michael Greenberg <michael@greenberg.science>
- Subject: Re: `return` does not behave properly under `!`
- Date: Wed, 7 Dec 2022 17:21:49 +0000 (GMT)
- Archived-at: <https://zsh.org/workers/51125>
- Importance: Normal
- In-reply-to: <CAH+w=7bGbnWYJUQ6eZUzP-NoxFE+8==8h0tDr-vdJ+Ez-pGC8Q@mail.gmail.com>
- List-id: <zsh-workers.zsh.org>
- References: <m2a640qtt8.fsf@greenberg.science> <20221207084255.ykkg6cgzn4nqc73f@chazelas.org> <m2o7sfp83l.fsf@greenberg.science> <20221207160113.ol3lcbm6p7xu3rru@chazelas.org> <576947410.2118097.1670429780069@mail.virginmedia.com> <CAH+w=7bGbnWYJUQ6eZUzP-NoxFE+8==8h0tDr-vdJ+Ez-pGC8Q@mail.gmail.com>
> 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