blob: 3c63d1a4a33437e445089813aaa0793f91c0f015 [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 In a setOrMapLiteral collection, the inferred type of an element
/// is a set element type T, a pair of a key type K and a value type V, or both.
/// It is computed relative to a context type P:
///
/// If collection is unambiguously a set literal, then P is Set<Pe> where Pe is
/// determined by downwards inference, and may be ? if downwards inference does
/// not constrain it.
///
/// @description Checks that if collection is unambiguously a set literal, then P
/// is Set<Pe> where Pe is determined by downwards inference and may be ?
/// @author sgrekhov@unipro.ru
import "../../Utils/expect.dart";
void test1<X extends num>(X x, X y) {
var s1 = {x, y};
var s2 = <X> {};
Expect.isTrue(s1 is Set<int>);
Expect.isTrue(s2 is Set<num>);
Expect.runtimeIsType<Set<int>>(s1);
Expect.runtimeIsType<Set<num>>(s2);
}
void test2<X extends num>(X x, X y) {
var s1 = {x, y};
var s2 = <X> {};
Expect.isTrue(s1 is Set<double>);
Expect.isTrue(s2 is Set<num>);
Expect.runtimeIsType<Set<double>>(s1);
Expect.runtimeIsType<Set<num>>(s2);
}
void test3<X extends num>(X x, X y) {
var s1 = {x, y};
var s2 = <X> {};
Expect.isTrue(s1 is Set<num>);
Expect.isTrue(s2 is Set<num>);
Expect.runtimeIsType<Set<num>>(s1);
Expect.runtimeIsType<Set<num>>(s2);
}
main() {
test1(3, 1);
test2(3.14, 2.718);
test3(3, 2.718);
}