| /* |
| * Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file |
| * for details. All rights reserved. Use of this source code is governed by a |
| * BSD-style license that can be found in the LICENSE file. |
| */ |
| /** |
| * @assertion It is a static error if: |
| * If a list or set spread element's static type implements [Iterable<T>] for |
| * some [T] and [T] is not assignable to the element type of the list. |
| * @description Checks that compile error is not thrown if spread element type |
| * in the list literal is assignable to the type of the list. |
| * @author iarkh@unipro.ru |
| */ |
| import "dart:collection"; |
| |
| class MyIterable<T> extends IterableBase<T> { |
| late MyIterator<T> iterator; |
| MyIterable() { iterator = new MyIterator(); } |
| Iterator getIterator<T>() { return iterator; } |
| } |
| |
| class MyIterator<T> extends Iterator<T> { |
| @override |
| bool moveNext() { return false; } |
| |
| @override |
| T get current => throw "Should not reach here!"; |
| } |
| |
| main() { |
| test1(); |
| test2(); |
| } |
| |
| void test1() { |
| List l1 = <Object> []; |
| List<bool> l2 = <bool>[true, false, true, true]; |
| List<String> l3 = <String>[]; |
| List<String> l4 = <String>["1", "2"]; |
| List l5 = <Object>["1", "2"]; |
| |
| Iterable<String> i1 = new MyIterable<String>(); |
| Iterable i2 = new MyIterable<Object>(); |
| |
| List list1 = <String>[...l1]; |
| List list2 = <Object>[...l2]; |
| List list3 = <String>[...l3]; |
| List list4 = <String>[...l4]; |
| List list5 = <String>[...l5]; |
| |
| List list16 = <String>[...i1]; |
| List list17 = <String>[...i2]; |
| } |
| |
| void test2() { |
| var l1 = <Object> [] as List?; |
| var l2 = <bool>[true, false, true, true] as List<bool>?; |
| var l3 = <String>[] as List<String>?; |
| var l4 = <String>["1", "2"] as List<String>?; |
| var l5 = <Object>["1", "2"] as List?; |
| |
| var i1 = new MyIterable<String>() as Iterable<String>?; |
| var i2 = new MyIterable<Object>() as Iterable?; |
| |
| List list8 = <String>[...?l1]; |
| List list9 = <Object>[...?l2]; |
| List list10 = <String>[...?l3]; |
| List list11 = <String>[...?l4]; |
| List list12 = <String>[...?l5]; |
| |
| List list13 = <String>[...?i1]; |
| List list14 = <String>[...?i2]; |
| } |