From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22045 invoked by alias); 31 Aug 2017 09:42:31 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 41626 Received: (qmail 18277 invoked by uid 1010); 31 Aug 2017 09:42:31 -0000 X-Qmail-Scanner-Diagnostics: from mailout2.w1.samsung.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(210.118.77.12):SA:0(-6.9/5.0):. Processed in 2.142556 secs); 31 Aug 2017 09:42:31 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,RP_MATCHES_RCVD,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.1 X-Envelope-From: p.stephenson@samsung.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | X-AuditID: cbfec7f5-f79d06d0000031c7-27-59a7d877341f Date: Thu, 31 Aug 2017 10:35:47 +0100 From: Peter Stephenson To: zsh-workers@zsh.org Cc: Jan Alexander Steffens Subject: Re: err_return in initialization scripts returns from conditionals Message-id: <20170831103547.0350b063@pwslap01u.europe.root.pri> In-reply-to: Organization: Samsung Cambridge Solution Centre X-Mailer: Claws Mail 3.7.9 (GTK+ 2.22.0; i386-redhat-linux-gnu) MIME-version: 1.0 Content-type: text/plain; charset="US-ASCII" Content-transfer-encoding: 7bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrGIsWRmVeSWpSXmKPExsWy7djPc7rlN5ZHGlzYIWWxoeUtq8XB5odM DkweO2fdZfdYdfADUwBTFJdNSmpOZllqkb5dAlfGopUPmAt2iVZc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 m2azgdhsAoYSUzfNZgSxRQTEJc6uPc8CYjMLGEvsevMJrEZYwFvi7Js+sBpeAXuJBbdOgc3h FAiWWLDpAdTmZYwSkx41gzXzC+hLXP37iQniVnuJmVfOQDULSvyYfA9qgZbE5m1NrBC2vMTm NW+ZIa5Wl7hxdzf7BEaRWUhaZiFpmYWkZQEj8ypGkdTS4tz03GIjveLE3OLSvHS95PzcTYzA mNt27OeWHYxd74IPMQpwMCrx8FZsWRYpxJpYVlyZe4hRgoNZSYS39eDySCHelMTKqtSi/Pii 0pzU4kOMpsBQmsgsJZqcD0wHeSXxhiaG5paGRsYWFuZGRkrivOqXmyKFBNITS1KzU1MLUotg +pg4OKUaGPM38hUV158xSV/7LpvV8v2DrdPtpConlTN+fV4/82NXtdf3/z/zox1clcobK0XP n2LaNyWQM99V7pOQQBGTntG1xO+Hl/TmJkpY7tSKeiTU+F6KR6atfKvOn4LJYWc3LCyPl+us TnlRwCT52Hz281dXHOxc8y78X2PAHyNz9fyZC4mnGz0XKbEUZyQaajEXFScCAIXr9yjPAgAA X-MTR: 20000000000000000@CPGS X-CMS-MailID: 20170831093550eucas1p22dbb8abaa40c94a4f10d64d185c8c6a1 X-Msg-Generator: CA X-Sender-IP: 182.198.249.180 X-Local-Sender: =?UTF-8?B?UGV0ZXIgU3RlcGhlbnNvbhtTQ1NDLURhdGEgUGxhbmUb?= =?UTF-8?B?7IK87ISx7KCE7J6QG1ByaW5jaXBhbCBFbmdpbmVlciwgU29mdHdhcmU=?= X-Global-Sender: =?UTF-8?B?UGV0ZXIgU3RlcGhlbnNvbhtTQ1NDLURhdGEgUGxhbmUbU2Ft?= =?UTF-8?B?c3VuZyBFbGVjdHJvbmljcxtQcmluY2lwYWwgRW5naW5lZXIsIFNvZnR3YXJl?= X-Sender-Code: =?UTF-8?B?QzEwG0VIURtDMTBDRDA1Q0QwNTAwNTg=?= CMS-TYPE: 201P X-CMS-RootMailID: 20170830203746epcas4p13a2ca7201ee672dac3634b21add0d244 X-RootMTR: 20170830203746epcas4p13a2ca7201ee672dac3634b21add0d244 References: On Wed, 30 Aug 2017 20:36:48 +0000 Jan Alexander Steffens wrote: > Since recently (5.4.2?), there seems to be a bug involving err_return > during initialization. > > If I have a .zshrc with the following content: > > setopt err_return > true && function { > if false; then :; fi > echo 1 > } > echo 2 > > Then the "if false" causes the function to return and "1" is not printed. > Note that the behavior differs from running this file using "zsh .zshrc", > where both lines are printed, which I expect is the intended behavior. Yes, err_return (and err_exit which isn't affected by this problem) are supposed to be suppressed at that point in initialisation as in normal code. This shows up because initialisation is already specially handled and this was complicating the check for the state at that point. It seems that the extra special tweaks for the tweaks to support the option need some extra extra special tweaks. pws diff --git a/Src/loop.c b/Src/loop.c index 4859c97..7cd5219 100644 --- a/Src/loop.c +++ b/Src/loop.c @@ -541,8 +541,9 @@ execif(Estate state, int do_exec) olderrexit = noerrexit; end = state->pc + WC_IF_SKIP(code); - if (!noerrexit) - noerrexit = NOERREXIT_EXIT | NOERREXIT_RETURN; + /* Preserve special handling for init code */ + if (!noerrexit || (noerrexit & NOERREXIT_SIGNAL)) + noerrexit |= NOERREXIT_EXIT | NOERREXIT_RETURN; while (state->pc < end) { code = *state->pc++; if (wc_code(code) != WC_IF || @@ -570,9 +571,9 @@ execif(Estate state, int do_exec) if (olderrexit) noerrexit = olderrexit; else if (lastval) - noerrexit = NOERREXIT_EXIT | NOERREXIT_RETURN | NOERREXIT_UNTIL_EXEC; + noerrexit |= NOERREXIT_EXIT | NOERREXIT_RETURN | NOERREXIT_UNTIL_EXEC; else - noerrexit = 0; + noerrexit &= ~ (NOERREXIT_EXIT | NOERREXIT_RETURN); cmdpush(run == 2 ? CS_ELSE : (s ? CS_ELIFTHEN : CS_IFTHEN)); execlist(state, 1, do_exec); cmdpop(); diff --git a/Test/C03traps.ztst b/Test/C03traps.ztst index f8a1231..5794459 100644 --- a/Test/C03traps.ztst +++ b/Test/C03traps.ztst @@ -661,6 +661,25 @@ F:Must be tested with a top-level script rather than source or function >before-out >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 + (setopt err_exit for x in y; do false && true