From 1316a6b44123df11b98811ef243154a6e54b9bcc Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Wed, 10 Mar 2004 10:50:00 +0000 Subject: 19575: Fix problem with trap on EXIT overriding status --- Test/C03traps.ztst | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'Test/C03traps.ztst') diff --git a/Test/C03traps.ztst b/Test/C03traps.ztst index 81ef38a30..26ba73da5 100644 --- a/Test/C03traps.ztst +++ b/Test/C03traps.ztst @@ -196,3 +196,19 @@ f functions TRAPWINCH 1:Unsetting ordinary traps with localtraps. + +# +# Returns from within traps are a perennial problem. +# The following two apply to returns in and around standard +# ksh-style traps. The intention is that a return value from +# within the function is preserved (i.e. statuses set by the trap +# are ignored) unless the trap explicitly executes `return', which makes +# it return from the enclosing function. +# + fn() { trap 'true' EXIT; return 1; } + fn +1: ksh-style EXIT traps preserve return value + + inner() { trap 'return 3' EXIT; return 2: } + outer() { inner; return 1; } +3: ksh-style EXIT traps can force return status of enclosing function -- cgit 1.4.1