]> granicus.if.org Git - vim/commitdiff
patch 8.2.3168: Vim9: type error for constant of type any v8.2.3168
authorBram Moolenaar <Bram@vim.org>
Thu, 15 Jul 2021 17:23:18 +0000 (19:23 +0200)
committerBram Moolenaar <Bram@vim.org>
Thu, 15 Jul 2021 17:23:18 +0000 (19:23 +0200)
Problem:    Vim9: type error for constant of type any.
Solution:   Do add a runtime type check if a constant has type any.
            (closes #8570)

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

index 6bbbc3681ea3c12236d499b0968a223e9750a83f..3599d6c5d1bcae2cd7ea12ad8fee4b147dd7ab2b 100644 (file)
@@ -1667,6 +1667,16 @@ def Test_var_type_check()
     s:d = {}
   END
   CheckScriptSuccess(lines)
+
+  lines =<< trim END
+    vim9script
+    var d = {a: 1, b: [2]}
+    def Func(b: bool)
+      var l: list<number> = b ? d.b : [3]
+    enddef
+    defcompile
+  END
+  CheckScriptSuccess(lines)
 enddef
 
 let g:dict_number = #{one: 1, two: 2}
index 6a4943d50f39e7a8fa531cda01b2613ef288bc31..b8c782eef29739f0da7a07e2ec139405f54ccde5 100644 (file)
@@ -755,6 +755,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    3168,
 /**/
     3167,
 /**/
index 4763e9550b2a64543d6f1d0e8f4e8c2fa71df352..956ce44eb01621916f8516d7b1e4d973a8d9dfaf 100644 (file)
@@ -1051,7 +1051,8 @@ need_type(
 
     // If the actual type can be the expected type add a runtime check.
     // If it's a constant a runtime check makes no sense.
-    if (!actual_is_const && use_typecheck(actual, expected))
+    if ((!actual_is_const || actual == &t_any)
+                                           && use_typecheck(actual, expected))
     {
        generate_TYPECHECK(cctx, expected, offset, arg_idx);
        return OK;