From: Bram Moolenaar Date: Fri, 14 Aug 2020 19:27:37 +0000 (+0200) Subject: patch 8.2.1451: Vim9: list type at script level only uses first item X-Git-Tag: v8.2.1451 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=41fab3eac80893fd203663fc6a7ded09b04b633f;p=vim 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 #6712) Also for dictionary. --- diff --git a/src/testdir/test_vim9_expr.vim b/src/testdir/test_vim9_expr.vim index 81d3cb9f9..c6734539e 100644 --- a/src/testdir/test_vim9_expr.vim +++ b/src/testdir/test_vim9_expr.vim @@ -1498,6 +1498,27 @@ def Test_expr7_list_vim9script() let l = [11 , 22] END CheckScriptFailure(lines, 'E1068:') + + lines =<< trim END + vim9script + let l: list = [234, 'x'] + END + CheckScriptFailure(lines, 'E1013:') + lines =<< trim END + vim9script + let l: list = ['x', 234] + END + CheckScriptFailure(lines, 'E1013:') + lines =<< trim END + vim9script + let l: list = ['x', 234] + END + CheckScriptFailure(lines, 'E1013:') + lines =<< trim END + vim9script + let l: list = [234, 'x'] + END + CheckScriptFailure(lines, 'E1013:') enddef def LambdaWithComments(): func @@ -1679,6 +1700,27 @@ def Test_expr7_dict_vim9script() let d = #{one: 1 , two: 2} END CheckScriptFailure(lines, 'E1068:') + + lines =<< trim END + vim9script + let l: dict = #{a: 234, b: 'x'} + END + CheckScriptFailure(lines, 'E1013:') + lines =<< trim END + vim9script + let l: dict = #{a: 'x', b: 234} + END + CheckScriptFailure(lines, 'E1013:') + lines =<< trim END + vim9script + let l: dict = #{a: 'x', b: 234} + END + CheckScriptFailure(lines, 'E1013:') + lines =<< trim END + vim9script + let l: dict = #{a: 234, b: 'x'} + END + CheckScriptFailure(lines, 'E1013:') enddef let g:oneString = 'one' diff --git a/src/version.c b/src/version.c index ce5bfb01a..132af7cae 100644 --- a/src/version.c +++ b/src/version.c @@ -754,6 +754,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 1451, /**/ 1450, /**/ diff --git a/src/vim9type.c b/src/vim9type.c index 95785974a..318739bde 100644 --- a/src/vim9type.c +++ b/src/vim9type.c @@ -214,11 +214,17 @@ typval2type(typval_T *tv, garray_T *type_gap) 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_gap) || 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); }