]> granicus.if.org Git - vim/commitdiff
patch 8.2.3035: Vim9: crash when calling :def function with partial v8.2.3035
authorBram Moolenaar <Bram@vim.org>
Tue, 22 Jun 2021 17:32:17 +0000 (19:32 +0200)
committerBram Moolenaar <Bram@vim.org>
Tue, 22 Jun 2021 17:32:17 +0000 (19:32 +0200)
Problem:    Vim9: crash when calling :def function with partial and return
            type is not set.
Solution:   When the return type is not set handle like the return type is
            unknown. (closes #8422)

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

index de09baaf6cd04a216989580c4f24dcabb06b406d..301a55c8757a03ac8630b58ee583a563d7976297 100644 (file)
@@ -1005,6 +1005,20 @@ def Test_pass_legacy_lambda_to_def_func()
       Foo()
   END
   CheckScriptSuccess(lines)
+
+  lines =<< trim END
+      vim9script
+      def g:TestFunc(f: func())
+      enddef
+      legacy call g:TestFunc({-> 0})
+      delfunc g:TestFunc
+
+      def g:TestFunc(f: func(number))
+      enddef
+      legacy call g:TestFunc({nr -> 0})
+      delfunc g:TestFunc
+  END
+  CheckScriptSuccess(lines)
 enddef
 
 " Default arg and varargs
index 5502952b7af539a1c596fafccbc5f913398c1d66..653e578b9f477bdf0fb23e00b6ceaf0359abc43d 100644 (file)
@@ -755,6 +755,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    3035,
 /**/
     3034,
 /**/
index f3718e4685b0ec675a9757209c99423b4704f52e..91dc3fe6077aa11c541e452bd6eed866f141c796 100644 (file)
@@ -171,7 +171,7 @@ alloc_func_type(type_T *ret_type, int argcount, garray_T *type_gap)
     if (type == NULL)
        return &t_any;
     type->tt_type = VAR_FUNC;
-    type->tt_member = ret_type;
+    type->tt_member = ret_type == NULL ? &t_unknown : ret_type;
     type->tt_argcount = argcount;
     type->tt_args = NULL;
     return type;
@@ -188,7 +188,7 @@ get_func_type(type_T *ret_type, int argcount, garray_T *type_gap)
     // recognize commonly used types
     if (argcount <= 0)
     {
-       if (ret_type == &t_unknown)
+       if (ret_type == &t_unknown || ret_type == NULL)
        {
            // (argcount == 0) is not possible
            return &t_func_unknown;