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)
diff --git a/src/dict.c b/src/dict.c
index 5581a55..051ba2f 100644
--- a/src/dict.c
+++ b/src/dict.c
@@ -951,6 +951,11 @@
}
if (evaluate)
{
+ if (vim9script && check_for_string(&tvkey) == FAIL)
+ {
+ clear_tv(&tvkey);
+ goto failret;
+ }
key = tv_get_string_buf_chk(&tvkey, buf);
if (key == NULL)
{
diff --git a/src/testdir/test_vim9_expr.vim b/src/testdir/test_vim9_expr.vim
index 9147536..f2c9200 100644
--- a/src/testdir/test_vim9_expr.vim
+++ b/src/testdir/test_vim9_expr.vim
@@ -1989,6 +1989,14 @@
CheckDefFailure(['var x = ({'], 'E723:', 2)
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
def Test_expr7_dict_vim9script()
diff --git a/src/version.c b/src/version.c
index aeac265..a95042c 100644
--- a/src/version.c
+++ b/src/version.c
@@ -751,6 +751,8 @@
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 2146,
+/**/
2145,
/**/
2144,