summaryrefslogtreecommitdiffstats
path: root/src/dict.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2021-01-02 15:41:03 +0100
committerBram Moolenaar <Bram@vim.org>2021-01-02 15:41:03 +0100
commitaa210a3aeccc33c6051978017959126b037f94af (patch)
tree29c2f91c51dc55a52e427f89643ae4b9c4c56c58 /src/dict.c
parent3e0107ea16349b354e0e9712e95b09ef019e99e5 (diff)
patch 8.2.2272: Vim9: extend() can violate the type of a variablev8.2.2272
Problem: Vim9: extend() can violate the type of a variable. Solution: Add the type to the dictionary or list and check items against it. (closes #7593)
Diffstat (limited to 'src/dict.c')
-rw-r--r--src/dict.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/dict.c b/src/dict.c
index 5abb9964ae..fc8756c57b 100644
--- a/src/dict.c
+++ b/src/dict.c
@@ -107,6 +107,8 @@ rettv_dict_set(typval_T *rettv, dict_T *d)
dict_free_contents(dict_T *d)
{
hashtab_free_contents(&d->dv_hashtab);
+ free_type(d->dv_type);
+ d->dv_type = NULL;
}
/*
@@ -1057,6 +1059,12 @@ dict_extend(dict_T *d1, dict_T *d2, char_u *action)
hashitem_T *hi2;
int todo;
char_u *arg_errmsg = (char_u *)N_("extend() argument");
+ type_T *type;
+
+ if (d1->dv_type != NULL && d1->dv_type->tt_member != NULL)
+ type = d1->dv_type->tt_member;
+ else
+ type = NULL;
todo = (int)d2->dv_hashtab.ht_used;
for (hi2 = d2->dv_hashtab.ht_array; todo > 0; ++hi2)
@@ -1076,6 +1084,11 @@ dict_extend(dict_T *d1, dict_T *d2, char_u *action)
if (!valid_varname(hi2->hi_key, TRUE))
break;
}
+
+ if (type != NULL
+ && check_typval_type(type, &HI2DI(hi2)->di_tv, 0) == FAIL)
+ break;
+
if (di1 == NULL)
{
di1 = dictitem_copy(HI2DI(hi2));