Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm
Precedence: bulk
X-No-Archive: yes
List-Id: Zsh Workers List <zsh-workers.zsh.org>
List-Post: <mailto:zsh-workers@zsh.org>
List-Help: <mailto:zsh-workers-help@zsh.org>
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 <d.s@daniel.shahaf.name>
To: Eric Cook <llua@gmx.com>
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)
X-Seq: zsh-workers 37637

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

