mirror of
https://github.com/dart-lang/sdk
synced 2024-10-14 12:30:03 +00:00
fc1b1ecc71
Change-Id: Idbcc965a27e9ffeedf5e0a1068b019de4193070f Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/127745 Commit-Queue: Bob Nystrom <rnystrom@google.com> Reviewed-by: Alexander Thomas <athom@google.com>
66 lines
1.9 KiB
Dart
66 lines
1.9 KiB
Dart
// Copyright (c) 2017, 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.
|
|
|
|
import "package:expect/expect.dart";
|
|
|
|
T f<T>(T x) => x;
|
|
|
|
int intToInt(int x) => x;
|
|
String stringToString(String x) => x;
|
|
String stringAndIntToString(String x, int y) => x;
|
|
|
|
test(intFuncDynamic, stringFuncDynamic, dynamicFuncDynamic) {
|
|
Expect.isTrue(intFuncDynamic is int Function(int));
|
|
Expect.isFalse(intFuncDynamic is String Function(String));
|
|
Expect.equals(intFuncDynamic(1), 1);
|
|
Expect.equals("${intFuncDynamic.runtimeType}", "${intToInt.runtimeType}");
|
|
Expect.throwsTypeError(() {
|
|
intFuncDynamic('oops');
|
|
});
|
|
Expect.throwsNoSuchMethodError(() {
|
|
intFuncDynamic<String>('oops');
|
|
});
|
|
Expect.isTrue(stringFuncDynamic is String Function(String));
|
|
Expect.isFalse(stringFuncDynamic is int Function(int));
|
|
Expect.equals(stringFuncDynamic('hello'), 'hello');
|
|
Expect.equals(
|
|
"${stringFuncDynamic.runtimeType}", "${stringToString.runtimeType}");
|
|
Expect.throwsTypeError(() {
|
|
stringFuncDynamic(1);
|
|
});
|
|
Expect.throwsNoSuchMethodError(() {
|
|
stringFuncDynamic<int>(1);
|
|
});
|
|
Expect.throwsNoSuchMethodError(() {
|
|
dynamicFuncDynamic<int>(1);
|
|
});
|
|
}
|
|
|
|
main() {
|
|
int Function(int) if1 = f;
|
|
String Function(String) sf1 = f;
|
|
dynamic Function(dynamic) df1 = f;
|
|
test(if1, sf1, df1);
|
|
|
|
T local<T>(T x) => x;
|
|
|
|
int Function(int) if2 = local;
|
|
String Function(String) sf2 = local;
|
|
dynamic Function(dynamic) df2 = local;
|
|
test(if2, sf2, df2);
|
|
|
|
dynamic bar<X>() {
|
|
String foo<T>(X x, T t) {
|
|
return "$X, $T";
|
|
}
|
|
|
|
String Function(X, int) x = foo;
|
|
return x;
|
|
}
|
|
|
|
dynamic fn = bar<String>();
|
|
Expect.equals("${fn.runtimeType}", "${stringAndIntToString.runtimeType}");
|
|
Expect.equals(fn("a", 1), "String, int");
|
|
}
|