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

Re: Inconsistency of GLOB_ASSIGN



NOTE:  The two patches included in this message are mutually exclusive.
Do not attempt to apply both of them on top of one another.

On Nov 27,  1:38pm, Bart Schaefer wrote:
}
} On Nov 27,  8:43pm, Peter Stephenson wrote:
} }
} } It would be neater always to do an array assignment, in fact, but
} } the traditional behaviour is that if there was only one result the
} } assignment is scalar
} 
} That's too bad, because making it always be an array assignment is a
} lot simpler than figuring out whether the glob expanded to something.

So in actuality, not too much different.  Below are two patches, pick
one ... both need the haswilds() test to preserve the behavior of
assigning a non-glob-string-that-looks-like-math to an integer/float.

Here is the patch for making the assigment always be an array:

--- 8< --- snip --- 8< ---
diff --git a/Src/exec.c b/Src/exec.c
index 02a8fe3..702b731 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -2243,8 +2243,11 @@ addvars(Estate state, Wordcode pc, int addflags)
 		state->pc = opc;
 		return;
 	    }
-	    if (isset(GLOBASSIGN) || !isstr)
+	    if (!isstr || (isset(GLOBASSIGN) &&
+			   haswilds((char *)getdata(firstnode(vl))))) {
 		globlist(vl, 0);
+		isstr = 0;
+	    }
 	    if (errflag) {
 		state->pc = opc;
 		return;
--- >8 --- snip --- >8 ---

And here is the patch for making the type scalar or array based on how
many results got returned:

--- 8< --- snip --- 8< ---
diff --git a/Src/exec.c b/Src/exec.c
index 02a8fe3..2b7c55f 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -2243,8 +2243,16 @@ addvars(Estate state, Wordcode pc, int addflags)
 		state->pc = opc;
 		return;
 	    }
-	    if (isset(GLOBASSIGN) || !isstr)
+	    if (!isstr || (isset(GLOBASSIGN) &&
+			   haswilds((char *)getdata(firstnode(vl))))) {
 		globlist(vl, 0);
+		/* Unset the parameter to force it to be recreated
+		 * as either scalar or array depending on how many
+		 * matches were found for the glob.
+		 */
+		if (isset(GLOBASSIGN))
+		    unsetparam(name);
+	    }
 	    if (errflag) {
 		state->pc = opc;
 		return;
--- >8 --- snip --- >8 ---


All tests (except X02zlevi some of the time) still pass with either of
the above, but there may be hidden consequences of each.



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