diff src/vim9compile.c @ 21648:33fec2448697 v8.2.1374

patch 8.2.1374: Vim9: error for assigning empty list to script variable Commit: https://github.com/vim/vim/commit/a71e2633207557c31432c954194078cb6062d04f Author: Bram Moolenaar <Bram@vim.org> Date: Wed Aug 5 15:11:03 2020 +0200 patch 8.2.1374: Vim9: error for assigning empty list to script variable Problem: Vim9: error for assigning empty list to script variable. Solution: Use t_unknown for empty list member. (closes https://github.com/vim/vim/issues/6595)
author Bram Moolenaar <Bram@vim.org>
date Wed, 05 Aug 2020 15:15:03 +0200
parents a640bc762196
children 79a8d723a3d2
line wrap: on
line diff
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -502,22 +502,25 @@ typval2type(typval_T *tv, garray_T *type
     if (tv->v_type == VAR_STRING)
 	return &t_string;
 
-    if (tv->v_type == VAR_LIST
-	    && tv->vval.v_list != NULL
-	    && tv->vval.v_list->lv_first != NULL)
-    {
+    if (tv->v_type == VAR_LIST)
+    {
+	if (tv->vval.v_list == NULL || tv->vval.v_list->lv_first == NULL)
+	    return &t_list_empty;
+
 	// Use the type of the first member, it is the most specific.
 	member_type = typval2type(&tv->vval.v_list->lv_first->li_tv, type_gap);
 	return get_list_type(member_type, type_gap);
     }
 
-    if (tv->v_type == VAR_DICT
-	    && tv->vval.v_dict != NULL
-	    && tv->vval.v_dict->dv_hashtab.ht_used > 0)
+    if (tv->v_type == VAR_DICT)
     {
 	dict_iterator_T iter;
 	typval_T	*value;
 
+	if (tv->vval.v_dict == NULL
+				   || tv->vval.v_dict->dv_hashtab.ht_used == 0)
+	    return &t_dict_empty;
+
 	// Use the type of the first value, it is the most specific.
 	dict_iterate_start(tv, &iter);
 	dict_iterate_next(&iter, &value);