about summary refs log tree commit diff
diff options
context:
space:
mode:
authorBart Schaefer <schaefer@zsh.org>2024-02-28 20:40:26 -0800
committerBart Schaefer <schaefer@zsh.org>2024-02-28 20:40:26 -0800
commit85172998f499cb789570714ffdd43f1ca3b53e58 (patch)
tree793f9ab6e74b256171e5aafa8e778e60fb1ea7f7
parent69c58874611a586c68be14ce7965029dc00f41b7 (diff)
downloadzsh-85172998f499cb789570714ffdd43f1ca3b53e58.tar.gz
zsh-85172998f499cb789570714ffdd43f1ca3b53e58.tar.xz
zsh-85172998f499cb789570714ffdd43f1ca3b53e58.zip
52619 (plus tests): no empty element when appending array to unset scalar
-rw-r--r--ChangeLog7
-rw-r--r--Src/params.c2
-rw-r--r--Test/A06assign.ztst21
3 files changed, 24 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index e836a3853..9ab0218c9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2024-02-28  Bart Schaefer  <schaefer@zsh.org>
+
+	* 52619 (plus tests): Src/params.c, Test/A06assign.ztst: there
+	is no empty element when appending array to unset scalar
+
 2024-02-28  Oliver Kiddle  <opk@zsh.org>
 
 	* 52622 (tweaked, c.f. 52626): Src/jobs.c: adjust number of columns
@@ -54,7 +59,7 @@ x2024-02-19  Jun-ichi Takimoto  <takimoto-j@kba.biglobe.ne.jp>
 	* 52544: Completion/Unix/Type/_diff_options: support macOS Ventura
 	or newer
 
-2024-02-18  Bart Schaefer  <schaefer@toltec-ubuntu>
+2024-02-18  Bart Schaefer  <schaefer@zsh.org>
 
 	* 52558: Etc/FAQ.yo: make note of word splitting differences
 	with nofork substitutions; update ToC; minor formatting fixes
diff --git a/Src/params.c b/Src/params.c
index 7c5e9d8ff..064dbd2bc 100644
--- a/Src/params.c
+++ b/Src/params.c
@@ -3355,7 +3355,7 @@ assignaparam(char *s, char **val, int flags)
 	} else if (!(PM_TYPE(v->pm->node.flags) & (PM_ARRAY|PM_HASHED)) &&
 		 !(v->pm->node.flags & (PM_SPECIAL|PM_TIED))) {
 	    int uniq = v->pm->node.flags & PM_UNIQUE;
-	    if (flags & ASSPM_AUGMENT) {
+	    if ((flags & ASSPM_AUGMENT) && !(v->pm->node.flags & PM_UNSET)) {
 	    	/* insert old value at the beginning of the val array */
 		char **new;
 		int lv = arrlen(val);
diff --git a/Test/A06assign.ztst b/Test/A06assign.ztst
index f89edb888..3eff5331a 100644
--- a/Test/A06assign.ztst
+++ b/Test/A06assign.ztst
@@ -296,13 +296,26 @@
 
 # tests of var+=(array)
 
+ a=
+ a+=(1 2 3)
+ print "${(q@)a}"
+0:add array to empty parameter
+>'' 1 2 3
+
  unset a
  a+=(1 2 3)
- print -l $a
+ print "${(q@)a}"
 0:add array to unset parameter
->1
->2
->3
+>1 2 3
+
+ () {
+  setopt localoptions typeset_to_unset
+  typeset a
+  a+=(1 2 3)
+  print "${(q@)a}"
+ }
+0:add array to declared unset parameter
+>1 2 3
 
  a=(a)
  a+=(b)