1
0
forked from aniani/vim

patch 8.2.2146: Vim9: automatic conversion of number to string for dict key

Problem:    Vim9: automatic conversion of number to string for dict key.
Solution:   Do not convert number to string. (closes #7474)
This commit is contained in:
Bram Moolenaar
2020-12-15 21:41:56 +01:00
parent 399ea8108c
commit 9987fb0b4b
3 changed files with 15 additions and 0 deletions

View File

@@ -951,6 +951,11 @@ eval_dict(char_u **arg, typval_T *rettv, evalarg_T *evalarg, int literal)
} }
if (evaluate) if (evaluate)
{ {
if (vim9script && check_for_string(&tvkey) == FAIL)
{
clear_tv(&tvkey);
goto failret;
}
key = tv_get_string_buf_chk(&tvkey, buf); key = tv_get_string_buf_chk(&tvkey, buf);
if (key == NULL) if (key == NULL)
{ {

View File

@@ -1989,6 +1989,14 @@ def Test_expr7_dict()
CheckDefFailure(['var x = ({'], 'E723:', 2) CheckDefFailure(['var x = ({'], 'E723:', 2)
CheckDefExecFailure(['{}[getftype("file")]'], 'E716: Key not present in Dictionary: ""', 1) CheckDefExecFailure(['{}[getftype("file")]'], 'E716: Key not present in Dictionary: ""', 1)
# no automatic conversion from number to string
lines =<< trim END
var n = 123
var d = {[n]: 1}
END
CheckDefFailure(lines, 'E1012:', 2)
CheckScriptFailure(['vim9script'] + lines, 'E928:', 3)
enddef enddef
def Test_expr7_dict_vim9script() def Test_expr7_dict_vim9script()

View File

@@ -750,6 +750,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
2146,
/**/ /**/
2145, 2145,
/**/ /**/