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

Bug: function calls with break in preexec



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.




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