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:
@@ -1498,6 +1498,27 @@ def Test_expr7_list_vim9script()
|
|||||||
let l = [11 , 22]
|
let l = [11 , 22]
|
||||||
END
|
END
|
||||||
CheckScriptFailure(lines, 'E1068:')
|
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
|
enddef
|
||||||
|
|
||||||
def LambdaWithComments(): func
|
def LambdaWithComments(): func
|
||||||
@@ -1679,6 +1700,27 @@ def Test_expr7_dict_vim9script()
|
|||||||
let d = #{one: 1 , two: 2}
|
let d = #{one: 1 , two: 2}
|
||||||
END
|
END
|
||||||
CheckScriptFailure(lines, 'E1068:')
|
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
|
enddef
|
||||||
|
|
||||||
let g:oneString = 'one'
|
let g:oneString = 'one'
|
||||||
|
@@ -754,6 +754,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
1451,
|
||||||
/**/
|
/**/
|
||||||
1450,
|
1450,
|
||||||
/**/
|
/**/
|
||||||
|
@@ -214,11 +214,17 @@ typval2type(typval_T *tv, garray_T *type_gap)
|
|||||||
|
|
||||||
if (tv->v_type == VAR_LIST)
|
if (tv->v_type == VAR_LIST)
|
||||||
{
|
{
|
||||||
|
listitem_T *li;
|
||||||
|
|
||||||
if (tv->vval.v_list == NULL || tv->vval.v_list->lv_first == NULL)
|
if (tv->vval.v_list == NULL || tv->vval.v_list->lv_first == NULL)
|
||||||
return &t_list_empty;
|
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);
|
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);
|
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)
|
|| tv->vval.v_dict->dv_hashtab.ht_used == 0)
|
||||||
return &t_dict_empty;
|
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_start(tv, &iter);
|
||||||
dict_iterate_next(&iter, &value);
|
dict_iterate_next(&iter, &value);
|
||||||
member_type = typval2type(value, type_gap);
|
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);
|
return get_dict_type(member_type, type_gap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user