summaryrefslogtreecommitdiffstats
path: root/src/vim9type.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/vim9type.c')
-rw-r--r--src/vim9type.c26
1 files changed, 16 insertions, 10 deletions
diff --git a/src/vim9type.c b/src/vim9type.c
index 2485efb41e..8b0f2f15e2 100644
--- a/src/vim9type.c
+++ b/src/vim9type.c
@@ -252,9 +252,10 @@ func_type_add_arg_types(
/*
* Get a type_T for a typval_T.
* "type_gap" is used to temporarily create types in.
+ * When "do_member" is TRUE also get the member type, otherwise use "any".
*/
static type_T *
-typval2type_int(typval_T *tv, int copyID, garray_T *type_gap)
+typval2type_int(typval_T *tv, int copyID, garray_T *type_gap, int do_member)
{
type_T *type;
type_T *member_type = &t_any;
@@ -274,6 +275,8 @@ typval2type_int(typval_T *tv, int copyID, garray_T *type_gap)
if (l == NULL || l->lv_first == NULL)
return &t_list_empty;
+ if (!do_member)
+ return &t_list_any;
if (l->lv_first == &range_list_item)
return &t_list_number;
if (l->lv_copyID == copyID)
@@ -282,9 +285,9 @@ typval2type_int(typval_T *tv, int copyID, garray_T *type_gap)
l->lv_copyID = copyID;
// Use the common type of all members.
- member_type = typval2type(&l->lv_first->li_tv, copyID, type_gap);
+ member_type = typval2type(&l->lv_first->li_tv, copyID, type_gap, TRUE);
for (li = l->lv_first->li_next; li != NULL; li = li->li_next)
- common_type(typval2type(&li->li_tv, copyID, type_gap),
+ common_type(typval2type(&li->li_tv, copyID, type_gap, TRUE),
member_type, &member_type, type_gap);
return get_list_type(member_type, type_gap);
}
@@ -297,6 +300,8 @@ typval2type_int(typval_T *tv, int copyID, garray_T *type_gap)
if (d == NULL || d->dv_hashtab.ht_used == 0)
return &t_dict_empty;
+ if (!do_member)
+ return &t_dict_any;
if (d->dv_copyID == copyID)
// avoid recursion
return &t_dict_any;
@@ -305,9 +310,9 @@ typval2type_int(typval_T *tv, int copyID, garray_T *type_gap)
// Use the common type of all values.
dict_iterate_start(tv, &iter);
dict_iterate_next(&iter, &value);
- member_type = typval2type(value, copyID, type_gap);
+ member_type = typval2type(value, copyID, type_gap, TRUE);
while (dict_iterate_next(&iter, &value) != NULL)
- common_type(typval2type(value, copyID, type_gap),
+ common_type(typval2type(value, copyID, type_gap, TRUE),
member_type, &member_type, type_gap);
return get_dict_type(member_type, type_gap);
}
@@ -378,11 +383,12 @@ need_convert_to_bool(type_T *type, typval_T *tv)
/*
* Get a type_T for a typval_T.
* "type_list" is used to temporarily create types in.
+ * When "do_member" is TRUE also get the member type, otherwise use "any".
*/
type_T *
-typval2type(typval_T *tv, int copyID, garray_T *type_gap)
+typval2type(typval_T *tv, int copyID, garray_T *type_gap, int do_member)
{
- type_T *type = typval2type_int(tv, copyID, type_gap);
+ type_T *type = typval2type_int(tv, copyID, type_gap, do_member);
if (type != NULL && type != &t_bool
&& (tv->v_type == VAR_NUMBER
@@ -404,7 +410,7 @@ typval2type_vimvar(typval_T *tv, garray_T *type_gap)
return &t_list_string;
if (tv->v_type == VAR_DICT) // e.g. for v:completed_item
return &t_dict_any;
- return typval2type(tv, get_copyID(), type_gap);
+ return typval2type(tv, get_copyID(), type_gap, TRUE);
}
int
@@ -429,7 +435,7 @@ check_typval_type(type_T *expected, typval_T *actual_tv, where_T where)
int res = FAIL;
ga_init2(&type_list, sizeof(type_T *), 10);
- actual_type = typval2type(actual_tv, get_copyID(), &type_list);
+ actual_type = typval2type(actual_tv, get_copyID(), &type_list, TRUE);
if (actual_type != NULL)
res = check_type(expected, actual_type, TRUE, where);
clear_type_list(&type_list);
@@ -1210,7 +1216,7 @@ f_typename(typval_T *argvars, typval_T *rettv)
rettv->v_type = VAR_STRING;
ga_init2(&type_list, sizeof(type_T *), 10);
- type = typval2type(argvars, get_copyID(), &type_list);
+ type = typval2type(argvars, get_copyID(), &type_list, TRUE);
name = type_name(type, &tofree);
if (tofree != NULL)
rettv->vval.v_string = (char_u *)tofree;