summaryrefslogtreecommitdiffstats
path: root/src/eval.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2020-09-23 15:56:50 +0200
committerBram Moolenaar <Bram@vim.org>2020-09-23 15:56:50 +0200
commit81ed4960482f8baabdd7f95b4d5e39744be88ae7 (patch)
tree53339c1c9e90871169f6da1b8efb3eda6da691df /src/eval.c
parent04bdd573d0a48e789eb92ed2a81e0dd732761391 (diff)
patch 8.2.1731: Vim9: cannot use += to append to empty NULL listv8.2.1731
Problem: Vim9: cannot use += to append to empty NULL list. Solution: Copy the list instead of extending it. (closes #6998)
Diffstat (limited to 'src/eval.c')
-rw-r--r--src/eval.c28
1 files changed, 24 insertions, 4 deletions
diff --git a/src/eval.c b/src/eval.c
index 9b9b7f47ca..6c37e70d00 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -872,8 +872,7 @@ get_lval(
while (*p == '[' || (*p == '.' && lp->ll_tv->v_type == VAR_DICT))
{
if (!(lp->ll_tv->v_type == VAR_LIST && lp->ll_tv->vval.v_list != NULL)
- && !(lp->ll_tv->v_type == VAR_DICT
- && lp->ll_tv->vval.v_dict != NULL)
+ && !(lp->ll_tv->v_type == VAR_DICT)
&& !(lp->ll_tv->v_type == VAR_BLOB
&& lp->ll_tv->vval.v_blob != NULL))
{
@@ -994,7 +993,20 @@ get_lval(
}
}
lp->ll_list = NULL;
+
+ // a NULL dict is equivalent with an empty dict
+ if (lp->ll_tv->vval.v_dict == NULL)
+ {
+ lp->ll_tv->vval.v_dict = dict_alloc();
+ if (lp->ll_tv->vval.v_dict == NULL)
+ {
+ clear_tv(&var1);
+ return NULL;
+ }
+ ++lp->ll_tv->vval.v_dict->dv_refcount;
+ }
lp->ll_dict = lp->ll_tv->vval.v_dict;
+
lp->ll_di = dict_find(lp->ll_dict, key, len);
// When assigning to a scope dictionary check that a function and
@@ -1460,8 +1472,16 @@ tv_op(typval_T *tv1, typval_T *tv2, char_u *op)
if (*op != '+' || tv2->v_type != VAR_LIST)
break;
// List += List
- if (tv1->vval.v_list != NULL && tv2->vval.v_list != NULL)
- list_extend(tv1->vval.v_list, tv2->vval.v_list, NULL);
+ if (tv2->vval.v_list != NULL)
+ {
+ if (tv1->vval.v_list == NULL)
+ {
+ tv1->vval.v_list = tv2->vval.v_list;
+ ++tv1->vval.v_list->lv_refcount;
+ }
+ else
+ list_extend(tv1->vval.v_list, tv2->vval.v_list, NULL);
+ }
return OK;
case VAR_NUMBER: