summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2020-07-13 18:55:48 +0200
committerBram Moolenaar <Bram@vim.org>2020-07-13 18:55:48 +0200
commitf1a2368d81fc3f70dfcf7d577957185da6ccf0b6 (patch)
tree92d8df1c8d3bbadcd56e10d1b1c956642a196551
parentbfd65589d9b6bd5fd2c8ee768d1427469bd61ead (diff)
downloadvim-git-f1a2368d81fc3f70dfcf7d577957185da6ccf0b6.tar.gz
patch 8.2.1201: Vim9: crash when passing number as dict keyv8.2.1201
Problem: Vim9: crash when passing number as dict key. Solution: Check key type to be string. (closes #6449)
-rw-r--r--src/testdir/test_vim9_func.vim8
-rw-r--r--src/version.c2
-rw-r--r--src/vim9compile.c9
3 files changed, 18 insertions, 1 deletions
diff --git a/src/testdir/test_vim9_func.vim b/src/testdir/test_vim9_func.vim
index 53206dfb7..99b2a113a 100644
--- a/src/testdir/test_vim9_func.vim
+++ b/src/testdir/test_vim9_func.vim
@@ -954,6 +954,14 @@ def Test_filter_return_type()
assert_equal(6, res)
enddef
+def Wrong_dict_key_type(items: list<number>): list<number>
+ return filter(items, {_, val -> get({val: 1}, 'x')})
+enddef
+
+def Test_wrong_dict_key_type()
+ assert_fails('Wrong_dict_key_type([1, 2, 3])', 'E1029:')
+enddef
+
def Line_continuation_in_def(dir: string = ''): string
let path: string = empty(dir)
\ ? 'empty'
diff --git a/src/version.c b/src/version.c
index 87eda28b4..2c9c4f07a 100644
--- a/src/version.c
+++ b/src/version.c
@@ -755,6 +755,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 1201,
+/**/
1200,
/**/
1199,
diff --git a/src/vim9compile.c b/src/vim9compile.c
index 8d6c1398d..30a92ff3c 100644
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -3212,6 +3212,7 @@ compile_lambda_call(char_u **arg, cctx_T *cctx)
compile_dict(char_u **arg, cctx_T *cctx, int literal)
{
garray_T *instr = &cctx->ctx_instr;
+ garray_T *stack = &cctx->ctx_type_stack;
int count = 0;
dict_T *d = dict_alloc();
dictitem_T *item;
@@ -3254,10 +3255,16 @@ compile_dict(char_u **arg, cctx_T *cctx, int literal)
if (compile_expr0(arg, cctx) == FAIL)
return FAIL;
- // TODO: check type is string
isn = ((isn_T *)instr->ga_data) + instr->ga_len - 1;
if (isn->isn_type == ISN_PUSHS)
key = isn->isn_arg.string;
+ else
+ {
+ type_T *keytype = ((type_T **)stack->ga_data)
+ [stack->ga_len - 1];
+ if (need_type(keytype, &t_string, -1, cctx, FALSE) == FAIL)
+ return FAIL;
+ }
}
// Check for duplicate keys, if using string keys.