forked from aniani/vim
patch 8.2.3127: Vim9: no error when adding number to list of string
Problem: Vim9: no error when adding number to list of string. Solution: Check the value type. (closes #8529)
This commit is contained in:
@@ -597,13 +597,16 @@ list_append(list_T *l, listitem_T *item)
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Append typval_T "tv" to the end of list "l". "tv" is copied.
|
* Append typval_T "tv" to the end of list "l". "tv" is copied.
|
||||||
* Return FAIL when out of memory.
|
* Return FAIL when out of memory or the type is wrong.
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
list_append_tv(list_T *l, typval_T *tv)
|
list_append_tv(list_T *l, typval_T *tv)
|
||||||
{
|
{
|
||||||
listitem_T *li = listitem_alloc();
|
listitem_T *li = listitem_alloc();
|
||||||
|
|
||||||
|
if (l->lv_type != NULL && l->lv_type->tt_member != NULL
|
||||||
|
&& check_typval_arg_type(l->lv_type->tt_member, tv, 0) == FAIL)
|
||||||
|
return FAIL;
|
||||||
if (li == NULL)
|
if (li == NULL)
|
||||||
return FAIL;
|
return FAIL;
|
||||||
copy_tv(tv, &li->li_tv);
|
copy_tv(tv, &li->li_tv);
|
||||||
|
|||||||
@@ -104,6 +104,13 @@ def Test_add_list()
|
|||||||
add(l, 123)
|
add(l, 123)
|
||||||
END
|
END
|
||||||
CheckScriptSuccess(lines)
|
CheckScriptSuccess(lines)
|
||||||
|
|
||||||
|
lines =<< trim END
|
||||||
|
vim9script
|
||||||
|
var l: list<string> = ['a']
|
||||||
|
l->add(123)
|
||||||
|
END
|
||||||
|
CheckScriptFailure(lines, 'E1012: Type mismatch; expected string but got number', 3)
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
def Test_add_blob()
|
def Test_add_blob()
|
||||||
|
|||||||
@@ -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 */
|
||||||
|
/**/
|
||||||
|
3127,
|
||||||
/**/
|
/**/
|
||||||
3126,
|
3126,
|
||||||
/**/
|
/**/
|
||||||
|
|||||||
Reference in New Issue
Block a user