OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library analyzer.test.generated.strong_mode_test; | 5 library analyzer.test.generated.strong_mode_test; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 | 8 |
9 import 'package:analyzer/dart/ast/ast.dart'; | 9 import 'package:analyzer/dart/ast/ast.dart'; |
10 import 'package:analyzer/dart/ast/standard_resolution_map.dart'; | 10 import 'package:analyzer/dart/ast/standard_resolution_map.dart'; |
(...skipping 1056 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1067 MethodInvocation invoke = await _testFutureOr(r''' | 1067 MethodInvocation invoke = await _testFutureOr(r''' |
1068 FutureOr<T> mk<T>(Future<T> x) => x; | 1068 FutureOr<T> mk<T>(Future<T> x) => x; |
1069 Future<int> f; | 1069 Future<int> f; |
1070 test() => f.then<Null>((int x) { return null;}); | 1070 test() => f.then<Null>((int x) { return null;}); |
1071 '''); | 1071 '''); |
1072 _isFunction2Of(_isInt, _isNull)( | 1072 _isFunction2Of(_isInt, _isNull)( |
1073 invoke.argumentList.arguments[0].staticType); | 1073 invoke.argumentList.arguments[0].staticType); |
1074 _isFutureOfNull(invoke.staticType); | 1074 _isFutureOfNull(invoke.staticType); |
1075 } | 1075 } |
1076 | 1076 |
| 1077 test_generic_partial() async { |
| 1078 // Test that upward and downward type inference handles partial |
| 1079 // type schemas correctly. Downwards inference in a partial context |
| 1080 // (e.g. Map<String, ?>) should still allow upwards inference to fill |
| 1081 // in the missing information. |
| 1082 String code = r''' |
| 1083 class A<T> { |
| 1084 A(T x); |
| 1085 A.fromA(A<T> a) {} |
| 1086 A.fromMap(Map<String, T> m) {} |
| 1087 A.fromList(List<T> m) {} |
| 1088 A.fromT(T t) {} |
| 1089 A.fromB(B<T, String> a) {} |
| 1090 } |
| 1091 |
| 1092 class B<S, T> { |
| 1093 B(S s); |
| 1094 } |
| 1095 |
| 1096 void test() { |
| 1097 var a0 = new A.fromA(new A(3)); |
| 1098 var a1 = new A.fromMap({'hello' : 3}); |
| 1099 var a2 = new A.fromList([3]); |
| 1100 var a3 = new A.fromT(3); |
| 1101 var a4 = new A.fromB(new B(3)); |
| 1102 } |
| 1103 '''; |
| 1104 CompilationUnit unit = await resolveSource(code); |
| 1105 Element elementA = AstFinder.getClass(unit, "A").element; |
| 1106 List<Statement> statements = |
| 1107 AstFinder.getStatementsInTopLevelFunction(unit, "test"); |
| 1108 DartType check(int i) { |
| 1109 VariableDeclarationStatement stmt = statements[i]; |
| 1110 VariableDeclaration decl = stmt.variables.variables[0]; |
| 1111 Expression init = decl.initializer; |
| 1112 _isInstantiationOf(_hasElement(elementA))([_isInt])(init.staticType); |
| 1113 } |
| 1114 |
| 1115 for (var i = 0; i < 5; i++) check(i); |
| 1116 } |
| 1117 |
1077 test_inferConstructor_unknownTypeLowerBound() async { | 1118 test_inferConstructor_unknownTypeLowerBound() async { |
1078 Source source = addSource(r''' | 1119 Source source = addSource(r''' |
1079 class C<T> { | 1120 class C<T> { |
1080 C(void callback(List<T> a)); | 1121 C(void callback(List<T> a)); |
1081 } | 1122 } |
1082 test() { | 1123 test() { |
1083 // downwards inference pushes List<?> and in parameter position this | 1124 // downwards inference pushes List<?> and in parameter position this |
1084 // becomes inferred as List<Null>. | 1125 // becomes inferred as List<Null>. |
1085 var c = new C((items) {}); | 1126 var c = new C((items) {}); |
1086 } | 1127 } |
(...skipping 2769 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3856 var v = x; | 3897 var v = x; |
3857 v; // marker | 3898 v; // marker |
3858 } | 3899 } |
3859 int x = 3; | 3900 int x = 3; |
3860 '''; | 3901 '''; |
3861 CompilationUnit unit = await resolveSource(code); | 3902 CompilationUnit unit = await resolveSource(code); |
3862 assertPropagatedAssignedType(code, unit, typeProvider.intType, null); | 3903 assertPropagatedAssignedType(code, unit, typeProvider.intType, null); |
3863 assertTypeOfMarkedExpression(code, unit, typeProvider.intType, null); | 3904 assertTypeOfMarkedExpression(code, unit, typeProvider.intType, null); |
3864 } | 3905 } |
3865 } | 3906 } |
OLD | NEW |