patch 8.2.4634: Vim9: cannot initialize a variable to null_list
Problem: Vim9: cannot initialize a variable to null_list.
Solution: Give negative count to NEWLIST. (closes #10027)
Also fix inconsistencies in comparing with null values.
diff --git a/src/evalvars.c b/src/evalvars.c
index 058e804..19a0f33 100644
--- a/src/evalvars.c
+++ b/src/evalvars.c
@@ -2816,11 +2816,13 @@
type = sv->sv_type;
}
- // If a list or dict variable wasn't initialized, do it now.
- // Not for global variables, they are not declared.
+ // If a list or dict variable wasn't initialized and has meaningful
+ // type, do it now. Not for global variables, they are not
+ // declared.
if (ht != &globvarht)
{
- if (tv->v_type == VAR_DICT && tv->vval.v_dict == NULL)
+ if (tv->v_type == VAR_DICT && tv->vval.v_dict == NULL
+ && type != NULL && type != &t_dict_empty)
{
tv->vval.v_dict = dict_alloc();
if (tv->vval.v_dict != NULL)
@@ -2829,7 +2831,8 @@
tv->vval.v_dict->dv_type = alloc_type(type);
}
}
- else if (tv->v_type == VAR_LIST && tv->vval.v_list == NULL)
+ else if (tv->v_type == VAR_LIST && tv->vval.v_list == NULL
+ && type != NULL && type != &t_list_empty)
{
tv->vval.v_list = list_alloc();
if (tv->vval.v_list != NULL)
@@ -2838,12 +2841,6 @@
tv->vval.v_list->lv_type = alloc_type(type);
}
}
- else if (tv->v_type == VAR_BLOB && tv->vval.v_blob == NULL)
- {
- tv->vval.v_blob = blob_alloc();
- if (tv->vval.v_blob != NULL)
- ++tv->vval.v_blob->bv_refcount;
- }
}
copy_tv(tv, rettv);
}