about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Stephenson <pws@zsh.org>2015-11-20 11:18:16 +0000
committerPeter Stephenson <pws@zsh.org>2015-11-20 11:18:16 +0000
commit72a67716aca9896cb75a2b92457fdaed060d8e9e (patch)
treec363f3aa4d587bed22ea3737da1b7f666e96bcd9
parentc563f1ba83c40aab632ac958a1d3a57277ca22cc (diff)
downloadzsh-72a67716aca9896cb75a2b92457fdaed060d8e9e.tar.gz
zsh-72a67716aca9896cb75a2b92457fdaed060d8e9e.tar.xz
zsh-72a67716aca9896cb75a2b92457fdaed060d8e9e.zip
20974: Bug with scalar assignment to special array in typeset
-rw-r--r--ChangeLog5
-rw-r--r--Src/builtin.c24
-rw-r--r--Test/D04parameter.ztst19
3 files changed, 44 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index 252f2fc5f..7a507fe00 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2015-11-20  Peter Stephenson  <p.stephenson@samsung.com>
+
+	* 20974: Src/builtin.c, Test/D04parameter.ztst: fix bug
+	when scalar value assigned to special array in typeset.
+
 2015-11-20  Daniel Shahaf  <d.s@daniel.shahaf.name>
 
 	* 37164: Completion/Unix/Command/_tmux: _tmux: Complete external
diff --git a/Src/builtin.c b/Src/builtin.c
index 18dfdce05..01eb5b84c 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -2438,10 +2438,26 @@ typeset_single(char *cname, char *pname, Param pm, UNUSED(int func),
     if (ASG_VALUEP(asg) && !dont_set) {
 	Param ipm = pm;
 	if (pm->node.flags & (PM_ARRAY|PM_HASHED)) {
-	    DPUTS(!ASG_ARRAYP(asg), "BUG: inconsistent scalar value for array");
-	    if (!(pm=assignaparam(pname, asg->value.array ?
-				  zlinklist2array(asg->value.array) :
-				  mkarray(NULL), 0)))
+	    char **arrayval;
+	    if (!ASG_ARRAYP(asg)) {
+		/*
+		 * Attempt to assign a scalar value to an array.
+		 * This can happen if the array is special.
+		 * We'll be lenient and guess what the user meant.
+		 * This is how normal assigment works.
+		 */
+		if (*asg->value.scalar) {
+		    /* Array with one value */
+		    arrayval = mkarray(ztrdup(asg->value.scalar));
+		} else {
+		    /* Empty array */
+		    arrayval = mkarray(NULL);
+		}
+	    } else if (asg->value.array)
+		arrayval = zlinklist2array(asg->value.array);
+	    else
+		arrayval = mkarray(NULL);
+	    if (!(pm=assignaparam(pname, arrayval, 0)))
 		return NULL;
 	} else {
 	    DPUTS(ASG_ARRAYP(asg), "BUG: inconsistent array value for scalar");
diff --git a/Test/D04parameter.ztst b/Test/D04parameter.ztst
index 210c0d854..a3c5d71df 100644
--- a/Test/D04parameter.ztst
+++ b/Test/D04parameter.ztst
@@ -1847,3 +1847,22 @@
 0:nested parameter name references
 >all these worlds belong to foo
 >worlds
+
+  (
+  path=(/random /value)
+  testfn1() {
+    local path=
+    print $#path
+  }
+  testfn1
+  testfn2() {
+    local path=/somewhere
+    print $#path $path
+  }
+  testfn2
+  print $#path $path
+  )
+0:Local special variables with loose typing
+>0
+>1 /somewhere
+>2 /random /value