]> granicus.if.org Git - vim/commitdiff
patch 8.2.1730: Vim9: cannot use member of unknown type v8.2.1730
authorBram Moolenaar <Bram@vim.org>
Wed, 23 Sep 2020 11:25:32 +0000 (13:25 +0200)
committerBram Moolenaar <Bram@vim.org>
Wed, 23 Sep 2020 11:25:32 +0000 (13:25 +0200)
Problem:    Vim9: cannot use member of unknown type.
Solution:   When type is unknown us "any". (closes #6997)

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

index 65e106593e2a716af0c1e2865df82598246c629e..852db4ad777e972ed385f61e97862b0e90296316 100644 (file)
@@ -676,6 +676,33 @@ def Test_assign_dict()
   assert_equal({'0': 0, '1': 1, '2': 2}, nrd)
 enddef
 
+def Test_assign_dict_unknown_type()
+  let lines =<< trim END
+      vim9script
+      let mylist = []
+      mylist += [#{one: 'one'}]
+      def Func()
+        let dd = mylist[0]
+        assert_equal('one', dd.one)
+      enddef
+      Func()
+  END
+  CheckScriptSuccess(lines)
+
+  # doesn't work yet
+  #lines =<< trim END
+  #    vim9script
+  #    let mylist = [[]]
+  #    mylist[0] += [#{one: 'one'}]
+  #    def Func()
+  #      let dd = mylist[0][0]
+  #      assert_equal('one', dd.one)
+  #    enddef
+  #    Func()
+  #END
+  #CheckScriptSuccess(lines)
+enddef
+
 def Test_assign_lambda()
   # check if assign a lambda to a variable which type is func or any.
   let lines =<< trim END
index aa821b2d885bdeb2b8fd06edfb5f18cf1a283238..655e34919a731a2ec40926170aa1ce7251960323 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1730,
 /**/
     1729,
 /**/
index 52651f36a1a898fef075e1ec1695c8c452f9fc72..06ee2f5a8c3afaa6abbd3c6af1398f7108e330ad 100644 (file)
@@ -5080,12 +5080,14 @@ compile_assignment(char_u *arg, exarg_T *eap, cmdidx_T cmdidx, cctx_T *cctx)
                        }
                        else
                        {
-                           // An empty list or dict has a &t_void member,
+                           // An empty list or dict has a &t_unknown member,
                            // for a variable that implies &t_any.
                            if (stacktype == &t_list_empty)
                                lvar->lv_type = &t_list_any;
                            else if (stacktype == &t_dict_empty)
                                lvar->lv_type = &t_dict_any;
+                           else if (stacktype == &t_unknown)
+                               lvar->lv_type = &t_any;
                            else
                                lvar->lv_type = stacktype;
                        }