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

PATCH: unset and assoc (was Re: Let's finish this new completion stuff)



Bart Schaefer wrote:

> zagzig% typeset -A foo
> zagzig% echo ${+foo[x]}
> 1
> zagzig% typeset -a bar
> zagzig% echo ${+bar[x]}
> 0
> 
> That is, all fields of associative arrays currently appear to be set,
> even when they aren't; this is not true of plain arrays.

The problem was that at the time the lookup in the hastable occurs,
there is an struct pm for it with the PM_UNSET flag set. The patch
below makes this flag be tested in subst.c. I think this is the
simplest solution and the tests I did worked, does anyone see any
problems with this?

Bye
 Sven

--- os/subst.c	Mon Feb 22 10:49:23 1999
+++ Src/subst.c	Tue Feb 23 13:47:42 1999
@@ -999,11 +999,12 @@
 
 	if (!(v = fetchvalue((subexp ? &ov : &s), (wantt ? -1 :
 				  ((unset(KSHARRAYS) || inbrace) ? 1 : -1)),
-			     hkeys|hvals)))
+			     hkeys|hvals)) ||
+	    (v->pm && (v->pm->flags & PM_UNSET)))
 	    vunset = 1;
 
 	if (wantt) {
-	    if (v) {
+	    if (v && v->pm && !(v->pm->flags & PM_UNSET)) {
 		int f = v->pm->flags;
 
 		switch (PM_TYPE(f)) {

--
Sven Wischnowsky                         wischnow@xxxxxxxxxxxxxxxxxxxxxxx



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