]> granicus.if.org Git - vim/commitdiff
patch 8.2.2146: Vim9: automatic conversion of number to string for dict key v8.2.2146
authorBram Moolenaar <Bram@vim.org>
Tue, 15 Dec 2020 20:41:56 +0000 (21:41 +0100)
committerBram Moolenaar <Bram@vim.org>
Tue, 15 Dec 2020 20:41:56 +0000 (21:41 +0100)
Problem:    Vim9: automatic conversion of number to string for dict key.
Solution:   Do not convert number to string. (closes #7474)

src/dict.c
src/testdir/test_vim9_expr.vim
src/version.c

index 5581a5571bc0263981cace0cf14980d261421145..051ba2f6ece00a6bc843efd415464a3993b810f3 100644 (file)
@@ -951,6 +951,11 @@ eval_dict(char_u **arg, typval_T *rettv, evalarg_T *evalarg, int literal)
        }
        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)
            {
index 9147536a66f5524398879a67ab53e7b7f09da734..f2c9200eea68897013d0cebd85cfa1c251a487cf 100644 (file)
@@ -1989,6 +1989,14 @@ def Test_expr7_dict()
 
   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()
index aeac2652e728081580c560df58ccffb475c245d5..a95042c15c86eccfda6fa0cceebc6b2eb339f3c0 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2146,
 /**/
     2145,
 /**/