]> granicus.if.org Git - vim/commitdiff
patch 8.2.1374: Vim9: error for assigning empty list to script variable v8.2.1374
authorBram Moolenaar <Bram@vim.org>
Wed, 5 Aug 2020 13:11:03 +0000 (15:11 +0200)
committerBram Moolenaar <Bram@vim.org>
Wed, 5 Aug 2020 13:11:03 +0000 (15:11 +0200)
Problem:    Vim9: error for assigning empty list to script variable.
Solution:   Use t_unknown for empty list member. (closes #6595)

src/testdir/test_vim9_script.vim
src/version.c
src/vim9compile.c

index f99333c0cbb4fd9627953ac664460b2eeaf2e12f..c50a0d337a78e8162c174f1c68e81d3e58bd8f9c 100644 (file)
@@ -2782,6 +2782,20 @@ def Test_let_type_check()
     let var: asdf
   END
   CheckScriptFailure(lines, 'E1010:')
+
+  lines =<< trim END
+    vim9script
+    let s:l: list<number>
+    s:l = []
+  END
+  CheckScriptSuccess(lines)
+
+  lines =<< trim END
+    vim9script
+    let s:d: dict<number>
+    s:d = {}
+  END
+  CheckScriptSuccess(lines)
 enddef
 
 def Test_forward_declaration()
index 7b1b8d8c2199ab8dd1d0f8c6852790afbb1638fe..abf2af0c723b37e5f29b0d98a9cd0d3085ca4582 100644 (file)
@@ -754,6 +754,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1374,
 /**/
     1373,
 /**/
index dc10b4851b8b5caca7930e5877956f10a5d9f6bd..e87634b31bab524c4da286573ee69369a65d23f1 100644 (file)
@@ -502,22 +502,25 @@ typval2type(typval_T *tv, garray_T *type_gap)
     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);