To: vim_dev@googlegroups.com Subject: Patch 8.2.1451 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.1451 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. Files: src/vim9type.c, src/testdir/test_vim9_expr.vim *** ../vim-8.2.1450/src/vim9type.c 2020-08-13 22:47:20.377992734 +0200 --- src/vim9type.c 2020-08-14 21:26:13.913801830 +0200 *************** *** 214,224 **** if (tv->v_type == VAR_LIST) { 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. member_type = typval2type(&tv->vval.v_list->lv_first->li_tv, type_gap); return get_list_type(member_type, type_gap); } --- 214,230 ---- 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 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,240 **** || 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. dict_iterate_start(tv, &iter); dict_iterate_next(&iter, &value); member_type = typval2type(value, type_gap); return get_dict_type(member_type, type_gap); } --- 237,249 ---- || tv->vval.v_dict->dv_hashtab.ht_used == 0) return &t_dict_empty; ! // 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); } *** ../vim-8.2.1450/src/testdir/test_vim9_expr.vim 2020-08-12 21:34:43.270489452 +0200 --- src/testdir/test_vim9_expr.vim 2020-08-14 21:23:34.034738644 +0200 *************** *** 1498,1503 **** --- 1498,1524 ---- 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,1684 **** --- 1700,1726 ---- 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' *** ../vim-8.2.1450/src/version.c 2020-08-14 20:52:25.174495868 +0200 --- src/version.c 2020-08-14 21:20:11.507872493 +0200 *************** *** 756,757 **** --- 756,759 ---- { /* Add new patch number below this line */ + /**/ + 1451, /**/ -- hundred-and-one symptoms of being an internet addict: 201. When somebody asks you where you are, you tell them in which chat room. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///