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

[PATCH] Appending an array to a scalar



On Mon, Feb 26, 2024 at 6:51 PM Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
>
> % x+=(a b)
> % typeset -p x
> typeset -a x=( '' a b )
>
> This has been the case for as long as += has been around, as far as I
> can tell.  Works this way even with typesettounset

Hm, this is actually consistent with ksh, except for the
typesettounset bit, which is a recent addition.

diff --git a/Src/params.c b/Src/params.c
index 225acb8a1..8fb73f6a0 100644
--- a/Src/params.c
+++ b/Src/params.c
@@ -3345,7 +3345,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);




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