dart-sdk/tests/language/function_subtype/local2_test.dart
Erik Ernst 3a7eeb6315 Rename is{Strong,Weak}Mode to has{Sound,Unsound}NullSafety
Change-Id: If3912d75c5f89a741299b2fae4299d01ac928eec
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/170424
Reviewed-by: Lasse R.H. Nielsen <lrn@google.com>
Reviewed-by: Michael Thomsen <mit@google.com>
Reviewed-by: Mayank Patke <fishythefish@google.com>
Commit-Queue: Erik Ernst <eernst@google.com>
2020-11-05 14:26:53 +00:00

44 lines
1.6 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.
// Dart test program for constructors and initializers.
// Check function subtyping for local functions on generic type against generic
// typedefs.
import 'package:expect/expect.dart';
typedef int Foo<T>(T a, [String b]);
typedef int Bar<T>(T a, [String b]);
typedef int Baz<T>(T a, {String b});
typedef int Boz<T>(T a);
typedef int Biz<T>(T a, int b);
class C<T> {
void test(String nameOfT, bool expectedResult) {
int foo(bool a, [String b = '']) => -1;
int baz(bool a, {String b = ''}) => -1;
Expect.equals(expectedResult, foo is Foo<T>, 'foo is Foo<$nameOfT>');
Expect.equals(expectedResult, foo is Bar<T>, 'foo is Bar<$nameOfT>');
Expect.isFalse(foo is Baz<T>, 'foo is Baz<$nameOfT>');
Expect.equals(expectedResult, foo is Boz<T>, 'foo is Boz<$nameOfT>');
Expect.isFalse(foo is Biz<T>, 'foo is Biz<$nameOfT>');
Expect.isFalse(baz is Foo<T>, 'baz is Foo<$nameOfT>');
Expect.isFalse(baz is Bar<T>, 'baz is Bar<$nameOfT>');
Expect.equals(expectedResult, baz is Baz<T>, 'baz is Baz<$nameOfT>');
Expect.equals(expectedResult, baz is Boz<T>, 'baz is Boz<$nameOfT>');
Expect.isFalse(baz is Biz<T>, 'bar is Biz<$nameOfT>');
}
}
main() {
new C<bool>().test('bool', true);
new C<int>().test('int', false);
new C<dynamic>().test('dynamic', false);
new C<Object>().test('Object', false);
new C<Null>().test('Null', hasUnsoundNullSafety);
new C<Never>().test('Never', true);
}