Mercurial > vim
diff src/vim9type.c @ 21803:e591b448a670 v8.2.1451
patch 8.2.1451: Vim9: list type at script level only uses first item
Commit: https://github.com/vim/vim/commit/41fab3eac80893fd203663fc6a7ded09b04b633f
Author: Bram Moolenaar <Bram@vim.org>
Date: Fri Aug 14 21:27:37 2020 +0200
patch 8.2.1451: Vim9: list type at script level only uses first item
Problem: Vim9: list type at script level only uses first item.
Solution: Use all members, like in a compiled function. (closes https://github.com/vim/vim/issues/6712)
Also for dictionary.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Fri, 14 Aug 2020 21:30:04 +0200 |
parents | f84625b961a8 |
children | 0deb6f96a5a3 |
line wrap: on
line diff
--- a/src/vim9type.c +++ b/src/vim9type.c @@ -214,11 +214,17 @@ typval2type(typval_T *tv, garray_T *type if (tv->v_type == VAR_LIST) { + listitem_T *li; + if (tv->vval.v_list == NULL || tv->vval.v_list->lv_first == NULL) return &t_list_empty; - // Use the type of the first member, it is the most specific. + // Use the common type of all members. member_type = typval2type(&tv->vval.v_list->lv_first->li_tv, type_gap); + for (li = tv->vval.v_list->lv_first->li_next; li != NULL; + li = li->li_next) + common_type(typval2type(&li->li_tv, type_gap), + member_type, &member_type, type_gap); return get_list_type(member_type, type_gap); } @@ -231,10 +237,13 @@ typval2type(typval_T *tv, garray_T *type || tv->vval.v_dict->dv_hashtab.ht_used == 0) return &t_dict_empty; - // Use the type of the first value, it is the most specific. + // Use the common type of all values. dict_iterate_start(tv, &iter); dict_iterate_next(&iter, &value); member_type = typval2type(value, type_gap); + while (dict_iterate_next(&iter, &value) != NULL) + common_type(typval2type(value, type_gap), + member_type, &member_type, type_gap); return get_dict_type(member_type, type_gap); }