]> granicus.if.org Git - vim/commitdiff
patch 8.2.1758: Vim9: type of unmaterialized list is wrong v8.2.1758
authorBram Moolenaar <Bram@vim.org>
Sun, 27 Sep 2020 15:45:03 +0000 (17:45 +0200)
committerBram Moolenaar <Bram@vim.org>
Sun, 27 Sep 2020 15:45:03 +0000 (17:45 +0200)
Problem:    Vim9: type of unmaterialized list is wrong.
Solution:   Use list<number>.

src/testdir/test_vim9_expr.vim
src/version.c
src/vim9type.c

index 411ed7017484ec81960ff2758212101657422bcc..fe43e80e1f8cffecc6a3335e7bf97f9c17d89d51 100644 (file)
@@ -1517,6 +1517,10 @@ def Test_expr7_list()
   llstring = [[], ['text']]
   llstring = [[], []]
 
+  var rangelist: list<number> = range(3)
+  g:rangelist = range(3)
+  CheckDefExecFailure(["var x: list<string> = g:rangelist"], 'E1012: Type mismatch; expected list<string> but got list<number>', 1)
+
   CheckDefFailure(["let x = 1234[3]"], 'E1107:', 1)
   CheckDefExecFailure(["let x = g:anint[3]"], 'E1062:', 1)
 
index 9ef77d87a0d5eb854b3e90fa54d481fd572d888b..ed7b44933e25a19f0669068188b72eebca4e0d4d 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1758,
 /**/
     1757,
 /**/
index c7e3dde32cf2cc2dc20fe2345bff55b2c57cba3f..931b575b6673b98821154512a6a3cc15098ea89a 100644 (file)
@@ -269,15 +269,17 @@ typval2type_int(typval_T *tv, garray_T *type_gap)
 
     if (tv->v_type == VAR_LIST)
     {
-       listitem_T *li;
+       list_T      *l = tv->vval.v_list;
+       listitem_T  *li;
 
-       if (tv->vval.v_list == NULL || tv->vval.v_list->lv_first == NULL)
+       if (l == NULL || l->lv_first == NULL)
            return &t_list_empty;
+       if (l->lv_first == &range_list_item)
+           return &t_list_number;
 
        // Use the common type of all members.
-       member_type = typval2type(&tv->vval.v_list->lv_first->li_tv, type_gap);
-       for (li = tv->vval.v_list->lv_first->li_next; li != NULL;
-                                                            li = li->li_next)
+       member_type = typval2type(&l->lv_first->li_tv, type_gap);
+       for (li = l->lv_first->li_next; li != NULL; li = li->li_next)
            common_type(typval2type(&li->li_tv, type_gap),
                                          member_type, &member_type, type_gap);
        return get_list_type(member_type, type_gap);