1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-06-09 18:38:05 +02:00

51001: fix for ERR_EXIT following shell function; update tests

This commit is contained in:
Philippe Altherr 2022-12-03 20:44:10 -08:00 committed by Bart Schaefer
parent d47b8480f0
commit dd3ba3d599
2 changed files with 83 additions and 9 deletions

View file

@ -5932,15 +5932,6 @@ doshfunc(Shfunc shfunc, LinkList doshargs, int noreturnval)
* This function is forced to return. * This function is forced to return.
*/ */
retflag = 0; retflag = 0;
/*
* The calling function isn't necessarily forced to return,
* but it should be made sensitive to ERR_EXIT and
* ERR_RETURN as the assumptions we made at the end of
* constructs within this function no longer apply. If
* there are cases where this is not true, they need adding
* to C03traps.ztst.
*/
this_noerrexit = 0;
breaks = funcsave->breaks; breaks = funcsave->breaks;
} }
freearray(pparams); freearray(pparams);
@ -6010,6 +6001,7 @@ doshfunc(Shfunc shfunc, LinkList doshargs, int noreturnval)
trap_return++; trap_return++;
ret = lastval; ret = lastval;
noerrexit = funcsave->noerrexit; noerrexit = funcsave->noerrexit;
this_noerrexit = 0;
if (noreturnval) { if (noreturnval) {
lastval = funcsave->lastval; lastval = funcsave->lastval;
numpipestats = funcsave->numpipestats; numpipestats = funcsave->numpipestats;

View file

@ -742,6 +742,15 @@ F:Must be tested with a top-level script rather than source or function
0:ERR_EXIT not triggered by "false && true" 0:ERR_EXIT not triggered by "false && true"
>OK >OK
(setopt err_exit
fn() {
false && true
}
fn
print OK
)
1:ERR_EXIT not triggered by "false && true" but by return from fn
(setopt err_exit (setopt err_exit
for x in y; do for x in y; do
false && true false && true
@ -751,6 +760,17 @@ F:Must be tested with a top-level script rather than source or function
0:ERR_EXIT not triggered by status 1 at end of for 0:ERR_EXIT not triggered by status 1 at end of for
>OK >OK
(setopt err_exit
fn() {
for x in y; do
false && true
done
}
fn
print OK
)
1:ERR_EXIT not triggered by status 1 at end of for but by return from fn
(setopt err_exit (setopt err_exit
repeat 1; do repeat 1; do
false && true false && true
@ -760,6 +780,17 @@ F:Must be tested with a top-level script rather than source or function
0:ERR_EXIT not triggered by status 1 at end of repeat 0:ERR_EXIT not triggered by status 1 at end of repeat
>OK >OK
(setopt err_exit
fn() {
repeat 1; do
false && true
done
}
fn
print OK
)
1:ERR_EXIT not triggered by status 1 at end of repeat but by return from fn
(setopt err_exit (setopt err_exit
if true; then if true; then
false && true false && true
@ -769,6 +800,17 @@ F:Must be tested with a top-level script rather than source or function
0:ERR_EXIT not triggered by status 1 at end of if 0:ERR_EXIT not triggered by status 1 at end of if
>OK >OK
(setopt err_exit
fn() {
if true; then
false && true
fi
}
fn
print OK
)
1:ERR_EXIT not triggered by status 1 at end of if but by return from fn
(setopt err_exit (setopt err_exit
loop=true loop=true
while print COND; $loop; do while print COND; $loop; do
@ -782,6 +824,21 @@ F:Must be tested with a top-level script rather than source or function
>COND >COND
>OK >OK
(setopt err_exit
fn() {
loop=true
while print COND; $loop; do
loop=false
false && true
done
}
fn
print OK
)
1:ERR_EXIT not triggered by status 1 at end of while but by return from fn
>COND
>COND
(setopt err_exit (setopt err_exit
{ {
false && true false && true
@ -794,6 +851,20 @@ F:Must be tested with a top-level script rather than source or function
>ALWAYS >ALWAYS
>OK >OK
(setopt err_exit
fn() {
{
false && true
} always {
print ALWAYS
}
}
fn
print OK
)
1:ERR_EXIT not triggered by status 1 at end of always but by return from fn
>ALWAYS
(setopt err_exit (setopt err_exit
{ {
false && true false && true
@ -803,6 +874,17 @@ F:Must be tested with a top-level script rather than source or function
0:ERR_EXIT not triggered by status 1 at end of { } 0:ERR_EXIT not triggered by status 1 at end of { }
>OK >OK
(setopt err_exit
fn() {
{
false && true
}
}
fn
print OK
)
1:ERR_EXIT not triggered by status 1 at end of { } but by return from fn
unsetopt err_exit err_return unsetopt err_exit err_return
(setopt err_exit (setopt err_exit
for x in y; do for x in y; do