]> granicus.if.org Git - vim/commitdiff
patch 8.2.1337: Vim9: cannot use empty key in dict assignment v8.2.1337
authorBram Moolenaar <Bram@vim.org>
Sat, 1 Aug 2020 12:06:38 +0000 (14:06 +0200)
committerBram Moolenaar <Bram@vim.org>
Sat, 1 Aug 2020 12:06:38 +0000 (14:06 +0200)
Problem:    Vim9: cannot use empty key in dict assignment.
Solution:   Allow empty key. (closes #6591)

src/testdir/test_vim9_script.vim
src/version.c
src/vim9execute.c

index 405d4877a25707a56aba8f199d6465745b4b2303..ec63c6f11c590b17d0e9baffffde90d06d00167e 100644 (file)
@@ -244,7 +244,10 @@ def Test_assignment_dict()
   # overwrite
   dict3['key'] = 'another'
 
-  call CheckDefExecFailure(['let dd = {}', 'dd[""] = 6'], 'E713:')
+  # empty key can be used
+  let dd = {}
+  dd[""] = 6
+  assert_equal({'': 6}, dd)
 
   # type becomes dict<any>
   let somedict = rand() > 0 ? #{a: 1, b: 2} : #{a: 'a', b: 'b'}
@@ -783,13 +786,6 @@ def Test_try_catch()
   endtry
   assert_equal(300, n)
 
-  try
-    d[''] = 3
-  catch /E713:/
-    n = 311
-  endtry
-  assert_equal(311, n)
-
   try
     unlet g:does_not_exist
   catch /E108:/
index bf22a76d9cbe24e13e453a2b48ca6d612b3d396d..661875a27661a548823a430a123a6638e6ec3ad2 100644 (file)
@@ -754,6 +754,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1337,
 /**/
     1336,
 /**/
index 9bfec3af121375aaa450aa5329b86fb36e911c1a..de29988be123508ca1bba9e3f273f5248e6c19f9 100644 (file)
@@ -1422,11 +1422,8 @@ call_def_function(
                    dict_T      *dict = tv_dict->vval.v_dict;
                    dictitem_T  *di;
 
-                   if (key == NULL || *key == NUL)
-                   {
-                       emsg(_(e_emptykey));
-                       goto on_error;
-                   }
+                   if (key == NULL)
+                       key = (char_u *)"";
                    tv = STACK_TV_BOT(-3);
                    di = dict_find(dict, key, -1);
                    if (di != NULL)