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

Re: ERR_RETURN ignored in 'if' in a source'd file [FIXED]



James Widman wrote on Wed, 07 May 2025 11:18 +00:00:
> I recently hit a bug in zsh 5.9 that has since been fixed in the main git
> branch, so I thought I'd describe the bug here in case anyone else runs into
> it.
>
> The example is:
>
> #!/usr/bin/env zsh
> foo(){
>     setopt err_return
>     source <(echo 'if true; then return 42; fi')
>     echo "This line is printed by zsh 5.9 (but it shouldn't be)."
> }
> foo
>

Thanks for bisecting and reporting this, James.  I've added a regression test:

https://sourceforge.net/p/zsh/code/ci/60639c67f0cdab2b89fce481753f791321aa53de/

The test runs inside a «$ZTST_testdir/../Src/zsh -f» because, otherwise,
the ERR_RETURN would cause early returns not only in the test case's
code, but also in the test harness code executing the test code¹.  (Yes,
it's rather odd that it's possible for code being tested to affect the
test harness' control flow this way.)

And thanks for sharing your use of zparseopts.  Knowing how one's code
is used is always helpful :-)

Excuse brevity.

Cheers,

Daniel
(who is emphatically _not_ the author of zparseopts)

¹ An anonymous function in ZTST_execchunk(), and its callers in the same
  file, all the way up to (but not including) Test/runtests.zsh.




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