mirror of
https://github.com/vim/vim.git
synced 2025-09-24 03:44:06 -04:00
patch 8.2.1731: Vim9: cannot use += to append to empty NULL list
Problem: Vim9: cannot use += to append to empty NULL list. Solution: Copy the list instead of extending it. (closes #6998)
This commit is contained in:
28
src/eval.c
28
src/eval.c
@@ -872,8 +872,7 @@ get_lval(
|
|||||||
while (*p == '[' || (*p == '.' && lp->ll_tv->v_type == VAR_DICT))
|
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)
|
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->v_type == VAR_DICT)
|
||||||
&& lp->ll_tv->vval.v_dict != NULL)
|
|
||||||
&& !(lp->ll_tv->v_type == VAR_BLOB
|
&& !(lp->ll_tv->v_type == VAR_BLOB
|
||||||
&& lp->ll_tv->vval.v_blob != NULL))
|
&& lp->ll_tv->vval.v_blob != NULL))
|
||||||
{
|
{
|
||||||
@@ -994,7 +993,20 @@ get_lval(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
lp->ll_list = NULL;
|
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_dict = lp->ll_tv->vval.v_dict;
|
||||||
|
|
||||||
lp->ll_di = dict_find(lp->ll_dict, key, len);
|
lp->ll_di = dict_find(lp->ll_dict, key, len);
|
||||||
|
|
||||||
// When assigning to a scope dictionary check that a function and
|
// 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)
|
if (*op != '+' || tv2->v_type != VAR_LIST)
|
||||||
break;
|
break;
|
||||||
// List += List
|
// List += List
|
||||||
if (tv1->vval.v_list != NULL && tv2->vval.v_list != NULL)
|
if (tv2->vval.v_list != NULL)
|
||||||
list_extend(tv1->vval.v_list, 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;
|
return OK;
|
||||||
|
|
||||||
case VAR_NUMBER:
|
case VAR_NUMBER:
|
||||||
|
@@ -223,6 +223,20 @@ def Test_assignment()
|
|||||||
endif
|
endif
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
|
def Test_extend_list()
|
||||||
|
let lines =<< trim END
|
||||||
|
vim9script
|
||||||
|
let l: list<number>
|
||||||
|
l += [123]
|
||||||
|
assert_equal([123], l)
|
||||||
|
|
||||||
|
let d: dict<number>
|
||||||
|
d['one'] = 1
|
||||||
|
assert_equal(#{one: 1}, d)
|
||||||
|
END
|
||||||
|
CheckScriptSuccess(lines)
|
||||||
|
enddef
|
||||||
|
|
||||||
def Test_single_letter_vars()
|
def Test_single_letter_vars()
|
||||||
# single letter variables
|
# single letter variables
|
||||||
let a: number = 123
|
let a: number = 123
|
||||||
|
@@ -750,6 +750,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
1731,
|
||||||
/**/
|
/**/
|
||||||
1730,
|
1730,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user