]> granicus.if.org Git - vim/commitdiff
patch 8.2.1256: Vim9: type wrong after getting dict item in lambda v8.2.1256
authorBram Moolenaar <Bram@vim.org>
Mon, 20 Jul 2020 20:09:34 +0000 (22:09 +0200)
committerBram Moolenaar <Bram@vim.org>
Mon, 20 Jul 2020 20:09:34 +0000 (22:09 +0200)
Problem:    Vim9: type wrong after getting dict item in lambda.
Solution:   Set the type to "any" after enforcing dict type. (closes #6491)

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

index 7feec382a230bc4a8b597dd19f8075b20b307313..b68eb3e4a2029d91c867b1bd457df7479a89b94c 100644 (file)
@@ -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
 
index 71c164a428832f8aca7b4a9edddcb1aca7339428..ee1e3f44c4f00c3443b8e8578771a8ec223bb2d2 100644 (file)
@@ -754,6 +754,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1256,
 /**/
     1255,
 /**/
index 93a4d896c5acf017c2afd180b53909b206b65053..ce24dd6a56e6cec4b5835a255badbd3f9e8728bd 100644 (file)
@@ -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)