Skip to content

Commit 9987fb0

Browse files
committed
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)
1 parent 399ea81 commit 9987fb0

3 files changed

Lines changed: 15 additions & 0 deletions

File tree

src/dict.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -951,6 +951,11 @@ eval_dict(char_u **arg, typval_T *rettv, evalarg_T *evalarg, int literal)
951951
}
952952
if (evaluate)
953953
{
954+
if (vim9script && check_for_string(&tvkey) == FAIL)
955+
{
956+
clear_tv(&tvkey);
957+
goto failret;
958+
}
954959
key = tv_get_string_buf_chk(&tvkey, buf);
955960
if (key == NULL)
956961
{

src/testdir/test_vim9_expr.vim

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1989,6 +1989,14 @@ def Test_expr7_dict()
19891989

19901990
CheckDefFailure(['var x = ({'], 'E723:', 2)
19911991
CheckDefExecFailure(['{}[getftype("file")]'], 'E716: Key not present in Dictionary: ""', 1)
1992+
1993+
# no automatic conversion from number to string
1994+
lines =<< trim END
1995+
var n = 123
1996+
var d = {[n]: 1}
1997+
END
1998+
CheckDefFailure(lines, 'E1012:', 2)
1999+
CheckScriptFailure(['vim9script'] + lines, 'E928:', 3)
19922000
enddef
19932001

19942002
def Test_expr7_dict_vim9script()

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,8 @@ static char *(features[]) =
750750

751751
static int included_patches[] =
752752
{ /* Add new patch number below this line */
753+
/**/
754+
2146,
753755
/**/
754756
2145,
755757
/**/

0 commit comments

Comments
 (0)