]> granicus.if.org Git - vim/commitdiff
patch 8.2.2252: Vim9: crash when using lambda without return type in dict v8.2.2252
authorBram Moolenaar <Bram@vim.org>
Thu, 31 Dec 2020 12:31:23 +0000 (13:31 +0100)
committerBram Moolenaar <Bram@vim.org>
Thu, 31 Dec 2020 12:31:23 +0000 (13:31 +0100)
Problem:    Vim9: crash when using lambda without return type in dict.
Solution:   Without a return type use t_unknown. (closes #7587)

src/testdir/test_vim9_expr.vim
src/version.c
src/vim9compile.c
src/vim9type.c

index 4998471ee67877a175e1700e35a47cc5e3f721ac..428906964948d4ecd71631699635dc2c97dd09dc 100644 (file)
@@ -2077,6 +2077,10 @@ def Test_expr7_dict()
       assert_equal(g:test_hash_dict, {one: 1, two: 2})
 
       assert_equal({['a a']: 1, ['b/c']: 2}, {'a a': 1, "b/c": 2})
+
+      var d = {a: () => 3, b: () => 7}
+      assert_equal(3, d.a())
+      assert_equal(7, d.b())
   END
   CheckDefAndScriptSuccess(lines)
  
index f080e6866967f31e8c2a36e77bcee8d29d6ea151..d1bb9cc8fc2db230206d0828fb7053284c6985e9 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2252,
 /**/
     2251,
 /**/
index 6ef2b5e77e6e092359d2434ae548c000a3a4347e..5602ff592ae39d72b29cb993533e62666e114139 100644 (file)
@@ -4837,7 +4837,8 @@ compile_return(char_u *arg, int check_return_type, cctx_T *cctx)
        if (cctx->ctx_skip != SKIP_YES)
        {
            stack_type = ((type_T **)stack->ga_data)[stack->ga_len - 1];
-           if (check_return_type && cctx->ctx_ufunc->uf_ret_type == NULL)
+           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 = stack_type;
            }
index 3ff0762d435ce84af9f57e4a00ed53ba2249709e..d2dbc768c8388d514527fca7f032def0c8e7e20f 100644 (file)
@@ -480,7 +480,10 @@ check_type(type_T *expected, type_T *actual, int give_msg, int argidx)
        }
        else if (expected->tt_type == VAR_FUNC)
        {
-           if (expected->tt_member != &t_unknown)
+           // If the return type is unknown it can be anything, including
+           // nothing, thus there is no point in checking.
+           if (expected->tt_member != &t_unknown
+                                           && actual->tt_member != &t_unknown)
                ret = check_type(expected->tt_member, actual->tt_member,
                                                                     FALSE, 0);
            if (ret == OK && expected->tt_argcount != -1