Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: New typeset is a bit too verbose, and skips some assignments



On Thu, 25 Jun 2015 09:21:31 -0700
Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> torch% typeset x=()
> torch% typeset x=() x[2]=a x[4]=b
> x=()
> torch% typeset -p x
> typeset -a x
> x=('' a '' b)
> torch% 
> 
> The value of x should not have been displayed by the second typeset in
> that example, because all the names have assignments.  It also looks
> wrong, because it's the value from before the assignments to elements.

That's related to my previous fix --- x=() causes x to be marked as an
array but with no value, not just an empty list.  However, the mere fact
that that assignment is marked as an array (this is completely separate
from the parameter currently being marked as an array or the typeset
having the -a flag, sob) means there was a value there originally, so
that's good enough to use to shut it up.

It's outputing x empty because it's only triggered by the x=() bit at
the start, i.e. exactly as if you'd put "x" there.

(NO_TYPESET_SILENT is pretty useless as a feature these days but it does
have a useful effect of showing up unnecessary declarations...)

pws

diff --git a/Src/builtin.c b/Src/builtin.c
index ba38406..bc68545 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -2141,7 +2141,8 @@ typeset_single(char *cname, char *pname, Param pm, UNUSED(int func),
 	    if (OPT_ISSET(ops,'p'))
 		paramtab->printnode(&pm->node, PRINT_TYPESET);
 	    else if (!OPT_ISSET(ops,'g') &&
-		     (unset(TYPESETSILENT) || OPT_ISSET(ops,'m')))
+		     (unset(TYPESETSILENT) || OPT_ISSET(ops,'m'))
+		     && !asg->is_array)
 		paramtab->printnode(&pm->node, PRINT_INCLUDEVALUE);
 	    return pm;
 	}



Messages sorted by: Reverse Date, Date, Thread, Author