changeset 25386:9c749ad22565 v8.2.3230

patch 8.2.3230: Vim9: type error when function return type is not known yet Commit: https://github.com/vim/vim/commit/f723701de0636ad8b4aad6179b322f72b04354b9 Author: Bram Moolenaar <Bram@vim.org> Date: Tue Jul 27 22:21:44 2021 +0200 patch 8.2.3230: Vim9: type error when function return type is not known yet Problem: Vim9: type error when function return type is not known yet. Solution: When return type is unknown, use "any". (closes https://github.com/vim/vim/issues/8644)
author Bram Moolenaar <Bram@vim.org>
date Tue, 27 Jul 2021 22:30:03 +0200
parents c785de20eb86
children beb96a39cfac
files src/testdir/test_vim9_builtin.vim src/version.c src/vim9compile.c
diffstat 3 files changed, 15 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/testdir/test_vim9_builtin.vim
+++ b/src/testdir/test_vim9_builtin.vim
@@ -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()
--- a/src/version.c
+++ b/src/version.c
@@ -756,6 +756,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    3230,
+/**/
     3229,
 /**/
     3228,
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -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
     {