From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.3 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 2719 invoked from network); 7 Dec 2022 16:01:37 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 7 Dec 2022 16:01:37 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1670428897; b=CZRM4P7kTXD4jrDQH9afbFmN0+gdp5F6fUYgo+g8siQYg2hWgiOToCSyr9R3yxGJmA6978otPY CwUPczu4YYGc/v7PcvoLOLmZxbRyaAQ4i91bAPcfvyPQy2RgGQwUUp1O5HOegDRoDm8VsY/fYZ XxfWqMrRFFH3t2nXe+FRQR+Td2fmfFrYrQjaCblzpM9+6s3FjRDqyVhYzJ9NQAvNxiCveB9Sxe 9xQni3A0hFk0LWPVTDxuYea7EYJ1plAaxvAe39AAx5x08ADGgQaLdws0BoSWH50WZiTVmykX/A Q+P41SxSF6u/uYt+I3X2MmsTKO6DDRCrghcpQ9fU8dARTQ==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (relay8-d.mail.gandi.net) smtp.remote-ip=217.70.183.201; dmarc=none header.from=chazelas.org; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1670428897; bh=O0c10vTd2XxvZ7SUl1gz8q5duiLHUjkwOIad9ceCjo0=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:In-Reply-To:Content-Type:MIME-Version:References:Message-ID: Subject:Cc:To:From:Date:DKIM-Signature; b=MR0N09EJKrr+2QXstJLVixOE5eBi9+B36d7oCB1mPOsNGuNV+O9rm7ukn+SNRy2z3MnCldepAe GZz47cUYXka0q9SmN34QVuMWAGqLfHw8jfTwvE4rsPxi8mS6YozDuLAL2cN/h38EWaOmlUQJwl 7is1Rc9KvATlXqFkV4sFLkz6H4AL3FcokfE3bjjjmCeGqHWopPMcEYl6RWt+38WnBRI3Mi7yG4 4gT9Nbbfesi4jPKtqHZug5QJtsG0gPTH/5E6Ls88p21aTUMMEAWunDx/JP2oDQeXoG1ZFlw+2j ZOlvx0TNg9T4VTarIqFsM1MiwiQgz0NjojPWPBWjC8grKg==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20210803; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=3BOm0rq+ngdTCYxxnEjGZ45flgYqSTHl15MqdsMBiCM=; b=jFpjthfef++GpjeHEDueiB/H+1 Dfao9g6sZYVdHaq5fRgXlrfEKalJ3kWevosHIW0bHdy5q/k731gTMXf2HPXdMOVagiZjktVDtMl1J Rwb9hH9JTkgZzlnnDNMvopkwhZQO4OZK1F89W3g4WkwlUpVUrQYmP01Vi+z3Rn7Gwb+iDjFYDeGi1 mjUe+HaTXk0QH+5fWtoC+OrsaD+xB/WiPVPX68o00sAjIyJT4KZAvJFEGdZJ9mFgDGxBOpvJEkCpv RhMeCh/v+DNVu11hVlTDVTcvfLoK8uJOz9fqQtZgPUx7sGCDLKdu+UKGnHhCwxiUYefzX7TIcKJSz CIICI7mA==; Received: by zero.zsh.org with local id 1p2wrY-000M6z-Ro; Wed, 07 Dec 2022 16:01:36 +0000 Authentication-Results: zsh.org; iprev=pass (relay8-d.mail.gandi.net) smtp.remote-ip=217.70.183.201; dmarc=none header.from=chazelas.org; arc=none Received: from relay8-d.mail.gandi.net ([217.70.183.201]:36551) by zero.zsh.org with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) id 1p2wrF-000Lp7-2Z; Wed, 07 Dec 2022 16:01:18 +0000 Received: (Authenticated sender: stephane@chazelas.org) by mail.gandi.net (Postfix) with ESMTPSA id EB7D11BF21C; Wed, 7 Dec 2022 16:01:14 +0000 (UTC) Date: Wed, 7 Dec 2022 16:01:13 +0000 From: Stephane Chazelas To: Michael Greenberg Cc: Bart Schaefer , zsh-workers@zsh.org Subject: Re: `return` does not behave properly under `!` Message-ID: <20221207160113.ol3lcbm6p7xu3rru@chazelas.org> Mail-Followup-To: Michael Greenberg , Bart Schaefer , zsh-workers@zsh.org References: <20221207084255.ykkg6cgzn4nqc73f@chazelas.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Seq: 51113 Archived-At: X-Loop: zsh-workers@zsh.org Errors-To: zsh-workers-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-workers-request@zsh.org X-no-archive: yes List-Id: List-Help: , List-Subscribe: , List-Unsubscribe: , List-Post: List-Owner: List-Archive: 2022-12-07 10:05:34 -0500, Michael Greenberg: > Hi Stephane and Bart (reply inline below, as it's relevant to Stephane), [...] > So my reading is the opposite: `return` doesn't have an exit status, > because it causes the currently executing function (or sourced script) > to terminate; it does, however, set $?. So `!` shouldn't affect it. [...] Agreed. > But even without a close reading of the spec, it's just not how early > return works in any language. Having the evaluation context beyond > `return` affect the returned value subverts the early and immediate > return---and, in so doing, invites bugs. [...] Agreed. > So far, dash, yash, and zsh are the only shells I've found with this > behavior, and the dash folks seem to agree that it's an undesirable > bug. And also... Also bosh. I can't see why one would call ! return if not to expect that to have an effect on the exit status. $ zsh -c 'f() { ! { false || return; }; }; f; echo "$?"' 0 Is more of a problem though and I agree would be an undesirable bug.. [...] > Ah---thank you! I wish there were a straightforward fulltext search of > the archives (though I don't know I would have found this anyway, as it > doesn't explicitly mention `return`). I'll try to test these patches to > confirm. You can download and rsync the full archive from rsync://rsync.zsh.org/mla/zsh-workers/ And search in there. $ rsync rsync.zsh.org:: ======================================================== ZSH FTP primary site (rsync.zsh.org) Example usage: rsync -av --delete rsync://rsync.zsh.org/pub /local/path/to/zsh/pub Always do a dry run (-n) first or --delete may bite you! ======================================================== Modules: ======================================================== pub Zsh FTP Pub directory (~280MB as of Feb 2010) mla Zsh Mailing List Archive directory (~333MB as of Feb 2010) > > That's consistent with ! break causing the while/until loop it's > > in returning with failure which I've seen code rely upon (AFAIK, > > that's the only way to get those loops to return with failure; > > doesn't work in pdksh and derivatives though). > > That seems hardly relevant here: a return explicitly sets $?, unlike > break/continue (which both have exit statuses, unlike return). [...] They're still special builtins that break the flow, so I would still consider it relevant. I've not checked zsh recently but there are funny things you can do with some shells by calling break/continue in a function where the corresponding "enclosing" loop is in one of the callers. IIRC there was some POSIX discussion about that and the text tightened. -- Stephane