mirror of
https://github.com/vim/vim.git
synced 2025-07-26 11:04:33 -04:00
patch 8.2.2373: Vim9: list assignment only accepts a number index
Problem: Vim9: list assignment only accepts a number index. Solution: Accept "any" and do a runtime type check. (closes #7694)
This commit is contained in:
parent
585587dadb
commit
f30a14db3b
@ -350,7 +350,7 @@ def Test_assign_index()
|
|||||||
var lines: list<string>
|
var lines: list<string>
|
||||||
lines['a'] = 'asdf'
|
lines['a'] = 'asdf'
|
||||||
END
|
END
|
||||||
CheckDefFailure(lines, 'E39:', 2)
|
CheckDefFailure(lines, 'E1012:', 2)
|
||||||
|
|
||||||
lines =<< trim END
|
lines =<< trim END
|
||||||
var lines: string
|
var lines: string
|
||||||
@ -561,6 +561,15 @@ def Test_assignment_list()
|
|||||||
CheckDefExecFailure(lines, 'E1147:', 2)
|
CheckDefExecFailure(lines, 'E1147:', 2)
|
||||||
enddef
|
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()
|
def Test_assignment_list_vim9script()
|
||||||
var lines =<< trim END
|
var lines =<< trim END
|
||||||
vim9script
|
vim9script
|
||||||
@ -1405,7 +1414,7 @@ def Test_unlet()
|
|||||||
CheckDefExecFailure([
|
CheckDefExecFailure([
|
||||||
'var ll = [1]',
|
'var ll = [1]',
|
||||||
'unlet ll[g:astring]',
|
'unlet ll[g:astring]',
|
||||||
], 'E39:', 2)
|
], 'E1012:', 2)
|
||||||
CheckDefExecFailure([
|
CheckDefExecFailure([
|
||||||
'var dd = test_null_dict()',
|
'var dd = test_null_dict()',
|
||||||
'unlet dd["a"]',
|
'unlet dd["a"]',
|
||||||
|
@ -750,6 +750,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
2373,
|
||||||
/**/
|
/**/
|
||||||
2372,
|
2372,
|
||||||
/**/
|
/**/
|
||||||
|
@ -5802,13 +5802,10 @@ compile_assign_unlet(
|
|||||||
if (dest_type == VAR_DICT && may_generate_2STRING(-1, cctx) == FAIL)
|
if (dest_type == VAR_DICT && may_generate_2STRING(-1, cctx) == FAIL)
|
||||||
return FAIL;
|
return FAIL;
|
||||||
if (dest_type == VAR_LIST
|
if (dest_type == VAR_LIST
|
||||||
&& ((type_T **)stack->ga_data)[stack->ga_len - 1]->tt_type
|
&& need_type(((type_T **)stack->ga_data)[stack->ga_len - 1],
|
||||||
!= VAR_NUMBER)
|
&t_number, -1, 0, cctx, FALSE, FALSE) == FAIL)
|
||||||
{
|
|
||||||
emsg(_(e_number_exp));
|
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Load the dict or list. On the stack we then have:
|
// Load the dict or list. On the stack we then have:
|
||||||
// - value (for assignment, not for :unlet)
|
// - value (for assignment, not for :unlet)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user