mirror of
https://github.com/zsh-users/zsh
synced 2024-10-14 11:53:24 +00:00
45111: zshmisc(1): Clarify the documentation of 'return' and 'exit' in conjunction with try/always
Having reviewed 20076, 20084, 21734, and 21735, my understanding is that the original intention was: - A 'return' in a function does run always-list - An 'exit' outside a function does not run always-list - A 'return' outside a function is treated as an 'exit' All of which are the case today. The remaining case, of 'exit' used inside a function, was not specified by the referenced -workers@ posts; does, as implemented, run the always-list; and furthermore, based in 21734 it's fair to assume that the original documentation was assuming that 'exit' would be used outside of any function, just like it assumed 'return' would be used inside a function. Therefore, have the documentation specify only the behaviour of 'exit' outside any function, and leave the behaviour of 'exit' inside a function unspecified. Anyone who relied on the documentation of 'exit' as documented until this commit would have run into the documentation/implementation discrepancy described in 45075.
This commit is contained in:
parent
105ca83aa2
commit
a0c0aa41d2
|
@ -1,5 +1,9 @@
|
||||||
2019-12-22 Daniel Shahaf <danielsh@apache.org>
|
2019-12-22 Daniel Shahaf <danielsh@apache.org>
|
||||||
|
|
||||||
|
* 45111: Doc/Zsh/grammar.yo, Etc/BUGS, NEWS,
|
||||||
|
Test/A01grammar.ztst: zshmisc(1): Clarify the documentation of
|
||||||
|
'return' and 'exit' in conjunction with try/always
|
||||||
|
|
||||||
* 45112: Doc/Zsh/mod_zutil.yo: zshmodules: Explicitly document
|
* 45112: Doc/Zsh/mod_zutil.yo: zshmodules: Explicitly document
|
||||||
the return values of the 'zstyle' getters -s, -b, and -a.
|
the return values of the 'zstyle' getters -s, -b, and -a.
|
||||||
|
|
||||||
|
|
|
@ -297,11 +297,11 @@ findex(always)
|
||||||
cindex(always blocks)
|
cindex(always blocks)
|
||||||
cindex(try blocks)
|
cindex(try blocks)
|
||||||
item(tt({) var(try-list) tt(} always {) var(always-list) tt(}))(
|
item(tt({) var(try-list) tt(} always {) var(always-list) tt(}))(
|
||||||
First execute var(try-list). Regardless of errors, or tt(break),
|
First execute var(try-list). Regardless of errors, or tt(break) or
|
||||||
tt(continue), or tt(return) commands encountered within var(try-list),
|
tt(continue) commands encountered within var(try-list),
|
||||||
execute var(always-list). Execution then continues from the
|
execute var(always-list). Execution then continues from the
|
||||||
result of the execution of var(try-list); in other words, any error,
|
result of the execution of var(try-list); in other words, any error,
|
||||||
or tt(break), tt(continue), or tt(return) command is treated in the
|
or tt(break) or tt(continue) command is treated in the
|
||||||
normal way, as if var(always-list) were not present. The two
|
normal way, as if var(always-list) were not present. The two
|
||||||
chunks of code are referred to as the `try block' and the `always block'.
|
chunks of code are referred to as the `try block' and the `always block'.
|
||||||
|
|
||||||
|
@ -345,10 +345,16 @@ example({
|
||||||
}
|
}
|
||||||
# The error condition has been reset.)
|
# The error condition has been reset.)
|
||||||
|
|
||||||
An tt(exit) command (or a tt(return) command executed at the outermost
|
When a tt(try) block occurs outside of any function,
|
||||||
function level of a script) encountered in tt(try-list) does em(not) cause
|
a tt(return) or a tt(exit) encountered in var(try-list) does em(not) cause
|
||||||
the execution of var(always-list). Instead, the shell exits immediately
|
the execution of var(always-list). Instead, the shell exits immediately
|
||||||
after any tt(EXIT) trap has been executed.
|
after any tt(EXIT) trap has been executed.
|
||||||
|
Otherwise, a tt(return) command encountered in var(try-list) will cause the
|
||||||
|
execution of var(always-list), just like tt(break) and tt(continue).
|
||||||
|
|
||||||
|
COMMENT(The semantics of calling 'exit' in try-list inside a function are
|
||||||
|
deliberately left unspecified, because historically there was a mismatch between
|
||||||
|
the documented and implemented behaviours. Cf. 20076, 21734/21735, 45075.)
|
||||||
)
|
)
|
||||||
findex(function)
|
findex(function)
|
||||||
xitem(tt(function) var(word) ... [ tt(()) ] [ var(term) ] tt({) var(list) tt(}))
|
xitem(tt(function) var(word) ... [ tt(()) ] [ var(term) ] tt({) var(list) tt(}))
|
||||||
|
|
3
Etc/BUGS
3
Etc/BUGS
|
@ -39,6 +39,3 @@ fn trap1 trap2
|
||||||
echo out2
|
echo out2
|
||||||
]]]
|
]]]
|
||||||
------------------------------------------------------------------------
|
------------------------------------------------------------------------
|
||||||
45075 - Daniel Shahaf - '{ exit } always { foo }' - docs/code mismatch
|
|
||||||
and return/exit differences
|
|
||||||
------------------------------------------------------------------------
|
|
||||||
|
|
10
NEWS
10
NEWS
|
@ -34,6 +34,16 @@ path the leading '/' counts as one component.
|
||||||
|
|
||||||
The functions builtin gained a -c option to efficiently copy functions.
|
The functions builtin gained a -c option to efficiently copy functions.
|
||||||
|
|
||||||
|
The zshmisc(1) manual page incorrectly stated that when 'exit' is used
|
||||||
|
in a `try' block inside a function, the corresponding `always' block will
|
||||||
|
be executed. The manual page has been corrected. The shell's behaviour
|
||||||
|
has not changed, but code such as the following:
|
||||||
|
.
|
||||||
|
f() { { exit } always { echo Hello world } }
|
||||||
|
.
|
||||||
|
should be changed either to use 'return' instead of 'exit', or to have
|
||||||
|
the try/always block outside of any function.
|
||||||
|
|
||||||
Changes from 5.6.2 to 5.7.1
|
Changes from 5.6.2 to 5.7.1
|
||||||
---------------------------
|
---------------------------
|
||||||
|
|
||||||
|
|
|
@ -729,6 +729,7 @@
|
||||||
3:Exit and always block with functions: simple
|
3:Exit and always block with functions: simple
|
||||||
>BEGIN
|
>BEGIN
|
||||||
>END
|
>END
|
||||||
|
F:Note that the behaviour of 'exit' inside try-list inside a function is unspecified.
|
||||||
|
|
||||||
(
|
(
|
||||||
mytrue() { echo mytrue; return 0 }
|
mytrue() { echo mytrue; return 0 }
|
||||||
|
@ -741,6 +742,7 @@
|
||||||
>BEGIN
|
>BEGIN
|
||||||
>mytrue
|
>mytrue
|
||||||
>END
|
>END
|
||||||
|
F:Note that the behaviour of 'exit' inside try-list inside a function is unspecified.
|
||||||
|
|
||||||
(emulate sh -c '
|
(emulate sh -c '
|
||||||
fn() {
|
fn() {
|
||||||
|
|
Loading…
Reference in a new issue