]> granicus.if.org Git - vim/commitdiff
patch 8.2.2308: Vim9: no error when assigning lambda to funcref v8.2.2308
authorBram Moolenaar <Bram@vim.org>
Thu, 7 Jan 2021 18:23:08 +0000 (19:23 +0100)
committerBram Moolenaar <Bram@vim.org>
Thu, 7 Jan 2021 18:23:08 +0000 (19:23 +0100)
Problem:    Vim9: no error when assigning lambda to funcref without return
            value.
Solution:   Default return value to "any". (closes #7629)

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

index 2a21ca065f6c9ce0cbff4090726b1d30e972c74b..2d137a328142cd8774989407d1ec8b1e6c95efcd 100644 (file)
@@ -1091,6 +1091,13 @@ def Test_assign_lambda()
       assert_equal(123, FuncRef_Any())
   END
   CheckScriptSuccess(lines)
+
+  lines =<< trim END
+      var Ref: func(number)
+      Ref = (j) => !j
+  END
+  CheckDefFailure(lines, 'E1012: Type mismatch; expected func(number) but got func(any): bool')
+  CheckScriptFailure(['vim9script'] + lines, 'E1012: Type mismatch; expected func(number) but got func(any): any')
 enddef
 
 def Test_heredoc()
index c26f2af5bc595a3468495b4428ef5846a4dd3de3..9f19ebda9a309c3ba70c1ca394f6dfabac5ecdf9 100644 (file)
@@ -1508,7 +1508,7 @@ def Test_unknown_function()
       'delfunc g:NotExist'], 'E700:')
 enddef
 
-def RefFunc(Ref: func(string): string): string
+def RefFunc(Ref: func(any): any): string
   return Ref('more')
 enddef
 
index 4c59bb516e7fdc1a98af928b5f6c2bbab6319f50..814d400fb2d437555f8ba3382f096f3c32b332be 100644 (file)
@@ -668,7 +668,7 @@ get_lambda_tv(
                    goto errret;
            }
            else
-               fp->uf_ret_type = &t_unknown;
+               fp->uf_ret_type = &t_any;
        }
 
        fp->uf_lines = newlines;
index 3f8ed2a4191fc18057d0c7640c2502e0c0cb104c..f39a0d36181fa3625ecef29c3ccb9999aa818b6f 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2308,
 /**/
     2307,
 /**/
index c3aab20d3d389063c66f733aede9113bc1bfda0f..f66b27ff50d960a05e0a530d1caa27df41a04af4 100644 (file)
@@ -857,7 +857,9 @@ use_typecheck(type_T *actual, type_T *expected)
            || (actual->tt_type == VAR_FUNC
                && (expected->tt_type == VAR_FUNC
                                           || expected->tt_type == VAR_PARTIAL)
-               && (actual->tt_member == &t_any || actual->tt_argcount < 0)))
+               && (actual->tt_member == &t_any || actual->tt_argcount < 0)
+               && ((actual->tt_member == &t_void)
+                                        == (expected->tt_member == &t_void))))
        return TRUE;
     if ((actual->tt_type == VAR_LIST || actual->tt_type == VAR_DICT)
                                       && actual->tt_type == expected->tt_type)
@@ -4812,7 +4814,8 @@ compile_return(char_u *arg, int check_return_type, cctx_T *cctx)
        {
            stack_type = ((type_T **)stack->ga_data)[stack->ga_len - 1];
            if (check_return_type && (cctx->ctx_ufunc->uf_ret_type == NULL
-                               || cctx->ctx_ufunc->uf_ret_type == &t_unknown))
+                               || cctx->ctx_ufunc->uf_ret_type == &t_unknown
+                               || cctx->ctx_ufunc->uf_ret_type == &t_any))
            {
                cctx->ctx_ufunc->uf_ret_type = stack_type;
            }