OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 engine.resolver.error_verifier; | 5 library engine.resolver.error_verifier; |
6 | 6 |
7 import 'dart:collection'; | 7 import 'dart:collection'; |
8 import "dart:math" as math; | 8 import "dart:math" as math; |
9 | 9 |
10 import 'package:analyzer/src/generated/static_type_analyzer.dart'; | 10 import 'package:analyzer/src/generated/static_type_analyzer.dart'; |
(...skipping 1329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1340 String executableElementName = executableElement.name; | 1340 String executableElementName = executableElement.name; |
1341 FunctionType overridingFT = executableElement.type; | 1341 FunctionType overridingFT = executableElement.type; |
1342 FunctionType overriddenFT = overriddenExecutable.type; | 1342 FunctionType overriddenFT = overriddenExecutable.type; |
1343 InterfaceType enclosingType = _enclosingClass.type; | 1343 InterfaceType enclosingType = _enclosingClass.type; |
1344 overriddenFT = _inheritanceManager | 1344 overriddenFT = _inheritanceManager |
1345 .substituteTypeArgumentsInMemberFromInheritance( | 1345 .substituteTypeArgumentsInMemberFromInheritance( |
1346 overriddenFT, executableElementName, enclosingType); | 1346 overriddenFT, executableElementName, enclosingType); |
1347 if (overridingFT == null || overriddenFT == null) { | 1347 if (overridingFT == null || overriddenFT == null) { |
1348 return false; | 1348 return false; |
1349 } | 1349 } |
| 1350 |
| 1351 // Handle generic function type parameters. |
| 1352 // TODO(jmesserly): this duplicates some code in isSubtypeOf and most of |
| 1353 // _isGenericFunctionSubtypeOf. Ideally, we'd let TypeSystem produce |
| 1354 // an error message once it's ready to "return false". |
| 1355 if (!overridingFT.boundTypeParameters.isEmpty) { |
| 1356 if (overriddenFT.boundTypeParameters.isEmpty) { |
| 1357 overriddenFT = _typeSystem.instantiateToBounds(overriddenFT); |
| 1358 } else { |
| 1359 List<TypeParameterElement> params1 = overridingFT.boundTypeParameters; |
| 1360 List<TypeParameterElement> params2 = overriddenFT.boundTypeParameters; |
| 1361 int count = params1.length; |
| 1362 if (params2.length != count) { |
| 1363 _errorReporter.reportErrorForNode( |
| 1364 StaticWarningCode.INVALID_METHOD_OVERRIDE_TYPE_PARAMETERS, |
| 1365 errorNameTarget, [ |
| 1366 count, |
| 1367 params2.length, |
| 1368 overriddenExecutable.enclosingElement.displayName |
| 1369 ]); |
| 1370 return true; |
| 1371 } |
| 1372 // We build up a substitution matching up the type parameters |
| 1373 // from the two types, {variablesFresh/variables1} and |
| 1374 // {variablesFresh/variables2} |
| 1375 List<DartType> variables1 = new List<DartType>(); |
| 1376 List<DartType> variables2 = new List<DartType>(); |
| 1377 List<DartType> variablesFresh = new List<DartType>(); |
| 1378 for (int i = 0; i < count; i++) { |
| 1379 TypeParameterElement p1 = params1[i]; |
| 1380 TypeParameterElement p2 = params2[i]; |
| 1381 TypeParameterElementImpl pFresh = |
| 1382 new TypeParameterElementImpl(p1.name, -1); |
| 1383 |
| 1384 DartType variable1 = p1.type; |
| 1385 DartType variable2 = p2.type; |
| 1386 DartType variableFresh = new TypeParameterTypeImpl(pFresh); |
| 1387 |
| 1388 variables1.add(variable1); |
| 1389 variables2.add(variable2); |
| 1390 variablesFresh.add(variableFresh); |
| 1391 DartType bound1 = p1.bound ?? DynamicTypeImpl.instance; |
| 1392 DartType bound2 = p2.bound ?? DynamicTypeImpl.instance; |
| 1393 bound1 = bound1.substitute2(variablesFresh, variables1); |
| 1394 bound2 = bound2.substitute2(variablesFresh, variables2); |
| 1395 pFresh.bound = bound2; |
| 1396 if (!_typeSystem.isSubtypeOf(bound2, bound1)) { |
| 1397 _errorReporter.reportErrorForNode( |
| 1398 StaticWarningCode.INVALID_METHOD_OVERRIDE_TYPE_PARAMETER_BOUND, |
| 1399 errorNameTarget, [ |
| 1400 p1.displayName, |
| 1401 p1.bound, |
| 1402 p2.displayName, |
| 1403 p2.bound, |
| 1404 overriddenExecutable.enclosingElement.displayName |
| 1405 ]); |
| 1406 return true; |
| 1407 } |
| 1408 } |
| 1409 // Proceed with the rest of the checks, using instantiated types. |
| 1410 overridingFT = overridingFT.instantiate(variablesFresh); |
| 1411 overriddenFT = overriddenFT.instantiate(variablesFresh); |
| 1412 } |
| 1413 } |
| 1414 |
1350 DartType overridingFTReturnType = overridingFT.returnType; | 1415 DartType overridingFTReturnType = overridingFT.returnType; |
1351 DartType overriddenFTReturnType = overriddenFT.returnType; | 1416 DartType overriddenFTReturnType = overriddenFT.returnType; |
1352 List<DartType> overridingNormalPT = overridingFT.normalParameterTypes; | 1417 List<DartType> overridingNormalPT = overridingFT.normalParameterTypes; |
1353 List<DartType> overriddenNormalPT = overriddenFT.normalParameterTypes; | 1418 List<DartType> overriddenNormalPT = overriddenFT.normalParameterTypes; |
1354 List<DartType> overridingPositionalPT = overridingFT.optionalParameterTypes; | 1419 List<DartType> overridingPositionalPT = overridingFT.optionalParameterTypes; |
1355 List<DartType> overriddenPositionalPT = overriddenFT.optionalParameterTypes; | 1420 List<DartType> overriddenPositionalPT = overriddenFT.optionalParameterTypes; |
1356 Map<String, DartType> overridingNamedPT = overridingFT.namedParameterTypes; | 1421 Map<String, DartType> overridingNamedPT = overridingFT.namedParameterTypes; |
1357 Map<String, DartType> overriddenNamedPT = overriddenFT.namedParameterTypes; | 1422 Map<String, DartType> overriddenNamedPT = overriddenFT.namedParameterTypes; |
1358 // CTEC.INVALID_OVERRIDE_REQUIRED, CTEC.INVALID_OVERRIDE_POSITIONAL and | 1423 // CTEC.INVALID_OVERRIDE_REQUIRED, CTEC.INVALID_OVERRIDE_POSITIONAL and |
1359 // CTEC.INVALID_OVERRIDE_NAMED | 1424 // CTEC.INVALID_OVERRIDE_NAMED |
(...skipping 4750 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6110 toCheck.add(type.element); | 6175 toCheck.add(type.element); |
6111 // type arguments | 6176 // type arguments |
6112 if (type is InterfaceType) { | 6177 if (type is InterfaceType) { |
6113 InterfaceType interfaceType = type; | 6178 InterfaceType interfaceType = type; |
6114 for (DartType typeArgument in interfaceType.typeArguments) { | 6179 for (DartType typeArgument in interfaceType.typeArguments) { |
6115 _addTypeToCheck(typeArgument); | 6180 _addTypeToCheck(typeArgument); |
6116 } | 6181 } |
6117 } | 6182 } |
6118 } | 6183 } |
6119 } | 6184 } |
OLD | NEW |