mirror of
https://github.com/vim/vim.git
synced 2025-07-25 10:54:51 -04:00
patch 8.2.3322: Vim9: checking type of dict does not check member type
Problem: Vim9: checking type of dict does not check member type. Solution: When getting the type of a typval use dv_type and lv_type. (closes #8732)
This commit is contained in:
parent
bd9e796125
commit
b56c4419d4
@ -922,6 +922,12 @@ def Test_extend_dict_item_type()
|
|||||||
END
|
END
|
||||||
CheckDefExecFailure(lines, 'E1012: Type mismatch; expected number but got string', 0)
|
CheckDefExecFailure(lines, 'E1012: Type mismatch; expected number but got string', 0)
|
||||||
CheckScriptFailure(['vim9script'] + lines, 'E1012:', 1)
|
CheckScriptFailure(['vim9script'] + lines, 'E1012:', 1)
|
||||||
|
|
||||||
|
lines =<< trim END
|
||||||
|
var d: dict<bool>
|
||||||
|
extend(d, {b: 0})
|
||||||
|
END
|
||||||
|
CheckDefAndScriptFailure(lines, 'E1013: Argument 2: type mismatch, expected dict<bool> but got dict<number>', 2)
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
func g:ExtendList(l)
|
func g:ExtendList(l)
|
||||||
@ -947,6 +953,12 @@ def Test_extend_list_item_type()
|
|||||||
END
|
END
|
||||||
CheckDefExecFailure(lines, 'E1012: Type mismatch; expected number but got string', 0)
|
CheckDefExecFailure(lines, 'E1012: Type mismatch; expected number but got string', 0)
|
||||||
CheckScriptFailure(['vim9script'] + lines, 'E1012:', 1)
|
CheckScriptFailure(['vim9script'] + lines, 'E1012:', 1)
|
||||||
|
|
||||||
|
lines =<< trim END
|
||||||
|
var l: list<bool>
|
||||||
|
extend(l, [0])
|
||||||
|
END
|
||||||
|
CheckDefAndScriptFailure(lines, 'E1013: Argument 2: type mismatch, expected list<bool> but got list<number>', 2)
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
def Test_extend_return_type()
|
def Test_extend_return_type()
|
||||||
|
@ -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 */
|
||||||
|
/**/
|
||||||
|
3322,
|
||||||
/**/
|
/**/
|
||||||
3321,
|
3321,
|
||||||
/**/
|
/**/
|
||||||
|
@ -274,10 +274,12 @@ typval2type_int(typval_T *tv, int copyID, garray_T *type_gap, int do_member)
|
|||||||
list_T *l = tv->vval.v_list;
|
list_T *l = tv->vval.v_list;
|
||||||
listitem_T *li;
|
listitem_T *li;
|
||||||
|
|
||||||
if (l == NULL || l->lv_first == NULL)
|
if (l == NULL || (l->lv_first == NULL && l->lv_type == NULL))
|
||||||
return &t_list_empty;
|
return &t_list_empty;
|
||||||
if (!do_member)
|
if (!do_member)
|
||||||
return &t_list_any;
|
return &t_list_any;
|
||||||
|
if (l->lv_type != NULL)
|
||||||
|
return l->lv_type;
|
||||||
if (l->lv_first == &range_list_item)
|
if (l->lv_first == &range_list_item)
|
||||||
return &t_list_number;
|
return &t_list_number;
|
||||||
if (l->lv_copyID == copyID)
|
if (l->lv_copyID == copyID)
|
||||||
@ -299,10 +301,12 @@ typval2type_int(typval_T *tv, int copyID, garray_T *type_gap, int do_member)
|
|||||||
typval_T *value;
|
typval_T *value;
|
||||||
dict_T *d = tv->vval.v_dict;
|
dict_T *d = tv->vval.v_dict;
|
||||||
|
|
||||||
if (d == NULL || d->dv_hashtab.ht_used == 0)
|
if (d == NULL || (d->dv_hashtab.ht_used == 0 && d->dv_type == NULL))
|
||||||
return &t_dict_empty;
|
return &t_dict_empty;
|
||||||
if (!do_member)
|
if (!do_member)
|
||||||
return &t_dict_any;
|
return &t_dict_any;
|
||||||
|
if (d->dv_type != NULL)
|
||||||
|
return d->dv_type;
|
||||||
if (d->dv_copyID == copyID)
|
if (d->dv_copyID == copyID)
|
||||||
// avoid recursion
|
// avoid recursion
|
||||||
return &t_dict_any;
|
return &t_dict_any;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user