vimlist_remove(list, item, item);
if (list_extend(list, item->li_tv.vval.v_list, next) == FAIL)
+ {
+ list_free_item(list, item);
return;
+ }
clear_tv(&item->li_tv);
tofree = item;
rettv->vval.v_list = l;
if (l == NULL)
return;
+ // The type will change.
+ free_type(l->lv_type);
+ l->lv_type = NULL;
}
else
{
copy = list_alloc();
if (copy != NULL)
{
- copy->lv_type = orig->lv_type;
+ copy->lv_type = alloc_type(orig->lv_type);
if (copyID != 0)
{
// Do this before adding the items, because one of the items may
CheckDefAndScriptFailure2(['findfile("a", "b", "c")'], 'E1013: Argument 3: type mismatch, expected number but got string', 'E1210: Number required for argument 3')
enddef
+def Test_flatten()
+ var lines =<< trim END
+ echo flatten([1, 2, 3])
+ END
+ CheckDefAndScriptFailure(lines, 'E1158:')
+enddef
+
def Test_flattennew()
var lines =<< trim END
var l = [1, [2, [3, 4]], 5]
call assert_equal([1, 2, [3, 4], 5], flattennew(l, 1))
call assert_equal([1, [2, [3, 4]], 5], l)
+
+ var ll: list<list<string>> = [['a', 'b', 'c']]
+ assert_equal(['a', 'b', 'c'], ll->flattennew())
END
CheckDefAndScriptSuccess(lines)
- lines =<< trim END
- echo flatten([1, 2, 3])
- END
- CheckDefAndScriptFailure(lines, 'E1158:')
CheckDefAndScriptFailure2(['flattennew({})'], 'E1013: Argument 1: type mismatch, expected list<any> but got dict<unknown>', 'E1211: List required for argument 1')
CheckDefAndScriptFailure2(['flattennew([], "1")'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E1210: Number required for argument 2')
enddef