From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4005 invoked by alias); 15 Jan 2016 06:26:53 -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: 37637 Received: (qmail 2476 invoked from network); 15 Jan 2016 06:26:50 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.0 Date: Fri, 15 Jan 2016 06:26:45 +0000 From: Daniel Shahaf To: Eric Cook Cc: zsh-workers@zsh.org Subject: Re: [PATCH] typeset: set $? on incidental error Message-ID: <20160115062645.GB12223@tarsus.local2> References: <20160114001336.GA11173@tarsus.local2> <56973114.90807@gmx.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <56973114.90807@gmx.com> User-Agent: Mutt/1.5.23 (2014-03-12) Eric Cook wrote on Thu, Jan 14, 2016 at 00:24:36 -0500: > On 01/13/2016 07:13 PM, Daniel Shahaf wrote: > > The 'typeset' family of builtins doesn't set $? when one would expect it > > to do so: > > > > % x=$(true) y=$(exit 42); echo $? > > 42 > > % local x=$(true) y=$(exit 42); echo $? > > 0 > > > > This patch makes 'typeset' behave as ordiary assignment does. > > > But who expects that? I did. I ran into this in practice: . https://github.com/zsh-users/zsh-syntax-highlighting/blob/28932316cca6004253ec57f5d87981c72be64e86/tests/test-highlighting.zsh#L118-L121 118 run_test() { 119 # Do not combine the declaration and initialization: «local x="$(false)"» does not set $?. 120 local __tests_tempdir 121 __tests_tempdir="$(mktemp -d)" && [[ -d $__tests_tempdir ]] || { . Having such comments in source code suggests the language semantics are surprising / non-obvious. This was also reported to debian years ago (http://bugs.debian.org/479841). > no other shell with a typeset behaves that way. So if this change is made, zsh users who switch to other shells might be surprised that those other shells don't set $? of typeset. On the other hand, if we agree that «typeset x=$(exit 42)» should set $?, then perhaps zsh can be the first to implement that and other shells will follow. Somebody has to be the first shell to change behaviour, after all. Cheers, Daniel