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

Re: Possible bug: Zsh function does not terminate when ${name:?word} fails



On Wed, Sep 14, 2016 at 10:00 AM, Ronald Fischer <ynnor@xxxxx> wrote:
> (See also for a complete discussion:
> http://stackoverflow.com/questions/39463547/zsh-function-does-not-terminate-when-nameword-fails?noredirect=1#comment66276136_39463547)
>
> I have in my .zshrc the following function definition (simplified
> example):
>
> function foo {
>   local p=${1:?parameter missing}
>   echo continue ....
> }
>
> Running the function by just typing foo produces, as expected, the
> message parameter missing, but it also outputs continue. I had expected
> that the function terminates when the :? check fails, but it continues
> to run.
>
> I tested this with zsh 5.1.1, but I was informed that this behaviour
> also can be reproduced with zsh 5.2

This seems to be a side effect of the reserved word handling, if you do
disable -r local
then it behaves as expected. Being in a function or not makes no
difference, the same thing happens if you do
local p=${foo:?hello}; echo continue
on the command line.

-- 
Mikael Magnusson



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