1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-10-06 09:01:13 +02:00

Fix problem with ERR_RETURN.

It wasn't suppressed properly in the code following an if
in some circumstances, in particular in initialsation scripts
and also in a nested function where the caller had suppressed
it.
This commit is contained in:
Peter Stephenson 2017-08-31 16:54:19 +01:00
parent 73514c40f6
commit ebcea98eca
3 changed files with 43 additions and 4 deletions

View file

@ -1,3 +1,9 @@
2017-08-31 Peter Stephenson <p.stephenson@samsung.com>
* 41627: Src/loop.c, Test/C03traps.ztst: fix problem with
ERR_RETURN in initialisation scripts and also on nested
function involving ERR_RETURN suppression in the caller.
2017-08-30 Daniel Shahaf <d.s@daniel.shahaf.name> 2017-08-30 Daniel Shahaf <d.s@daniel.shahaf.name>
* 41567: Completion/Unix/Command/_tmux: Complete detached * 41567: Completion/Unix/Command/_tmux: Complete detached

View file

@ -541,8 +541,7 @@ execif(Estate state, int do_exec)
olderrexit = noerrexit; olderrexit = noerrexit;
end = state->pc + WC_IF_SKIP(code); end = state->pc + WC_IF_SKIP(code);
if (!noerrexit) noerrexit |= NOERREXIT_EXIT | NOERREXIT_RETURN;
noerrexit = NOERREXIT_EXIT | NOERREXIT_RETURN;
while (state->pc < end) { while (state->pc < end) {
code = *state->pc++; code = *state->pc++;
if (wc_code(code) != WC_IF || if (wc_code(code) != WC_IF ||
@ -570,9 +569,9 @@ execif(Estate state, int do_exec)
if (olderrexit) if (olderrexit)
noerrexit = olderrexit; noerrexit = olderrexit;
else if (lastval) else if (lastval)
noerrexit = NOERREXIT_EXIT | NOERREXIT_RETURN | NOERREXIT_UNTIL_EXEC; noerrexit |= NOERREXIT_EXIT | NOERREXIT_RETURN | NOERREXIT_UNTIL_EXEC;
else else
noerrexit = 0; noerrexit &= ~ (NOERREXIT_EXIT | NOERREXIT_RETURN);
cmdpush(run == 2 ? CS_ELSE : (s ? CS_ELIFTHEN : CS_IFTHEN)); cmdpush(run == 2 ? CS_ELSE : (s ? CS_ELIFTHEN : CS_IFTHEN));
execlist(state, 1, do_exec); execlist(state, 1, do_exec);
cmdpop(); cmdpop();

View file

@ -661,6 +661,40 @@ F:Must be tested with a top-level script rather than source or function
>before-out >before-out
>before-in >before-in
mkdir -p zdotdir
print >zdotdir/.zshenv '
setopt norcs errreturn
fn() {
if false; then
print Bad
else
print Good
fi
print Better
}
fn
print In .zshenv'
ZDOTDIR=$PWD/zdotdir $ZTST_testdir/../Src/zsh -c 'true'
0:ERR_RETURN within initialisation code with special flags
>Good
>Better
>In .zshenv
fn2() {
if false; then
print Bad
else
print Good
fi
}
fn() {
setopt err_return
fn2 || true
}
fn
0:ERR_RETURN in "else" branch in nested function
>Good
(setopt err_exit (setopt err_exit
for x in y; do for x in y; do
false && true false && true