From: Bart Schaefer <schaefer@brasslantern.com>
To: Zsh hackers list <zsh-workers@zsh.org>
Subject: Bug: function calls with break in preexec
Date: Sat, 16 Sep 2023 08:08:12 -0700 [thread overview]
Message-ID: <CAH+w=7ZLvbJadBMgKrnMZZr70B55jjK0vkE=0LVNZgyi+H8hnQ@mail.gmail.com> (raw)
This nofork test is what got me here:
repeat 3 do purr ${
for x in 1 2 3 4
do (( x == 3 )) && break 2; print $x
done
} XX
done
This fails when added to the test suite because it produces no output at all.
"purr" is a function:
purr() { print -r -- "$@" }
If "purr" is replaced by "print -r --" in the repeat loop, everything
works as expected, the output is
1
2 XX
Its important that the ${ ... } is expanded by preexec() before the
function is called. After scratching my head for a while I came up
with a way to have that happen even without the nofork patches:
repeat 3 print c*(oe:'break':)
prints all the files starting with "c" (e.g., run it in the zsh source
tree) but only once. Conversely,
repeat 3 purr c*(oe:'break':)
prints nothing. "set -x" shows the function call being made, but it
immediately stops without executing any commands.
One of these cases has to be wrong: Either the loop should break
immediately, so neither the builtin nor the function runs, or the
function should run and then the loop should break. Or more
radically, a break occurring in the argument expansions should just be
discarded, but that seems wrong too. I think it's the former: The
builtin shouldn't run in this case.
reply other threads:[~2023-09-16 15:09 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=7ZLvbJadBMgKrnMZZr70B55jjK0vkE=0LVNZgyi+H8hnQ@mail.gmail.com' \
--to=schaefer@brasslantern.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).