diff options
author | Bram Moolenaar <Bram@vim.org> | 2020-12-15 21:41:56 +0100 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2020-12-15 21:41:56 +0100 |
commit | 9987fb0b4b591e6450fb1dfbe8f615f365057f2a (patch) | |
tree | 934e6a83812494bf39b91c168935636c70bf9492 | |
parent | 399ea8108c8da3fcdf5d738a0f8eae67155b4b10 (diff) | |
download | vim-git-9987fb0b4b591e6450fb1dfbe8f615f365057f2a.tar.gz |
patch 8.2.2146: Vim9: automatic conversion of number to string for dict keyv8.2.2146
Problem: Vim9: automatic conversion of number to string for dict key.
Solution: Do not convert number to string. (closes #7474)
-rw-r--r-- | src/dict.c | 5 | ||||
-rw-r--r-- | src/testdir/test_vim9_expr.vim | 8 | ||||
-rw-r--r-- | src/version.c | 2 |
3 files changed, 15 insertions, 0 deletions
diff --git a/src/dict.c b/src/dict.c index 5581a5571..051ba2f6e 100644 --- a/src/dict.c +++ b/src/dict.c @@ -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) { diff --git a/src/testdir/test_vim9_expr.vim b/src/testdir/test_vim9_expr.vim index 9147536a6..f2c9200ee 100644 --- a/src/testdir/test_vim9_expr.vim +++ b/src/testdir/test_vim9_expr.vim @@ -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() diff --git a/src/version.c b/src/version.c index aeac2652e..a95042c15 100644 --- a/src/version.c +++ b/src/version.c @@ -751,6 +751,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 2146, +/**/ 2145, /**/ 2144, |