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

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

Issue 1644403005: fix #25619 - downward inference on generic function tear-offs (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 11 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 | « pkg/analyzer/lib/src/generated/type_system.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 58161c61ce7acc4ef53b7cf6c6b74eeb6ebf82d9..eccb4f28fc5079f4d3a8f3e4a597806aa535ab6e 100644
--- a/pkg/analyzer/test/src/task/strong/inferred_type_test.dart
+++ b/pkg/analyzer/test/src/task/strong/inferred_type_test.dart
@@ -1151,7 +1151,8 @@ main() {
''';
testChecker('infer downwards', {'/main.dart': code});
- testChecker('infer if value types match context', {'/main.dart': r'''
+ testChecker('infer if value types match context', {
+ '/main.dart': r'''
class DartType {}
typedef void Asserter<T>(T type);
typedef Asserter<T> AsserterBuilder<S, T>(S arg);
@@ -1206,7 +1207,8 @@ main() {
g.assertAOf(/*info:INFERRED_TYPE_LITERAL*/[_isInt, _isString]);
g.assertDOf(/*info:INFERRED_TYPE_LITERAL*/[_isInt, _isString]);
}
- '''});
+ '''
+ });
});
group('downwards inference on function arguments', () {
@@ -1578,47 +1580,116 @@ main() {
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)
+ Future<String> results2 = results.then((List<int> list)
=> list.fold('', (String x, int y) => x + y.toString()));
}
'''
});
- // Regression test for https://github.com/dart-lang/dev_compiler/issues/47
- testChecker('null literal should not infer as bottom', {
+ // TODO(jmesserly): we should change how this inference works.
+ // For now this test will cover what we use.
+ testChecker('infer JS builtin', {
'/main.dart': '''
- var h = null;
- void foo(int f(Object _)) {}
-
- main() {
- var f = (x) => null;
- f = (x) => 'hello';
+import 'dart:math' as math;
+import 'dart:math' show min;
- var g = null;
- g = 'hello';
- (/*info:DYNAMIC_INVOKE*/g.foo());
+class C {
+ /*=T*/ m/*<T extends num>*/(/*=T*/ x, /*=T*/ y) => null;
+}
- h = 'hello';
- (/*info:DYNAMIC_INVOKE*/h.foo());
+main() {
+ takeIII(math.max);
+ takeDDD(math.max);
+ takeNNN(math.max);
+ takeIDN(math.max);
+ takeDIN(math.max);
+ takeIIN(math.max);
+ takeDDN(math.max);
+ takeIIO(math.max);
+ takeDDO(math.max);
+
+ takeOOI(/*severe:STATIC_TYPE_ERROR*/math.max);
+ takeIDI(/*severe:STATIC_TYPE_ERROR*/math.max);
+ takeDID(/*severe:STATIC_TYPE_ERROR*/math.max);
+
+ takeOON(/*warning:DOWN_CAST_COMPOSITE*/math.max);
+ takeOOO(/*warning:DOWN_CAST_COMPOSITE*/math.max);
+
+ // Also test SimpleIdentifier
+ takeIII(min);
+ takeDDD(min);
+ takeNNN(min);
+ takeIDN(min);
+ takeDIN(min);
+ takeIIN(min);
+ takeDDN(min);
+ takeIIO(min);
+ takeDDO(min);
+
+ takeOOI(/*severe:STATIC_TYPE_ERROR*/min);
+ takeIDI(/*severe:STATIC_TYPE_ERROR*/min);
+ takeDID(/*severe:STATIC_TYPE_ERROR*/min);
+
+ takeOON(/*warning:DOWN_CAST_COMPOSITE*/min);
+ takeOOO(/*warning:DOWN_CAST_COMPOSITE*/min);
+
+ // Also PropertyAccess
+ takeIII(new C().m);
+ takeDDD(new C().m);
+ takeNNN(new C().m);
+ takeIDN(new C().m);
+ takeDIN(new C().m);
+ takeIIN(new C().m);
+ takeDDN(new C().m);
+ takeIIO(new C().m);
+ takeDDO(new C().m);
+
+ takeOOI(/*severe:STATIC_TYPE_ERROR*/new C().m);
+ takeIDI(/*severe:STATIC_TYPE_ERROR*/new C().m);
+ takeDID(/*severe:STATIC_TYPE_ERROR*/new C().m);
+
+ takeOON(/*warning:DOWN_CAST_COMPOSITE*/new C().m);
+ takeOOO(/*warning:DOWN_CAST_COMPOSITE*/new C().m);
+}
- foo(/*info:INFERRED_TYPE_CLOSURE,info:INFERRED_TYPE_CLOSURE*/(x) => null);
- foo(/*info:INFERRED_TYPE_CLOSURE,info:INFERRED_TYPE_CLOSURE*/(x) => throw "not implemented");
- }
- '''
+void takeIII(int fn(int a, int b)) {}
+void takeDDD(double fn(double a, double b)) {}
+void takeIDI(int fn(double a, int b)) {}
+void takeDID(double fn(int a, double b)) {}
+void takeIDN(num fn(double a, int b)) {}
+void takeDIN(num fn(int a, double b)) {}
+void takeIIN(num fn(int a, int b)) {}
+void takeDDN(num fn(double a, double b)) {}
+void takeNNN(num fn(num a, num b)) {}
+void takeOON(num fn(Object a, Object b)) {}
+void takeOOO(num fn(Object a, Object b)) {}
+void takeOOI(int fn(Object a, Object b)) {}
+void takeIIO(Object fn(int a, int b)) {}
+void takeDDO(Object fn(double a, double b)) {}
+ '''
});
+ });
- // TODO(jmesserly): we should change how this inference works.
- // For now this test will cover what we use.
- testChecker('infer JS builtin', {
- '/main.dart': '''
- import 'dart:_foreign_helper' show JS;
- main() {
- String x = /*severe:STATIC_TYPE_ERROR*/JS('int', '42');
- var y = JS('String', '"hello"');
- y = "world";
- y = /*severe:STATIC_TYPE_ERROR*/42;
- }
- '''
- });
+ // Regression test for https://github.com/dart-lang/dev_compiler/issues/47
+ testChecker('null literal should not infer as bottom', {
+ '/main.dart': '''
+ var h = null;
+ void foo(int f(Object _)) {}
+
+ main() {
+ var f = (x) => null;
+ f = (x) => 'hello';
+
+ var g = null;
+ g = 'hello';
+ (/*info:DYNAMIC_INVOKE*/g.foo());
+
+ h = 'hello';
+ (/*info:DYNAMIC_INVOKE*/h.foo());
+
+ foo(/*info:INFERRED_TYPE_CLOSURE,info:INFERRED_TYPE_CLOSURE*/(x) => null);
+ foo(/*info:INFERRED_TYPE_CLOSURE,info:INFERRED_TYPE_CLOSURE*/(x) => throw "not implemented");
+ }
+ '''
});
}
« no previous file with comments | « pkg/analyzer/lib/src/generated/type_system.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698