Subject: Re: [PATCH] typeset: set $? on incidental error
From: Peter Stephenson <[email-masked]>
To: zsh workers <[email-masked]>
Date: Fri, 15 Jan 2016 15:49:44 +0000
List-Id: Zsh Workers List <zsh-workers.zsh.org>

On Fri, 15 Jan 2016 09:54:37 -0500
Eric Cook <[email-masked]> wrote:
> But typeset should exit > 0 when it does fail to assign a parameter.

This looks about the minimal fix for this.

This is already a hard error, so will cause other stuff later in the
command to fail, however the error wasn't propagated properly within the
command handler.

pws

diff --git a/Src/builtin.c b/Src/builtin.c
index e1a7990..dd20f9e 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -2213,6 +2213,8 @@ typeset_single(char *cname, char *pname, Param pm, UNUSED(int func),
 				 mkarray(NULL), 0)))
 		return NULL;
 	}
+	if (errflag)
+	    return NULL;
 	pm->node.flags |= (on & PM_READONLY);
 	if (OPT_ISSET(ops,'p'))
 	    paramtab->printnode(&pm->node, PRINT_TYPESET);
diff --git a/Test/B02typeset.ztst b/Test/B02typeset.ztst
index 681fe73..d6d2421 100644
--- a/Test/B02typeset.ztst
+++ b/Test/B02typeset.ztst
@@ -706,3 +706,8 @@
 >typeset -a array=( '' two '' four )
 >typeset -a array=( one '' three )
 >no really nothing here
+
+  readonly isreadonly=yes
+  typeset isreadonly=still
+1:typeset returns status 1 if setting readonly variable
+?(eval):2: read-only variable: isreadonly