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

PATCH: 3.1.5-pws-4: minor setaparam() fixup for assoc. arrays



Consider the following:

zsh% typeset -A assoc
zsh% : ${(A)assoc[key]::=x y z}

This actually "worked" fine and set $assoc[key] to be the array (x y z).
However, none of the other substitution code is ready to have associative
arrays contain anything but scalars.  The following patch turns the above
fragment into an error case, and improves the error message in the case of

zsh% : ${(AA)=assoc[key]::=x y z}

I had mentioned before that perhaps that case should be changed to not
produce an error, but upon reflection I think it's better as it is.  To
assign to a single field of an associative array using the ${...:=...}
syntax, simply write

zsh% : ${assoc[key]::=value}

which already works with the obvious meaning (no change in this patch).

Index: Src/params.c
===================================================================
--- params.c	1999/01/11 02:19:45	1.20
+++ params.c	1999/01/12 16:51:55
@@ -1534,6 +1534,12 @@
 	if (!(v = getvalue(&s, 1)))
 	    createparam(t, PM_ARRAY);
 	*ss = '[';
+	if (PM_TYPE(v->pm->flags) == PM_HASHED) {
+	    zerr("attempt to set slice of associative array", NULL, 0);
+	    freearray(val);
+	    errflag = 1;
+	    return NULL;
+	}
 	v = NULL;
     } else {
 	if (!(v = getvalue(&s, 1)))
@@ -1571,7 +1577,7 @@
     }
     if (strchr(s, '[')) {
 	freearray(val);
-	zerr("attempt to set slice of associative array", NULL, 0);
+	zerr("nested associative arrays not yet supported", NULL, 0);
 	errflag = 1;
 	return NULL;
     } else {

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com



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