mirror of
https://github.com/vim/vim.git
synced 2025-07-26 11:04:33 -04:00
patch 8.2.3338: Vim9: no type check when assigning a list range
Problem: Vim9: no type check when assigning a list range. (Naohiro Ono) Solution: Check the member type. (closes #8750)
This commit is contained in:
parent
069f90852f
commit
89071cb6a1
@ -852,6 +852,7 @@ list_assign_range(
|
|||||||
long idx1 = idx1_arg;
|
long idx1 = idx1_arg;
|
||||||
listitem_T *first_li = list_find_index(dest, &idx1);
|
listitem_T *first_li = list_find_index(dest, &idx1);
|
||||||
long idx;
|
long idx;
|
||||||
|
type_T *member_type = NULL;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Check whether any of the list items is locked before making any changes.
|
* Check whether any of the list items is locked before making any changes.
|
||||||
@ -869,6 +870,10 @@ list_assign_range(
|
|||||||
++idx;
|
++idx;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (in_vim9script() && dest->lv_type != NULL
|
||||||
|
&& dest->lv_type->tt_member != NULL)
|
||||||
|
member_type = dest->lv_type->tt_member;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Assign the List values to the list items.
|
* Assign the List values to the list items.
|
||||||
*/
|
*/
|
||||||
@ -880,6 +885,10 @@ list_assign_range(
|
|||||||
tv_op(&dest_li->li_tv, &src_li->li_tv, op);
|
tv_op(&dest_li->li_tv, &src_li->li_tv, op);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
if (member_type != NULL
|
||||||
|
&& check_typval_arg_type(member_type, &src_li->li_tv,
|
||||||
|
NULL, 0) == FAIL)
|
||||||
|
return FAIL;
|
||||||
clear_tv(&dest_li->li_tv);
|
clear_tv(&dest_li->li_tv);
|
||||||
copy_tv(&src_li->li_tv, &dest_li->li_tv);
|
copy_tv(&src_li->li_tv, &dest_li->li_tv);
|
||||||
}
|
}
|
||||||
|
@ -189,6 +189,12 @@ func Test_list_range_assign()
|
|||||||
call assert_equal([5, 6], l)
|
call assert_equal([5, 6], l)
|
||||||
END
|
END
|
||||||
call CheckLegacyAndVim9Success(lines)
|
call CheckLegacyAndVim9Success(lines)
|
||||||
|
|
||||||
|
let lines =<< trim END
|
||||||
|
var l = [7]
|
||||||
|
l[:] = ['text']
|
||||||
|
END
|
||||||
|
call CheckDefAndScriptFailure(lines, 'E1012:', 2)
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
" Test removing items in list
|
" Test removing items in list
|
||||||
|
@ -755,6 +755,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 */
|
||||||
|
/**/
|
||||||
|
3338,
|
||||||
/**/
|
/**/
|
||||||
3337,
|
3337,
|
||||||
/**/
|
/**/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user