diff options
author | Bram Moolenaar <Bram@vim.org> | 2020-12-31 13:31:23 +0100 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2020-12-31 13:31:23 +0100 |
commit | 6b55377303968e1624339cd95053201d5acdcaa2 (patch) | |
tree | 6c0410ba3927ae81ac9a53bc2d1002c3aa7015d0 | |
parent | a04d447d3aaddb5b978dd9a0e0186007fde8e09e (diff) | |
download | vim-git-6b55377303968e1624339cd95053201d5acdcaa2.tar.gz |
patch 8.2.2252: Vim9: crash when using lambda without return type in dictv8.2.2252
Problem: Vim9: crash when using lambda without return type in dict.
Solution: Without a return type use t_unknown. (closes #7587)
-rw-r--r-- | src/testdir/test_vim9_expr.vim | 4 | ||||
-rw-r--r-- | src/version.c | 2 | ||||
-rw-r--r-- | src/vim9compile.c | 3 | ||||
-rw-r--r-- | src/vim9type.c | 5 |
4 files changed, 12 insertions, 2 deletions
diff --git a/src/testdir/test_vim9_expr.vim b/src/testdir/test_vim9_expr.vim index 4998471ee..428906964 100644 --- a/src/testdir/test_vim9_expr.vim +++ b/src/testdir/test_vim9_expr.vim @@ -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) diff --git a/src/version.c b/src/version.c index f080e6866..d1bb9cc8f 100644 --- a/src/version.c +++ b/src/version.c @@ -751,6 +751,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 2252, +/**/ 2251, /**/ 2250, diff --git a/src/vim9compile.c b/src/vim9compile.c index 6ef2b5e77..5602ff592 100644 --- a/src/vim9compile.c +++ b/src/vim9compile.c @@ -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; } diff --git a/src/vim9type.c b/src/vim9type.c index 3ff0762d4..d2dbc768c 100644 --- a/src/vim9type.c +++ b/src/vim9type.c @@ -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 |