]> granicus.if.org Git - vim/commitdiff
patch 8.2.1710: Vim9: list of list type can be wrong v8.2.1710
authorBram Moolenaar <Bram@vim.org>
Sat, 19 Sep 2020 12:12:34 +0000 (14:12 +0200)
committerBram Moolenaar <Bram@vim.org>
Sat, 19 Sep 2020 12:12:34 +0000 (14:12 +0200)
Problem:    Vim9: list of list type can be wrong.
Solution:   Use VAR_UNKNOWN for empty list.  Recognize VAR_UNKNOWN when
            looking for a common type. (closes #6979)

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

index d79e2cd6bce61d8f98565592c6aaea88f2eb4677..b9a68112b58ec9680a431293a52cd23b592c4d2b 100644 (file)
@@ -1513,6 +1513,10 @@ def Test_expr7_list()
        2] [3,
                4]
 
+  let llstring: list<list<string>> = [['text'], []]
+  llstring = [[], ['text']]
+  llstring = [[], []]
+
   CheckDefFailure(["let x = 1234[3]"], 'E1107:', 1)
   CheckDefExecFailure(["let x = g:anint[3]"], 'E1062:', 1)
 
@@ -1718,6 +1722,14 @@ def Test_expr7_dict()
   mixed = #{a: 234}
   mixed = #{}
 
+  let dictlist: dict<list<string>> = #{absent: [], present: ['hi']}
+  dictlist = #{absent: ['hi'], present: []}
+  dictlist = #{absent: [], present: []}
+
+  let dictdict: dict<dict<string>> = #{one: #{a: 'text'}, two: #{}}
+  dictdict = #{one: #{}, two: #{a: 'text'}}
+  dictdict = #{one: #{}, two: #{}}
   CheckDefFailure(["let x = #{a:8}"], 'E1069:', 1)
   CheckDefFailure(["let x = #{a : 8}"], 'E1068:', 1)
   CheckDefFailure(["let x = #{a :8}"], 'E1068:', 1)
index 60aa105995810c37c111a93f0dae0151c0703db8..3b1f963bbf8b8778b957650d0b9b3f1cb0fc85e6 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1710,
 /**/
     1709,
 /**/
index cc879d0e7526ed9d7e18b3542cc1c5d6e9ee9fe5..a7ffd32ed556e00603264f6b82a5501a9883c6f4 100644 (file)
@@ -869,6 +869,19 @@ common_type(type_T *type1, type_T *type2, type_T **dest, garray_T *type_gap)
        return;
     }
 
+    // If either is VAR_UNKNOWN use the other type.  An empty list/dict has no
+    // specific type.
+    if (type1->tt_type == VAR_UNKNOWN)
+    {
+       *dest = type2;
+       return;
+    }
+    if (type2->tt_type == VAR_UNKNOWN)
+    {
+       *dest = type1;
+       return;
+    }
+
     if (type1->tt_type == type2->tt_type)
     {
        if (type1->tt_type == VAR_LIST || type2->tt_type == VAR_DICT)
@@ -932,7 +945,7 @@ get_member_type_from_stack(
 
     // Use "any" for an empty list or dict.
     if (count == 0)
-       return &t_void;
+       return &t_unknown;
 
     // Use the first value type for the list member type, then find the common
     // type from following items.