]> granicus.if.org Git - vim/commitdiff
patch 8.2.3695: confusing error for missing key v8.2.3695
authorBram Moolenaar <Bram@vim.org>
Mon, 29 Nov 2021 13:44:55 +0000 (13:44 +0000)
committerBram Moolenaar <Bram@vim.org>
Mon, 29 Nov 2021 13:44:55 +0000 (13:44 +0000)
Problem:    Confusing error for missing key.
Solution:   Use the actualy key for the error. (closes #9241)

src/eval.c
src/testdir/test_listdict.vim
src/version.c

index 0e8b6a6776a806ce687ae4071865de1f410125e3..bebe2f0ad504303e6ab32f85c75a88023c151ff9 100644 (file)
@@ -4287,12 +4287,18 @@ eval_index_inner(
                        return FAIL;
                }
 
-               item = dict_find(rettv->vval.v_dict, key, (int)keylen);
+               item = dict_find(rettv->vval.v_dict, key, keylen);
 
-               if (item == NULL && verbose)
-                   semsg(_(e_dictkey), key);
                if (item == NULL)
+               {
+                   if (verbose)
+                   {
+                       if (keylen > 0)
+                           key[keylen] = NUL;
+                       semsg(_(e_dictkey), key);
+                   }
                    return FAIL;
+               }
 
                copy_tv(&item->di_tv, &tmp);
                clear_tv(rettv);
index 2eda9a8801e4c23cee58f7a64b92cda9b4efe4f9..0b024a0f6f2d192c3de05f5502cf3f2bc9cabc82 100644 (file)
@@ -454,6 +454,25 @@ func Test_dict_func_remove()
   END
   call CheckLegacyAndVim9Failure(lines, 'E716:')
 
+  let lines =<< trim END
+      let d = {'a-b': 55}
+      echo d.a-b
+  END
+  call CheckScriptFailure(lines, 'E716: Key not present in Dictionary: "a"')
+
+  let lines =<< trim END
+      vim9script
+      var d = {'a-b': 55}
+      echo d.a-b
+  END
+  call CheckScriptFailure(lines, 'E716: Key not present in Dictionary: "a"')
+
+  let lines =<< trim END
+      var d = {'a-b': 55}
+      echo d.a-b
+  END
+  call CheckDefFailure(lines, 'E1004: White space required before and after ''-''')
+
   let lines =<< trim END
       let d = {1: 'a', 3: 'c'}
       call remove(d, [])
index 623afb2def4aebc7e879866edbf25d360cad5323..e4c85892f21a2c31ef5974c567ffef2c67ef094c 100644 (file)
@@ -757,6 +757,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    3695,
 /**/
     3694,
 /**/