]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 8.2.3230: Vim9: type error when function return type is not known yet v8.2.3230
authorBram Moolenaar <Bram@vim.org>
Tue, 27 Jul 2021 20:21:44 +0000 (22:21 +0200)
committerBram Moolenaar <Bram@vim.org>
Tue, 27 Jul 2021 20:21:44 +0000 (22:21 +0200)
Problem:    Vim9: type error when function return type is not known yet.
Solution:   When return type is unknown, use "any". (closes #8644)

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

index 2001079d2863f7a415a7de9847677cb2b7ea57ca..bd52f702c304b51542fcd46a7c9c3070d6f26c88 100644 (file)
@@ -1172,6 +1172,16 @@ def Test_get()
   var F: func = function('min', [[5, 8, 6]])
   F->get('name')->assert_equal('min')
   F->get('args')->assert_equal([[5, 8, 6]])
+
+  var lines =<< trim END
+      vim9script
+      def DoThat(): number
+        var Getqflist: func = function('getqflist', [{id: 42}])
+        return Getqflist()->get('id', 77)
+      enddef
+      assert_equal(0, DoThat())
+  END
+  CheckScriptSuccess(lines)
 enddef
 
 def Test_getbufinfo()
index a628f5116abbd3be4de8a21aec4ac7265d62e43c..425f8f311f41283f6f20a3343e1683e4619e2210 100644 (file)
@@ -755,6 +755,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    3230,
 /**/
     3229,
 /**/
index 7d169f8c21a34f76714e99b035ae40b5897a2084..0d54db3d5b65038bf4a1a8ecaf2a10a0accdb001 100644 (file)
@@ -2130,6 +2130,9 @@ generate_PCALL(
            }
        }
        ret_type = type->tt_member;
+       if (ret_type == &t_unknown)
+           // return type not known yet, use a runtime check
+           ret_type = &t_any;
     }
     else
     {