OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 // Tests related to the [TypeSystem] class. | 5 // Tests related to the [TypeSystem] class. |
6 | 6 |
7 library analyzer.test.generated.type_system_test; | 7 library analyzer.test.generated.type_system_test; |
8 | 8 |
9 import 'package:analyzer/dart/element/element.dart'; | 9 import 'package:analyzer/dart/element/element.dart'; |
10 import 'package:analyzer/dart/element/type.dart'; | 10 import 'package:analyzer/dart/element/type.dart'; |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 FunctionType expected = _functionType([], optional: [objectType, numType]); | 157 FunctionType expected = _functionType([], optional: [objectType, numType]); |
158 _checkLeastUpperBound(type1, type2, expected); | 158 _checkLeastUpperBound(type1, type2, expected); |
159 } | 159 } |
160 | 160 |
161 void test_functionsLubRequiredParams() { | 161 void test_functionsLubRequiredParams() { |
162 FunctionType type1 = _functionType([stringType, intType, intType]); | 162 FunctionType type1 = _functionType([stringType, intType, intType]); |
163 FunctionType type2 = _functionType([intType, doubleType, numType]); | 163 FunctionType type2 = _functionType([intType, doubleType, numType]); |
164 FunctionType expected = _functionType([objectType, numType, numType]); | 164 FunctionType expected = _functionType([objectType, numType, numType]); |
165 _checkLeastUpperBound(type1, type2, expected); | 165 _checkLeastUpperBound(type1, type2, expected); |
166 } | 166 } |
167 | |
168 void test_nestedNestedFunctionsLubInnermostParamTypes() { | 167 void test_nestedNestedFunctionsLubInnermostParamTypes() { |
169 FunctionType type1 = _functionType([ | 168 FunctionType type1 = _functionType([ |
170 _functionType([ | 169 _functionType([ |
171 _functionType([stringType, intType, intType]) | 170 _functionType([stringType, intType, intType]) |
172 ]) | 171 ]) |
173 ]); | 172 ]); |
174 FunctionType type2 = _functionType([ | 173 FunctionType type2 = _functionType([ |
175 _functionType([ | 174 _functionType([ |
176 _functionType([intType, doubleType, numType]) | 175 _functionType([intType, doubleType, numType]) |
177 ]) | 176 ]) |
(...skipping 957 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1135 } | 1134 } |
1136 | 1135 |
1137 void test_functionsDifferentRequiredArityBecomeOptional() { | 1136 void test_functionsDifferentRequiredArityBecomeOptional() { |
1138 FunctionType type1 = _functionType([intType]); | 1137 FunctionType type1 = _functionType([intType]); |
1139 FunctionType type2 = _functionType([intType, intType, intType]); | 1138 FunctionType type2 = _functionType([intType, intType, intType]); |
1140 FunctionType expected = | 1139 FunctionType expected = |
1141 _functionType([intType], optional: [intType, intType]); | 1140 _functionType([intType], optional: [intType, intType]); |
1142 _checkGreatestLowerBound(type1, type2, expected); | 1141 _checkGreatestLowerBound(type1, type2, expected); |
1143 } | 1142 } |
1144 | 1143 |
| 1144 void test_functionsFuzzyArrows() { |
| 1145 FunctionType type1 = _functionType([dynamicType]); |
| 1146 FunctionType type2 = _functionType([intType]); |
| 1147 FunctionType expected = _functionType([intType]); |
| 1148 _checkGreatestLowerBound(type1, type2, expected); |
| 1149 } |
| 1150 |
1145 void test_functionsGlbReturnType() { | 1151 void test_functionsGlbReturnType() { |
1146 FunctionType type1 = _functionType([], returns: intType); | 1152 FunctionType type1 = _functionType([], returns: intType); |
1147 FunctionType type2 = _functionType([], returns: numType); | 1153 FunctionType type2 = _functionType([], returns: numType); |
1148 FunctionType expected = _functionType([], returns: intType); | 1154 FunctionType expected = _functionType([], returns: intType); |
1149 _checkGreatestLowerBound(type1, type2, expected); | 1155 _checkGreatestLowerBound(type1, type2, expected); |
1150 } | 1156 } |
1151 | 1157 |
1152 void test_functionsLubNamedParams() { | 1158 void test_functionsLubNamedParams() { |
1153 FunctionType type1 = | 1159 FunctionType type1 = |
1154 _functionType([], named: {'a': stringType, 'b': intType}); | 1160 _functionType([], named: {'a': stringType, 'b': intType}); |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1304 * In particular, function parameters are compared using LUB in spec mode, but | 1310 * In particular, function parameters are compared using LUB in spec mode, but |
1305 * GLB in strong mode. | 1311 * GLB in strong mode. |
1306 */ | 1312 */ |
1307 @reflectiveTest | 1313 @reflectiveTest |
1308 class StrongLeastUpperBoundTest extends LeastUpperBoundTestBase { | 1314 class StrongLeastUpperBoundTest extends LeastUpperBoundTestBase { |
1309 void setUp() { | 1315 void setUp() { |
1310 typeSystem = new StrongTypeSystemImpl(); | 1316 typeSystem = new StrongTypeSystemImpl(); |
1311 super.setUp(); | 1317 super.setUp(); |
1312 } | 1318 } |
1313 | 1319 |
| 1320 void test_functionsFuzzyArrows() { |
| 1321 FunctionType type1 = _functionType([dynamicType]); |
| 1322 FunctionType type2 = _functionType([intType]); |
| 1323 FunctionType expected = _functionType([dynamicType]); |
| 1324 _checkLeastUpperBound(type1, type2, expected); |
| 1325 } |
| 1326 |
1314 void test_functionsGlbNamedParams() { | 1327 void test_functionsGlbNamedParams() { |
1315 FunctionType type1 = | 1328 FunctionType type1 = |
1316 _functionType([], named: {'a': stringType, 'b': intType}); | 1329 _functionType([], named: {'a': stringType, 'b': intType}); |
1317 FunctionType type2 = _functionType([], named: {'a': intType, 'b': numType}); | 1330 FunctionType type2 = _functionType([], named: {'a': intType, 'b': numType}); |
1318 FunctionType expected = | 1331 FunctionType expected = |
1319 _functionType([], named: {'a': bottomType, 'b': intType}); | 1332 _functionType([], named: {'a': bottomType, 'b': intType}); |
1320 _checkLeastUpperBound(type1, type2, expected); | 1333 _checkLeastUpperBound(type1, type2, expected); |
1321 } | 1334 } |
1322 | 1335 |
1323 void test_functionsGlbPositionalParams() { | 1336 void test_functionsGlbPositionalParams() { |
(...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1789 if (types != null) { | 1802 if (types != null) { |
1790 f.typeParameters = | 1803 f.typeParameters = |
1791 new List<TypeParameterElement>.from(types.map((t) => t.element)); | 1804 new List<TypeParameterElement>.from(types.map((t) => t.element)); |
1792 } | 1805 } |
1793 return f.type = new FunctionTypeImpl(f); | 1806 return f.type = new FunctionTypeImpl(f); |
1794 } | 1807 } |
1795 | 1808 |
1796 static TypeParameterType variable(String name, {DartType bound}) => | 1809 static TypeParameterType variable(String name, {DartType bound}) => |
1797 ElementFactory.typeParameterWithType(name, bound).type; | 1810 ElementFactory.typeParameterWithType(name, bound).type; |
1798 } | 1811 } |
OLD | NEW |