Chromium Code Reviews| Index: tests/language_2/generic_closure_test.dart |
| diff --git a/tests/language_2/generic_closure_test.dart b/tests/language_2/generic_closure_test.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..febdefba6ecbd1808967a41c561789a63846c467 |
| --- /dev/null |
| +++ b/tests/language_2/generic_closure_test.dart |
| @@ -0,0 +1,68 @@ |
| +// Copyright (c) 2014, 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 that generic closures are properly instantiated. |
| + |
| +import 'package:expect/expect.dart'; |
| + |
| +typedef T F<T>(T x); |
| +typedef R G<T, R>(T x); |
| + |
| +class C<T> { |
| + get f => (T x) => x; |
| + T g(T x) => x; |
| +} |
| + |
| +main() { |
| + { |
| + var c = new C<int>(); |
| + var f = c.f; |
| + var g = c.g; |
| + Expect.equals("(int) => int", f.runtimeType.toString()); //# 01: ok |
|
Jennifer Messerly
2017/08/25 21:59:47
FYI, I filed https://github.com/dart-lang/sdk/issu
jcollins
2017/08/29 15:41:06
I slightly prefer the VM since it (at a limited gl
|
| + Expect.equals("(int) => int", g.runtimeType.toString()); //# 01: ok |
|
Jennifer Messerly
2017/08/25 21:59:47
this should be (Object) -> int
because of covaria
jcollins
2017/08/29 15:41:05
Done.
|
| + Expect.equals(21, f(21)); |
| + Expect.equals(14, g(14)); |
| + Expect.isTrue(f is Function); |
| + Expect.isTrue(g is Function); |
| + Expect.isTrue(f is F); |
| + Expect.isTrue(g is F); |
| + Expect.isTrue(f is F<int>); |
| + Expect.isTrue(g is F<int>); |
| + Expect.isTrue(f is! F<bool>); |
| + Expect.isTrue(g is! F<bool>); |
| + Expect.isTrue(f is G<int, int>); |
| + Expect.isTrue(g is G<int, int>); |
| + Expect.isTrue(f is! G<int, bool>); |
| + Expect.isTrue(g is! G<int, bool>); |
|
Jennifer Messerly
2017/08/25 21:59:48
could we add these two tests, to illustrate the di
jcollins
2017/08/29 15:41:05
Done.
|
| + } |
| + |
| + { |
| + var c = new C<bool>(); |
| + var f = c.f; |
| + var g = c.g; |
| + Expect.equals("(bool) => bool", f.runtimeType.toString()); //# 01: ok |
| + Expect.equals("(bool) => bool", g.runtimeType.toString()); //# 01: ok |
|
Jennifer Messerly
2017/08/25 21:59:48
this should be `(Object) -> bool`
jcollins
2017/08/29 15:41:05
Done.
|
| + Expect.isTrue(f is F); |
| + Expect.isTrue(g is F); |
| + Expect.isTrue(f is! F<int>); |
| + Expect.isTrue(g is! F<int>); |
| + Expect.isTrue(f is F<bool>); |
| + Expect.isTrue(g is F<bool>); |
| + } |
| + |
| + { |
| + var c = new C(); |
| + var f = c.f; |
| + var g = c.g; |
| + Expect.equals("(dynamic) => dynamic", f.runtimeType.toString()); //# 01: ok |
| + Expect.equals("(dynamic) => dynamic", g.runtimeType.toString()); //# 01: ok |
|
Jennifer Messerly
2017/08/25 21:59:48
this should be `(Object) -> dynamic`
jcollins
2017/08/29 15:41:05
Done.
|
| + Expect.isTrue(f is F); |
| + Expect.isTrue(g is F); |
| + Expect.isTrue(f is! F<int>); |
| + Expect.isTrue(g is! F<int>); |
| + Expect.isTrue(f is! F<bool>); |
| + Expect.isTrue(g is! F<bool>); |
| + } |
| +} |