v9.CheckScriptSuccess(lines)
enddef
+def Test_assignment_empty_list()
+ var lines =<< trim END
+ var l2: list<any> = []
+ var l: list<string>
+ l = l2
+ END
+ v9.CheckDefAndScriptSuccess(lines)
+enddef
+
def Test_assignment_vim9script()
var lines =<< trim END
vim9script
enddef
Foo()
END
+ # "any" could be "dict<any>", thus OK
lines[2] = 'var l: list<any>'
- v9.CheckScriptFailure(lines, 'E1013: Argument 1: type mismatch, expected list<dict<any>> but got list<any>', 2)
-
+ v9.CheckScriptSuccess(lines)
lines[2] = 'var l: list<any> = []'
- v9.CheckScriptFailure(lines, 'E1013: Argument 1: type mismatch, expected list<dict<any>> but got list<any>', 2)
+ v9.CheckScriptSuccess(lines)
lines[2] = 'var l: list<any> = [11]'
v9.CheckScriptFailure(lines, 'E1013: Argument 1: type mismatch, expected list<dict<any>> but got list<number>', 2)
static int included_patches[] =
{ /* Add new patch number below this line */
+/**/
+ 4287,
/**/
4286,
/**/
list_T *l = tv->vval.v_list;
listitem_T *li;
- if (l == NULL || (l->lv_first == NULL && l->lv_type == NULL))
+ // An empty list has type list<unknown>, unless the type was specified
+ // and is not list<any>. This matters when assigning to a variable
+ // with a specific list type.
+ if (l == NULL || (l->lv_first == NULL
+ && (l->lv_type == NULL || l->lv_type->tt_member == &t_any)))
return &t_list_empty;
if ((flags & TVTT_DO_MEMBER) == 0)
return &t_list_any;