Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(14)

Unified Diff: tests/language_strong/generic_function_dcall_test.dart

Issue 2833203002: add a test for #28079, dynamic calls to generic functions and other RTTI (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/language_strong/generic_function_dcall_test.dart
diff --git a/tests/language_strong/generic_function_dcall_test.dart b/tests/language_strong/generic_function_dcall_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..a0e7175ae47742e381a78252d7c3fa8a2d7c129e
--- /dev/null
+++ b/tests/language_strong/generic_function_dcall_test.dart
@@ -0,0 +1,59 @@
+// 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 testCallsToGenericFn() {
+ T f<T>(T a, T b) => ((a as dynamic) + b) as T;
+
+ var x = (f as dynamic)<int>(40, 2);
+ Expect.equals(x, 42);
+
+ var y = (f as dynamic)<String>('hi', '!');
+ Expect.equals(y, 'hi!');
+
+ var dd2d = (x, y) => x;
+ dd2d = f; // implicit <dynamic>
+ x = (dd2d as dynamic)(40, 2);
+ Expect.equals(x, 42);
+ y = (dd2d as dynamic)('hi', '!');
+ Expect.equals(y, 'hi!');
+}
+
+void testGenericFnAsArg() {
+ h<T>(a) => a as T;
+ Object foo(f(Object a), Object a) => f(a);
+ Expect.throws(() => foo(h as dynamic, 42));
+
+ var int2int = (int x) => x;
+ T bar<T>(x) => x as T;
+ dynamic list = <Object>[1, 2, 3];
+ Expect.throws(() => list.map(bar));
+ int2int = bar;
+ Expect.listEquals(list.map(int2int).toList(), [1, 2, 3]);
+}
+
+typedef T2T = T Function<T>(T t);
+void testGenericFnAsGenericFnArg() {
+ h<T>(a) => a as T;
+ S foo<S>(T2T f, S a) => f<S>(a);
+ Expect.equals(foo<int>(h, 42), 42);
+ Expect.equals(foo<dynamic>(h, 42), 42);
+ Expect.equals(foo<int>(h as dynamic, 42), 42);
+ Expect.equals(foo<dynamic>(h as dynamic, 42), 42);
+}
+
+void testGenericFnTypeToString() {
+ T f<T>(T a) => a;
+ // TODO(jmesserly): other Dart implementations use `=>` arrow, so we may need
+ // to change this in DDC at some point.
+ Expect.equals(f.runtimeType.toString(), "<T>(T) -> T");
+}
+
+main() {
+ testCallsToGenericFn();
+ testGenericFnAsArg();
+ testGenericFnAsGenericFnArg();
+ testGenericFnTypeToString();
+}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698