Files
sdk/pkg/front_end/testcases/nnbd/issue43455.dart
T
Dmitry Stefantsov d3114bac63 [cfe] Implement updates for UP and type parameters
Closes #43455.

Bug: https://github.com/dart-lang/sdk/issues/43455
Change-Id: Iaf083b21f0cabfd0f6907f0bf0549b643cb08417
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/164092
Commit-Queue: Dmitry Stefantsov <dmitryas@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2020-09-24 11:50:20 +00:00

47 lines
1.2 KiB
Dart

// Copyright (c) 2020, 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.
assertRightSubtype(dynamic x) {
x as Set<Object?>;
}
assertLeftSubtype<X>(X x) {
new Set<Object?>() as X;
}
class C<X extends Object?, Y extends Object> {
test(X x, Y? y) {
var v = {x, 42}; // Checking UP(X, int).
var w = {42, x}; // Checking UP(int, X).
var p = {y, 42}; // Checking UP(Y?, int).
var q = {42, y}; // Checking UP(int, Y?).
// Check that variable types are both subtype and supertype of Set<Object?>.
assertRightSubtype(v);
assertLeftSubtype(v);
assertRightSubtype(w);
assertLeftSubtype(w);
assertRightSubtype(p);
assertLeftSubtype(p);
assertRightSubtype(q);
assertLeftSubtype(q);
// Check the same for intersection types.
if (x is Object?) {
var v = {x, 42}; // Checking UP(X & Object?, int).
var w = {42, x}; // Checking UP(int, X & Object?).
assertRightSubtype(v);
assertLeftSubtype(v);
assertRightSubtype(w);
assertLeftSubtype(w);
}
}
}
main() {
new C<int?, int>().test(42, null);
new C<int?, int>().test(null, null);
}