Skip to content

Commit 7892b95

Browse files
committed
patch 8.2.1256: Vim9: type wrong after getting dict item in lambda
Problem: Vim9: type wrong after getting dict item in lambda. Solution: Set the type to "any" after enforcing dict type. (closes #6491)
1 parent d43906d commit 7892b95

3 files changed

Lines changed: 12 additions & 3 deletions

File tree

src/testdir/test_vim9_expr.vim

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1176,6 +1176,10 @@ def Test_expr7_lambda()
11761176
let dl = [{'key': 0}, {'key': 22}]->filter({ _, v -> v['key'] })
11771177
assert_equal([{'key': 22}], dl)
11781178

1179+
dl = [{'key': 12}, {'foo': 34}]
1180+
assert_equal([{'key': 12}], filter(dl,
1181+
{_, v -> has_key(v, 'key') ? v['key'] == 12 : 0}))
1182+
11791183
call CheckDefFailure(["filter([1, 2], {k,v -> 1})"], 'E1069:')
11801184
enddef
11811185

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,8 @@ static char *(features[]) =
754754

755755
static int included_patches[] =
756756
{ /* Add new patch number below this line */
757+
/**/
758+
1256,
757759
/**/
758760
1255,
759761
/**/

src/vim9compile.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3797,9 +3797,12 @@ compile_subscript(
37973797
{
37983798
if ((*typep)->tt_type == VAR_DICT)
37993799
*typep = (*typep)->tt_member;
3800-
else if (need_type(*typep, &t_dict_any, -2, cctx, FALSE)
3801-
== FAIL)
3802-
return FAIL;
3800+
else
3801+
{
3802+
if (need_type(*typep, &t_dict_any, -2, cctx, FALSE) == FAIL)
3803+
return FAIL;
3804+
*typep = &t_any;
3805+
}
38033806
if (may_generate_2STRING(-1, cctx) == FAIL)
38043807
return FAIL;
38053808
if (generate_instr_drop(cctx, ISN_MEMBER, 1) == FAIL)

0 commit comments

Comments
 (0)