summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2020-07-20 22:09:34 +0200
committerBram Moolenaar <Bram@vim.org>2020-07-20 22:09:34 +0200
commit7892b953e0e496408008434ae3505293c0c93af1 (patch)
treea1f0ff0731d2a21574853d003e6f3acde9c01240
parentd43906d2e5969288f239df851f5ad7b1dc2c7251 (diff)
downloadvim-git-7892b953e0e496408008434ae3505293c0c93af1.tar.gz
patch 8.2.1256: Vim9: type wrong after getting dict item in lambdav8.2.1256
Problem: Vim9: type wrong after getting dict item in lambda. Solution: Set the type to "any" after enforcing dict type. (closes #6491)
-rw-r--r--src/testdir/test_vim9_expr.vim4
-rw-r--r--src/version.c2
-rw-r--r--src/vim9compile.c9
3 files changed, 12 insertions, 3 deletions
diff --git a/src/testdir/test_vim9_expr.vim b/src/testdir/test_vim9_expr.vim
index 7feec382a..b68eb3e4a 100644
--- a/src/testdir/test_vim9_expr.vim
+++ b/src/testdir/test_vim9_expr.vim
@@ -1176,6 +1176,10 @@ def Test_expr7_lambda()
let dl = [{'key': 0}, {'key': 22}]->filter({ _, v -> v['key'] })
assert_equal([{'key': 22}], dl)
+ dl = [{'key': 12}, {'foo': 34}]
+ assert_equal([{'key': 12}], filter(dl,
+ {_, v -> has_key(v, 'key') ? v['key'] == 12 : 0}))
+
call CheckDefFailure(["filter([1, 2], {k,v -> 1})"], 'E1069:')
enddef
diff --git a/src/version.c b/src/version.c
index 71c164a42..ee1e3f44c 100644
--- a/src/version.c
+++ b/src/version.c
@@ -755,6 +755,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 1256,
+/**/
1255,
/**/
1254,
diff --git a/src/vim9compile.c b/src/vim9compile.c
index 93a4d896c..ce24dd6a5 100644
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -3797,9 +3797,12 @@ compile_subscript(
{
if ((*typep)->tt_type == VAR_DICT)
*typep = (*typep)->tt_member;
- else if (need_type(*typep, &t_dict_any, -2, cctx, FALSE)
- == FAIL)
- return FAIL;
+ else
+ {
+ if (need_type(*typep, &t_dict_any, -2, cctx, FALSE) == FAIL)
+ return FAIL;
+ *typep = &t_any;
+ }
if (may_generate_2STRING(-1, cctx) == FAIL)
return FAIL;
if (generate_instr_drop(cctx, ISN_MEMBER, 1) == FAIL)