zsh-workers
 help / color / mirror / code / Atom feed
* PATCH: 3.1.5-pws-4: minor setaparam() fixup for assoc. arrays
@ 1999-01-12 17:55 Bart Schaefer
  0 siblings, 0 replies; only message in thread
From: Bart Schaefer @ 1999-01-12 17:55 UTC (permalink / raw)
  To: zsh-workers

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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~1999-01-12 17:59 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-01-12 17:55 PATCH: 3.1.5-pws-4: minor setaparam() fixup for assoc. arrays Bart Schaefer

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).