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

Re: [PATCH] More ERR_EXIT (was Re: Tests RE behavior of ERR_EXIT)



On Sun, Nov 13, 2022 at 7:46 AM Philippe Altherr
<philippe.altherr@xxxxxxxxx> wrote:
>
> Now let's remove the following code from exec.c
>
>>        if (!(oldnoerrexit & NOERREXIT_UNTIL_EXEC))
>>            noerrexit = oldnoerrexit;
>
>
> With that change the two functions still behave exactly the same but if you replace the while statement with any other statement (if, case, for, ...) then no ERR_EXIT is triggered in foo. Instead the non-zero exit status correctly bubbles up to the caller and triggers an ERR_EXIT in bar.
>
> I still don't understand why the change above fixes the problem for if, case, for, ... statements. I understand even less why it doesn't fix it for while statements.

NOERREXIT_UNTIL_EXEC is what protects the tests between keywords "if"
and "then" and those between "while" and "do" from triggering
ERR_EXIT.

The problem is that when an && || conditional expression appears
between "then" and "fi" or between "do" and "done" the assignment of
noerrexit = olderrexit still happens, which resets the state too far
into the past.




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