patch 8.2.1949: Vim9: using extend() on null dict is silently ignored
Problem: Vim9: using extend() on null dict is silently ignored.
Solution: Give an error message. Initialize a dict variable with an empty
dictionary. (closes #7251)
diff --git a/src/evalvars.c b/src/evalvars.c
index a5db6e9..9c05c57 100644
--- a/src/evalvars.c
+++ b/src/evalvars.c
@@ -2553,7 +2553,22 @@
ret = FAIL;
}
else if (rettv != NULL)
+ {
+ // If a list or dict variable wasn't initialized, do it now.
+ if (tv->v_type == VAR_DICT && tv->vval.v_dict == NULL)
+ {
+ tv->vval.v_dict = dict_alloc();
+ if (tv->vval.v_dict != NULL)
+ ++tv->vval.v_dict->dv_refcount;
+ }
+ else if (tv->v_type == VAR_LIST && tv->vval.v_list == NULL)
+ {
+ tv->vval.v_list = list_alloc();
+ if (tv->vval.v_list != NULL)
+ ++tv->vval.v_list->lv_refcount;
+ }
copy_tv(tv, rettv);
+ }
}
name[len] = cc;