patch 8.2.2272: Vim9: extend() can violate the type of a variable
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)
diff --git a/src/vim9execute.c b/src/vim9execute.c
index 5721c0e..5cfc327 100644
--- a/src/vim9execute.c
+++ b/src/vim9execute.c
@@ -2994,6 +2994,24 @@
}
break;
+ case ISN_SETTYPE:
+ {
+ checktype_T *ct = &iptr->isn_arg.type;
+
+ tv = STACK_TV_BOT(-1);
+ if (tv->v_type == VAR_DICT && tv->vval.v_dict != NULL)
+ {
+ free_type(tv->vval.v_dict->dv_type);
+ tv->vval.v_dict->dv_type = alloc_type(ct->ct_type);
+ }
+ else if (tv->v_type == VAR_LIST && tv->vval.v_list != NULL)
+ {
+ free_type(tv->vval.v_list->lv_type);
+ tv->vval.v_list->lv_type = alloc_type(ct->ct_type);
+ }
+ }
+ break;
+
case ISN_2BOOL:
case ISN_COND2BOOL:
{
@@ -3890,6 +3908,15 @@
iptr->isn_arg.checklen.cl_more_OK ? ">= " : "",
iptr->isn_arg.checklen.cl_min_len);
break;
+ case ISN_SETTYPE:
+ {
+ char *tofree;
+
+ smsg("%4d SETTYPE %s", current,
+ type_name(iptr->isn_arg.type.ct_type, &tofree));
+ vim_free(tofree);
+ break;
+ }
case ISN_COND2BOOL: smsg("%4d COND2BOOL", current); break;
case ISN_2BOOL: if (iptr->isn_arg.number)
smsg("%4d INVERT (!val)", current);