blob: 18402c526d57f1c8c1c1879c860f51c022e2aa23 [file] [log] [blame]
// 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 To infer the type of element:
/// ...
/// If element is a spreadElement with expression e1:
///
/// If P is ? then let S be the inferred type of e1 in context ?:
///
/// If S is a non-Null subtype of Iterable<Object>, then the inferred set element
/// type of element is T where T is the type such that Iterable<T> is a
/// superinterface of S (the result of constraint matching for X using the
/// constraint S <: Iterable<X>).
///
/// @description Checks that if S is a non-Null subtype of Iterable<Object?>,
/// then the inferred set element type of element is T where T is the type such
/// that Iterable<T> is a superinterface of S
/// @author sgrekhov@unipro.ru
import "../../Utils/expect.dart";
void test1<T extends Iterable<num>>(T t) {
var s1 = {...t};
var s2 = {...?t};
// ^^^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
// ^
// [cfe] Operand of null-aware operation '...?' has type 'T' which excludes null.
Expect.isTrue(s1 is Set<num>);
Expect.isFalse(s1 is Set<int>);
Expect.isTrue(s2 is Set<num>);
Expect.isFalse(s2 is Set<int>);
Expect.runtimeIsType<Set<num>>(s1);
Expect.runtimeIsNotType<Set<int>>(s1);
Expect.runtimeIsType<Set<num>>(s2);
Expect.runtimeIsNotType<Set<int>>(s2);
}
void test2<T extends Iterable<Object>>(T t) {
var s1 = {...t};
var s2 = {...?t};
// ^^^^
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
// ^
// [cfe] Operand of null-aware operation '...?' has type 'T' which excludes null.
Expect.isTrue(s1 is Set<Object>);
Expect.isFalse(s1 is Set<num>);
Expect.isTrue(s2 is Set<Object>);
Expect.isFalse(s2 is Set<num>);
Expect.runtimeIsType<Set<Object>>(s1);
Expect.runtimeIsNotType<Set<num>>(s1);
Expect.runtimeIsType<Set<Object>>(s2);
Expect.runtimeIsNotType<Set<num>>(s2);
}
main() {
int x = 2;
test1([1, x, 3, 4]);
test2([1.0, 2.0, x, 4]);
}