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

Unified Diff: pkg/analyzer/test/src/task/strong/inferred_type_test.dart

Issue 1720433002: fixes #25477, downward inference of generic methods (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 10 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: pkg/analyzer/test/src/task/strong/inferred_type_test.dart
diff --git a/pkg/analyzer/test/src/task/strong/inferred_type_test.dart b/pkg/analyzer/test/src/task/strong/inferred_type_test.dart
index 85a1085bef0fc6b253a86b6854b5c9315a60e496..ba964d8ea0c40f9464f4f79f545e50cc548e612c 100644
--- a/pkg/analyzer/test/src/task/strong/inferred_type_test.dart
+++ b/pkg/analyzer/test/src/task/strong/inferred_type_test.dart
@@ -1695,7 +1695,7 @@ 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()));
+ => list.fold('', /*info:INFERRED_TYPE_CLOSURE*/(x, y) => x + y.toString()));
}
''');
});
@@ -1838,7 +1838,7 @@ main() {
test('correctly recognize generic upper bound', () {
// Regression test for https://github.com/dart-lang/sdk/issues/25740.
- checkFile('''
+ checkFile(r'''
class Foo<T extends Pattern> {
void method/*<U extends T>*/(dynamic/*=U*/ u) {}
}
@@ -1853,11 +1853,52 @@ main() {
}
''');
});
+
+ test('basic downwards inference', () {
+ checkFile(r'''
+/*=T*/ f/*<S, T>*/(/*=S*/ s) => null;
+main() {
+ String x = f(42);
+ String y = (f)(42);
+}
+ ''');
+ });
+
+ test('downwards inference affects arguments', () {
+ checkFile(r'''
+/*=T*/ f/*<T>*/(List/*<T>*/ s) => null;
+main() {
+ String x = f(/*info:INFERRED_TYPE_LITERAL*/['hi']);
+ String y = f(/*info:INFERRED_TYPE_LITERAL*/[/*severe:STATIC_TYPE_ERROR*/42]);
+}
+ ''');
+ });
+
+ test('downwards inference fold', () {
+ // Regression from https://github.com/dart-lang/sdk/issues/25491
+ // The first example works now, but the latter requires a full solution to
+ // https://github.com/dart-lang/sdk/issues/25490
+ checkFile(r'''
+void main() {
+ List<int> o;
+ int y = o.fold(0, /*info:INFERRED_TYPE_CLOSURE*/(x, y) => x + y);
+ var z = o.fold(0, /*info:INFERRED_TYPE_CLOSURE*/(x, y) => /*info:DYNAMIC_INVOKE*/x + y);
+ y = /*info:DYNAMIC_CAST*/z;
+}
+void functionExpressionInvocation() {
+ List<int> o;
+ int y = (o.fold)(0, /*info:INFERRED_TYPE_CLOSURE*/(x, y) => x + y);
+ var z = (o.fold)(0, /*info:INFERRED_TYPE_CLOSURE*/(x, y) => /*info:DYNAMIC_INVOKE*/x + y);
+ y = /*info:DYNAMIC_CAST*/z;
+}
+ ''');
+ });
+
});
// Regression test for https://github.com/dart-lang/dev_compiler/issues/47
test('null literal should not infer as bottom', () {
- checkFile('''
+ checkFile(r'''
var h = null;
void foo(int f(Object _)) {}
« pkg/analyzer/lib/dart/ast/ast.dart ('K') | « pkg/analyzer/test/src/task/strong/checker_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698