Skip to content

Commit 5862687

Browse files
committed
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 #6591)
1 parent af50e89 commit 5862687

3 files changed

Lines changed: 8 additions & 13 deletions

File tree

src/testdir/test_vim9_script.vim

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,10 @@ def Test_assignment_dict()
244244
# overwrite
245245
dict3['key'] = 'another'
246246

247-
call CheckDefExecFailure(['let dd = {}', 'dd[""] = 6'], 'E713:')
247+
# empty key can be used
248+
let dd = {}
249+
dd[""] = 6
250+
assert_equal({'': 6}, dd)
248251

249252
# type becomes dict<any>
250253
let somedict = rand() > 0 ? #{a: 1, b: 2} : #{a: 'a', b: 'b'}
@@ -783,13 +786,6 @@ def Test_try_catch()
783786
endtry
784787
assert_equal(300, n)
785788

786-
try
787-
d[''] = 3
788-
catch /E713:/
789-
n = 311
790-
endtry
791-
assert_equal(311, n)
792-
793789
try
794790
unlet g:does_not_exist
795791
catch /E108:/

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+
1337,
757759
/**/
758760
1336,
759761
/**/

src/vim9execute.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1422,11 +1422,8 @@ call_def_function(
14221422
dict_T *dict = tv_dict->vval.v_dict;
14231423
dictitem_T *di;
14241424

1425-
if (key == NULL || *key == NUL)
1426-
{
1427-
emsg(_(e_emptykey));
1428-
goto on_error;
1429-
}
1425+
if (key == NULL)
1426+
key = (char_u *)"";
14301427
tv = STACK_TV_BOT(-3);
14311428
di = dict_find(dict, key, -1);
14321429
if (di != NULL)

0 commit comments

Comments
 (0)