summaryrefslogtreecommitdiff
path: root/src/list.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2022-02-02 20:01:27 +0000
committerBram Moolenaar <Bram@vim.org>2022-02-02 20:01:27 +0000
commit381692b6f1c2ec9b73a139500286ddc9347a1c01 (patch)
tree96145ec58ad29dd86bbc80e557377333c07d059b /src/list.c
parenta1c519518050383e7d319514a3ff6c42a9154c48 (diff)
downloadvim-git-381692b6f1c2ec9b73a139500286ddc9347a1c01.tar.gz
patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy()v8.2.4286
Problem: Vim9: strict type checking after copy() and deepcopy(). Solution: Allow type to change after making a copy. (closes #9644)
Diffstat (limited to 'src/list.c')
-rw-r--r--src/list.c17
1 files changed, 9 insertions, 8 deletions
diff --git a/src/list.c b/src/list.c
index ff7d5ab9b..86c16793f 100644
--- a/src/list.c
+++ b/src/list.c
@@ -1015,7 +1015,7 @@ flatten_common(typval_T *argvars, typval_T *rettv, int make_copy)
if (make_copy)
{
- l = list_copy(l, TRUE, get_copyID());
+ l = list_copy(l, TRUE, TRUE, get_copyID());
rettv->vval.v_list = l;
if (l == NULL)
return;
@@ -1102,7 +1102,7 @@ list_concat(list_T *l1, list_T *l2, typval_T *tv)
if (l1 == NULL)
l = list_alloc();
else
- l = list_copy(l1, FALSE, 0);
+ l = list_copy(l1, FALSE, TRUE, 0);
if (l == NULL)
return FAIL;
tv->v_type = VAR_LIST;
@@ -1200,11 +1200,11 @@ list_slice_or_index(
/*
* Make a copy of list "orig". Shallow if "deep" is FALSE.
* The refcount of the new list is set to 1.
- * See item_copy() for "copyID".
+ * See item_copy() for "top" and "copyID".
* Returns NULL when out of memory.
*/
list_T *
-list_copy(list_T *orig, int deep, int copyID)
+list_copy(list_T *orig, int deep, int top, int copyID)
{
list_T *copy;
listitem_T *item;
@@ -1216,7 +1216,7 @@ list_copy(list_T *orig, int deep, int copyID)
copy = list_alloc();
if (copy != NULL)
{
- copy->lv_type = alloc_type(orig->lv_type);
+ copy->lv_type = alloc_type(top || deep ? &t_list_any: orig->lv_type);
if (copyID != 0)
{
// Do this before adding the items, because one of the items may
@@ -1233,7 +1233,8 @@ list_copy(list_T *orig, int deep, int copyID)
break;
if (deep)
{
- if (item_copy(&item->li_tv, &ni->li_tv, deep, copyID) == FAIL)
+ if (item_copy(&item->li_tv, &ni->li_tv,
+ deep, FALSE, copyID) == FAIL)
{
vim_free(ni);
break;
@@ -2701,11 +2702,11 @@ list_extend_func(
}
l2 = argvars[1].vval.v_list;
if ((is_new || !value_check_lock(l1->lv_lock, arg_errmsg, TRUE))
- && l2 != NULL)
+ && l2 != NULL)
{
if (is_new)
{
- l1 = list_copy(l1, FALSE, get_copyID());
+ l1 = list_copy(l1, FALSE, TRUE, get_copyID());
if (l1 == NULL)
return;
}