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

Unified Diff: test/checker/inferred_type_test.dart

Issue 1317933005: Some preliminary support for quasi-generics (Closed) Base URL: https://github.com/dart-lang/dev_compiler.git@master
Patch Set: Reformat Created 5 years, 4 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
Index: test/checker/inferred_type_test.dart
diff --git a/test/checker/inferred_type_test.dart b/test/checker/inferred_type_test.dart
index edf73a3fa270c10b433c165bdc6e8cc3987234c7..59c90e6979e19f796384598692022b021d797023 100644
--- a/test/checker/inferred_type_test.dart
+++ b/test/checker/inferred_type_test.dart
@@ -1596,4 +1596,56 @@ void main() {
Foo([this.x = /*severe:StaticTypeError*/"1"]);
}'''
});
+
+ group('quasi-generics', () {
+ testChecker('dart:math min/max', {
+ '/main.dart': '''
+ import 'dart:math';
+
+ void printInt(int x) => print(x);
+ void printDouble(double x) => print(x);
+
+ num myMax(num x, num y) => max(x, y);
+
+ main() {
+ // Okay if static types match.
+ printInt(max(1, 2));
+ printInt(min(1, 2));
+ printDouble(max(1.0, 2.0));
+ printDouble(min(1.0, 2.0));
+
+ // No help for user-defined functions from num->num->num.
+ printInt(/*info:DownCastImplicit*/myMax(1, 2));
+ printInt(myMax(1, 2) as int);
+
+ // Mixing int and double means return type is num.
+ printInt(/*info:DownCastImplicit*/max(1, 2.0));
+ printInt(/*info:DownCastImplicit*/min(1, 2.0));
+ printDouble(/*info:DownCastImplicit*/max(1, 2.0));
+ printDouble(/*info:DownCastImplicit*/min(1, 2.0));
+
+ // Types other than int and double are not accepted.
+ printInt(
+ /*info:DownCastImplicit*/min(
+ /*severe:StaticTypeError*/"hi",
+ /*severe:StaticTypeError*/"there"));
+ }
+ '''
+ });
+
+ testChecker('Iterable and Future', {
+ '/main.dart': '''
+ import 'dart:async';
+
+ Future<int> make(int x) => (/*info:InferredTypeAllocation*/new Future(() => x));
+
+ main() {
+ Iterable<Future<int>> list = <int>[1, 2, 3].map(make);
+ Future<List<int>> results = Future.wait(list);
+ Future<String> results2 = results.then((List<int> list)
+ => list.fold('', (String x, int y) => x + y.toString()));
+ }
+ '''
+ });
+ });
}

Powered by Google App Engine
This is Rietveld 408576698