changeset 21574:b8b15e8cbf5f v8.2.1337

patch 8.2.1337: Vim9: cannot use empty key in dict assignment Commit: https://github.com/vim/vim/commit/586268721dd5d6e50903a8a457f02e0dda901856 Author: Bram Moolenaar <Bram@vim.org> Date: Sat Aug 1 14:06:38 2020 +0200 patch 8.2.1337: Vim9: cannot use empty key in dict assignment Problem: Vim9: cannot use empty key in dict assignment. Solution: Allow empty key. (closes https://github.com/vim/vim/issues/6591)
author Bram Moolenaar <Bram@vim.org>
date Sat, 01 Aug 2020 14:15:03 +0200
parents 56e2dfbce89f
children 69d8fbc507a1
files src/testdir/test_vim9_script.vim src/version.c src/vim9execute.c
diffstat 3 files changed, 8 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/src/testdir/test_vim9_script.vim
+++ b/src/testdir/test_vim9_script.vim
@@ -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'}
@@ -784,13 +787,6 @@ def Test_try_catch()
   assert_equal(300, n)
 
   try
-    d[''] = 3
-  catch /E713:/
-    n = 311
-  endtry
-  assert_equal(311, n)
-
-  try
     unlet g:does_not_exist
   catch /E108:/
     n = 322
--- 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 */
 /**/
+    1337,
+/**/
     1336,
 /**/
     1335,
--- a/src/vim9execute.c
+++ b/src/vim9execute.c
@@ -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)