mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 00:09:49 +00:00
0cf3c37e9e
Change-Id: Icf229e3877ce646340b6dad1bd49c20110953d44 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/169885 Reviewed-by: Johnni Winther <johnniwinther@google.com> Commit-Queue: Erik Ernst <eernst@google.com>
56 lines
1.7 KiB
Dart
56 lines
1.7 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.
|
|
|
|
// Test least upper bound for a Function type and a type that doesn't match
|
|
// any of the cases for function types being subtypes of each other.
|
|
|
|
import 'dart:async';
|
|
import '../static_type_helper.dart';
|
|
|
|
bool condition = true;
|
|
|
|
void main() {
|
|
void f1(void Function() x, Object y) {
|
|
var z = condition ? x : y;
|
|
z.expectStaticType<Exactly<Object>>();
|
|
}
|
|
|
|
void f2(int x, void Function<X>() y) {
|
|
var z = condition ? x : y;
|
|
z.expectStaticType<Exactly<Object>>();
|
|
}
|
|
|
|
void f3(double Function(int, int) x, FutureOr<Function> y) {
|
|
var z = condition ? x : y;
|
|
z.expectStaticType<Exactly<Object>>();
|
|
}
|
|
|
|
void f4(FutureOr<Function?> x, Function(int i, {int j}) y) {
|
|
var z = condition ? x : y;
|
|
// Expecting `Object?`. Check that the type is a top type.
|
|
z.expectStaticType<Exactly<Object?>>();
|
|
// Check that it is `Object?`.
|
|
if (z == null) throw 0;
|
|
z.expectStaticType<Exactly<Object>>();
|
|
}
|
|
|
|
void f5(Function Function<Y>([Y y]) x, dynamic y) {
|
|
var z = condition ? x : y;
|
|
// Check that the type of `z` is `dynamic`.
|
|
Never n = z; // It is `dynamic` or `Never`.
|
|
z = 0; // It is a supertype of `int`.
|
|
z = false; // It is a supertype of `bool`.
|
|
}
|
|
|
|
void f6(Never x, Never Function() y) {
|
|
var z = condition ? x : y;
|
|
z.expectStaticType<Exactly<Never Function()>>();
|
|
}
|
|
|
|
void f7(Function(Function) x, Null y) {
|
|
var z = condition ? x : y;
|
|
z.expectStaticType<Exactly<Function(Function)?>>();
|
|
}
|
|
}
|