mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 00:19:48 +00:00
3da1591253
Allow null to be cast as function types in weak mode. Change-Id: I42084250c428b7e6a18ce343305d43603b4e1ec4 Fixes: https://github.com/dart-lang/sdk/issues/41680 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/144995 Commit-Queue: Nicholas Shahan <nshahan@google.com> Reviewed-by: Sigmund Cherem <sigmund@google.com> Reviewed-by: Mark Zhou <markzipan@google.com>
27 lines
855 B
Dart
27 lines
855 B
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.
|
|
|
|
// Requirements=nnbd-weak
|
|
|
|
import "package:expect/expect.dart";
|
|
|
|
typedef dynamicToDynamic = dynamic Function(dynamic);
|
|
|
|
typedef voidToT = T Function<T>();
|
|
|
|
dynamic dynamicNull = null;
|
|
|
|
dynamic cast<T>(dynamic value) => value as T;
|
|
|
|
bool allowsArgument(T Function<T>() fn) => true;
|
|
|
|
main() {
|
|
// In weak mode Null should be allowed as a subtype of function types.
|
|
Expect.equals(null, dynamicNull as Function);
|
|
Expect.equals(null, dynamicNull as dynamicToDynamic);
|
|
Expect.equals(null, cast<dynamic Function(dynamic)>(dynamicNull));
|
|
Expect.equals(null, dynamicNull as voidToT);
|
|
Expect.equals(true, allowsArgument(dynamicNull));
|
|
}
|