summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2021-01-17 21:51:24 +0100
committerBram Moolenaar <Bram@vim.org>2021-01-17 21:51:24 +0100
commitf30a14db3b26e510f193f50ee0dd8a41303e4740 (patch)
tree065f9cfc1ad0ec9bc3afff7dca57062c2a6df890
parent585587dadbc2558520c33969098db9ff49598785 (diff)
patch 8.2.2373: Vim9: list assignment only accepts a number indexv8.2.2373
Problem: Vim9: list assignment only accepts a number index. Solution: Accept "any" and do a runtime type check. (closes #7694)
-rw-r--r--src/testdir/test_vim9_assign.vim13
-rw-r--r--src/version.c2
-rw-r--r--src/vim9compile.c7
3 files changed, 15 insertions, 7 deletions
diff --git a/src/testdir/test_vim9_assign.vim b/src/testdir/test_vim9_assign.vim
index c035558803..20bdb91380 100644
--- a/src/testdir/test_vim9_assign.vim
+++ b/src/testdir/test_vim9_assign.vim
@@ -350,7 +350,7 @@ def Test_assign_index()
var lines: list<string>
lines['a'] = 'asdf'
END
- CheckDefFailure(lines, 'E39:', 2)
+ CheckDefFailure(lines, 'E1012:', 2)
lines =<< trim END
var lines: string
@@ -561,6 +561,15 @@ def Test_assignment_list()
CheckDefExecFailure(lines, 'E1147:', 2)
enddef
+def Test_assignment_list_any_index()
+ var l: list<number> = [1, 2]
+ for [x, y, _]
+ in [[0, 1, ''], [1, 3, '']]
+ l[x] = l[x] + y
+ endfor
+ assert_equal([2, 5], l)
+enddef
+
def Test_assignment_list_vim9script()
var lines =<< trim END
vim9script
@@ -1405,7 +1414,7 @@ def Test_unlet()
CheckDefExecFailure([
'var ll = [1]',
'unlet ll[g:astring]',
- ], 'E39:', 2)
+ ], 'E1012:', 2)
CheckDefExecFailure([
'var dd = test_null_dict()',
'unlet dd["a"]',
diff --git a/src/version.c b/src/version.c
index 3a88080e0d..f1b728048a 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 */
/**/
+ 2373,
+/**/
2372,
/**/
2371,
diff --git a/src/vim9compile.c b/src/vim9compile.c
index 01bf2c19a8..d1df00821c 100644
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -5802,12 +5802,9 @@ compile_assign_unlet(
if (dest_type == VAR_DICT && may_generate_2STRING(-1, cctx) == FAIL)
return FAIL;
if (dest_type == VAR_LIST
- && ((type_T **)stack->ga_data)[stack->ga_len - 1]->tt_type
- != VAR_NUMBER)
- {
- emsg(_(e_number_exp));
+ && need_type(((type_T **)stack->ga_data)[stack->ga_len - 1],
+ &t_number, -1, 0, cctx, FALSE, FALSE) == FAIL)
return FAIL;
- }
}
// Load the dict or list. On the stack we then have: