From: Peter Stephenson <p.w.stephenson@ntlworld.com>
To: zsh-workers@zsh.org
Cc: Michael Greenberg <michael@greenberg.science>
Subject: Re: `return` does not behave properly under `!`
Date: Wed, 7 Dec 2022 17:21:49 +0000 (GMT) [thread overview]
Message-ID: <1195592041.2125811.1670433709206@mail.virginmedia.com> (raw)
In-Reply-To: <CAH+w=7bGbnWYJUQ6eZUzP-NoxFE+8==8h0tDr-vdJ+Ez-pGC8Q@mail.gmail.com>
> On 07/12/2022 17:06 Bart Schaefer <schaefer@brasslantern.com> wrote:
> On Wed, Dec 7, 2022 at 8:17 AM Peter Stephenson
> <p.w.stephenson@ntlworld.com> 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
next prev parent reply other threads:[~2022-12-07 17:28 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-06 18:18 Michael Greenberg
2022-12-07 4:53 ` Bart Schaefer
2022-12-07 8:42 ` Stephane Chazelas
2022-12-07 15:05 ` Michael Greenberg
2022-12-07 16:01 ` Stephane Chazelas
2022-12-07 16:16 ` Peter Stephenson
2022-12-07 17:06 ` Bart Schaefer
2022-12-07 17:21 ` Peter Stephenson [this message]
2022-12-07 18:51 ` Bart Schaefer
2022-12-07 17:10 ` Michael Greenberg
2022-12-09 15:22 ` Michael Greenberg
2022-12-09 16:21 ` Bart Schaefer
2022-12-09 19:20 ` Michael Greenberg
2022-12-07 16:08 ` 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=1195592041.2125811.1670433709206@mail.virginmedia.com \
--to=p.w.stephenson@ntlworld.com \
--cc=michael@greenberg.science \
--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).