dart-sdk/tests/language/function_subtype/regress41680_strong_test.dart
Nicholas Shahan 3da1591253 [ddc] Fix function type casts in weak mode
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>
2020-04-28 21:19:54 +00:00

27 lines
882 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-strong
import "package:expect/expect.dart";
typedef dynamicToDynamic = dynamic Function(dynamic);
typedef voidToT = T Function<T>();
dynamic dynamicNull = null;
cast<T>(dynamic value) => value as T;
bool allowsArgument(T Function<T>() fn) => true;
main() {
// In strong mode Null is not a subtype of function types.
Expect.throwsTypeError(() => dynamicNull as Function);
Expect.throwsTypeError(() => dynamicNull as dynamicToDynamic);
Expect.throwsTypeError(() => cast<dynamic Function(dynamic)>(dynamicNull));
Expect.throwsTypeError(() => dynamicNull as voidToT);
Expect.throwsTypeError(() => allowsArgument(dynamicNull));
}