dart-sdk/tests/language/least_upper_bound/runtime_test.dart
Robert Nystrom 1b8f589d3c Migrate language_2/least_upper_bound to NNBD.
Change-Id: Id1cffba25214323478af50a8ae539236377d53c6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/149047
Commit-Queue: Bob Nystrom <rnystrom@google.com>
Reviewed-by: Erik Ernst <eernst@google.com>
2020-05-30 00:55:26 +00:00

36 lines
1 KiB
Dart

// Copyright (c) 2013, 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.
// Test least upper bound through type checking of conditionals.
import 'package:expect/expect.dart';
class Expect {
static isTrue(bool cond, String message) {
if (!cond) throw message;
}
}
class A {}
class B {}
class C extends B {}
class D extends B {}
class E<T> {}
class F<T> extends E<T> {}
void main() {
checkType(true ? A() : B())<Object>();
checkType(true ? B() : C())<B>();
checkType(true ? C() : D())<B>();
checkType(true ? E<B>() : E<C>())<E<B>>();
checkType(true ? E<B>() : F<C>())<E<B>>();
}
/// Tests that [A] (which should be inferred from the expression for [actual]
/// is the same as [E].
void Function<E>() checkType<A>(A actual) {
return <E>() {
Expect.isTrue(<E>[] is List<A> && <A>[] is List<E>,
"Argument expression should have inferred type '$E' but was '$A'.");
};
}