1
0
forked from aniani/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.
This commit is contained in:
Bram Moolenaar
2020-08-14 21:27:37 +02:00
parent 7d6997015d
commit 41fab3eac8
3 changed files with 55 additions and 2 deletions

View File

@@ -1498,6 +1498,27 @@ def Test_expr7_list_vim9script()
let l = [11 , 22]
END
CheckScriptFailure(lines, 'E1068:')
lines =<< trim END
vim9script
let l: list<number> = [234, 'x']
END
CheckScriptFailure(lines, 'E1013:')
lines =<< trim END
vim9script
let l: list<number> = ['x', 234]
END
CheckScriptFailure(lines, 'E1013:')
lines =<< trim END
vim9script
let l: list<string> = ['x', 234]
END
CheckScriptFailure(lines, 'E1013:')
lines =<< trim END
vim9script
let l: list<string> = [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<number> = #{a: 234, b: 'x'}
END
CheckScriptFailure(lines, 'E1013:')
lines =<< trim END
vim9script
let l: dict<number> = #{a: 'x', b: 234}
END
CheckScriptFailure(lines, 'E1013:')
lines =<< trim END
vim9script
let l: dict<string> = #{a: 'x', b: 234}
END
CheckScriptFailure(lines, 'E1013:')
lines =<< trim END
vim9script
let l: dict<string> = #{a: 234, b: 'x'}
END
CheckScriptFailure(lines, 'E1013:')
enddef
let g:oneString = 'one'

View File

@@ -754,6 +754,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
1451,
/**/
1450,
/**/

View File

@@ -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);
}