Files
sdk/tests/language_2/closure/nested_generic_closure_test.dart
T
Robert Nystrom fc1b1ecc71 Move files under language_2 into subdirectories.
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>
2019-12-11 19:18:00 +00:00

50 lines
1.2 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';
void foo(F f<F>(F f)) {}
B bar<B>(B g<F>(F f)) => null;
Function baz<B>() {
B foo<F>(B b, F f) => null;
return foo;
}
class C<T> {
void foo(F f<F>(T t, F f)) => null;
B bar<B>(B g<F>(T t, F f)) => null;
Function baz<B>() {
B foo<F>(T t, F f) => null;
return foo;
}
}
main() {
// Check the run-time type of the functions with generic parameters.
Expect.type<void Function(X Function<X>(X))>(foo);
Expect.isTrue(bar is X1 Function<X1>(X1 Function<X2>(X2)));
Expect.isTrue(baz<int>() is int Function<X1>(int, X1));
Expect.isTrue(baz<Object>() is Object Function<X1>(Object, X1));
Expect.isTrue(baz<Null>() is Null Function<X1>(Null, X1));
void testC<T>() {
var c = new C<T>();
Expect.type<void Function(F Function<F>(T, F))>(c.foo);
Expect.isTrue(c.bar is X1 Function<X1>(X1 Function<X2>(T, X2)));
Expect.isTrue(c.baz<int>() is int Function<X1>(T, X1));
}
testC<bool>();
testC<Object>();
testC<Null>();
}