| 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 analyzer.src.generated.error_verifier; | 5 library analyzer.src.generated.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/dart/element/element.dart'; |
| 11 import 'package:analyzer/dart/element/type.dart'; |
| 12 import 'package:analyzer/dart/element/visitor.dart'; |
| 13 import 'package:analyzer/src/dart/element/element.dart'; |
| 14 import 'package:analyzer/src/dart/element/member.dart'; |
| 15 import 'package:analyzer/src/dart/element/type.dart'; |
| 10 import 'package:analyzer/src/generated/ast.dart'; | 16 import 'package:analyzer/src/generated/ast.dart'; |
| 11 import 'package:analyzer/src/generated/constant.dart'; | 17 import 'package:analyzer/src/generated/constant.dart'; |
| 12 import 'package:analyzer/src/generated/element.dart'; | |
| 13 import 'package:analyzer/src/generated/element_resolver.dart'; | 18 import 'package:analyzer/src/generated/element_resolver.dart'; |
| 14 import 'package:analyzer/src/generated/error.dart'; | 19 import 'package:analyzer/src/generated/error.dart'; |
| 15 import 'package:analyzer/src/generated/java_engine.dart'; | 20 import 'package:analyzer/src/generated/java_engine.dart'; |
| 16 import 'package:analyzer/src/generated/parser.dart' | 21 import 'package:analyzer/src/generated/parser.dart' |
| 17 show Parser, ParserErrorCode; | 22 show Parser, ParserErrorCode; |
| 18 import 'package:analyzer/src/generated/resolver.dart'; | 23 import 'package:analyzer/src/generated/resolver.dart'; |
| 19 import 'package:analyzer/src/generated/scanner.dart' as sc; | 24 import 'package:analyzer/src/generated/scanner.dart' as sc; |
| 20 import 'package:analyzer/src/generated/sdk.dart' show DartSdk, SdkLibrary; | 25 import 'package:analyzer/src/generated/sdk.dart' show DartSdk, SdkLibrary; |
| 21 import 'package:analyzer/src/generated/static_type_analyzer.dart'; | 26 import 'package:analyzer/src/generated/static_type_analyzer.dart'; |
| 22 import 'package:analyzer/src/generated/utilities_dart.dart'; | 27 import 'package:analyzer/src/generated/utilities_dart.dart'; |
| (...skipping 1171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1194 } | 1199 } |
| 1195 if (parameter is FieldFormalParameter) { | 1200 if (parameter is FieldFormalParameter) { |
| 1196 FieldElement fieldElement = | 1201 FieldElement fieldElement = |
| 1197 (parameter.element as FieldFormalParameterElementImpl).field; | 1202 (parameter.element as FieldFormalParameterElementImpl).field; |
| 1198 INIT_STATE state = fieldElementsMap[fieldElement]; | 1203 INIT_STATE state = fieldElementsMap[fieldElement]; |
| 1199 if (state == INIT_STATE.NOT_INIT) { | 1204 if (state == INIT_STATE.NOT_INIT) { |
| 1200 fieldElementsMap[fieldElement] = INIT_STATE.INIT_IN_FIELD_FORMAL; | 1205 fieldElementsMap[fieldElement] = INIT_STATE.INIT_IN_FIELD_FORMAL; |
| 1201 } else if (state == INIT_STATE.INIT_IN_DECLARATION) { | 1206 } else if (state == INIT_STATE.INIT_IN_DECLARATION) { |
| 1202 if (fieldElement.isFinal || fieldElement.isConst) { | 1207 if (fieldElement.isFinal || fieldElement.isConst) { |
| 1203 _errorReporter.reportErrorForNode( | 1208 _errorReporter.reportErrorForNode( |
| 1204 StaticWarningCode.FINAL_INITIALIZED_IN_DECLARATION_AND_CONSTRUCT
OR, | 1209 StaticWarningCode |
| 1210 .FINAL_INITIALIZED_IN_DECLARATION_AND_CONSTRUCTOR, |
| 1205 formalParameter.identifier, | 1211 formalParameter.identifier, |
| 1206 [fieldElement.displayName]); | 1212 [fieldElement.displayName]); |
| 1207 foundError = true; | 1213 foundError = true; |
| 1208 } | 1214 } |
| 1209 } else if (state == INIT_STATE.INIT_IN_FIELD_FORMAL) { | 1215 } else if (state == INIT_STATE.INIT_IN_FIELD_FORMAL) { |
| 1210 if (fieldElement.isFinal || fieldElement.isConst) { | 1216 if (fieldElement.isFinal || fieldElement.isConst) { |
| 1211 _errorReporter.reportErrorForNode( | 1217 _errorReporter.reportErrorForNode( |
| 1212 CompileTimeErrorCode.FINAL_INITIALIZED_MULTIPLE_TIMES, | 1218 CompileTimeErrorCode.FINAL_INITIALIZED_MULTIPLE_TIMES, |
| 1213 formalParameter.identifier, | 1219 formalParameter.identifier, |
| 1214 [fieldElement.displayName]); | 1220 [fieldElement.displayName]); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1229 SimpleIdentifier fieldName = constructorFieldInitializer.fieldName; | 1235 SimpleIdentifier fieldName = constructorFieldInitializer.fieldName; |
| 1230 Element element = fieldName.staticElement; | 1236 Element element = fieldName.staticElement; |
| 1231 if (element is FieldElement) { | 1237 if (element is FieldElement) { |
| 1232 FieldElement fieldElement = element; | 1238 FieldElement fieldElement = element; |
| 1233 INIT_STATE state = fieldElementsMap[fieldElement]; | 1239 INIT_STATE state = fieldElementsMap[fieldElement]; |
| 1234 if (state == INIT_STATE.NOT_INIT) { | 1240 if (state == INIT_STATE.NOT_INIT) { |
| 1235 fieldElementsMap[fieldElement] = INIT_STATE.INIT_IN_INITIALIZERS; | 1241 fieldElementsMap[fieldElement] = INIT_STATE.INIT_IN_INITIALIZERS; |
| 1236 } else if (state == INIT_STATE.INIT_IN_DECLARATION) { | 1242 } else if (state == INIT_STATE.INIT_IN_DECLARATION) { |
| 1237 if (fieldElement.isFinal || fieldElement.isConst) { | 1243 if (fieldElement.isFinal || fieldElement.isConst) { |
| 1238 _errorReporter.reportErrorForNode( | 1244 _errorReporter.reportErrorForNode( |
| 1239 StaticWarningCode.FIELD_INITIALIZED_IN_INITIALIZER_AND_DECLARA
TION, | 1245 StaticWarningCode |
| 1246 .FIELD_INITIALIZED_IN_INITIALIZER_AND_DECLARATION, |
| 1240 fieldName); | 1247 fieldName); |
| 1241 foundError = true; | 1248 foundError = true; |
| 1242 } | 1249 } |
| 1243 } else if (state == INIT_STATE.INIT_IN_FIELD_FORMAL) { | 1250 } else if (state == INIT_STATE.INIT_IN_FIELD_FORMAL) { |
| 1244 _errorReporter.reportErrorForNode( | 1251 _errorReporter.reportErrorForNode( |
| 1245 CompileTimeErrorCode.FIELD_INITIALIZED_IN_PARAMETER_AND_INITIALI
ZER, | 1252 CompileTimeErrorCode |
| 1253 .FIELD_INITIALIZED_IN_PARAMETER_AND_INITIALIZER, |
| 1246 fieldName); | 1254 fieldName); |
| 1247 foundError = true; | 1255 foundError = true; |
| 1248 } else if (state == INIT_STATE.INIT_IN_INITIALIZERS) { | 1256 } else if (state == INIT_STATE.INIT_IN_INITIALIZERS) { |
| 1249 _errorReporter.reportErrorForNode( | 1257 _errorReporter.reportErrorForNode( |
| 1250 CompileTimeErrorCode.FIELD_INITIALIZED_BY_MULTIPLE_INITIALIZERS, | 1258 CompileTimeErrorCode.FIELD_INITIALIZED_BY_MULTIPLE_INITIALIZERS, |
| 1251 fieldName, | 1259 fieldName, |
| 1252 [fieldElement.displayName]); | 1260 [fieldElement.displayName]); |
| 1253 foundError = true; | 1261 foundError = true; |
| 1254 } | 1262 } |
| 1255 } | 1263 } |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1334 bool isSetter = false; | 1342 bool isSetter = false; |
| 1335 if (executableElement is PropertyAccessorElement) { | 1343 if (executableElement is PropertyAccessorElement) { |
| 1336 PropertyAccessorElement accessorElement = executableElement; | 1344 PropertyAccessorElement accessorElement = executableElement; |
| 1337 isGetter = accessorElement.isGetter; | 1345 isGetter = accessorElement.isGetter; |
| 1338 isSetter = accessorElement.isSetter; | 1346 isSetter = accessorElement.isSetter; |
| 1339 } | 1347 } |
| 1340 String executableElementName = executableElement.name; | 1348 String executableElementName = executableElement.name; |
| 1341 FunctionType overridingFT = executableElement.type; | 1349 FunctionType overridingFT = executableElement.type; |
| 1342 FunctionType overriddenFT = overriddenExecutable.type; | 1350 FunctionType overriddenFT = overriddenExecutable.type; |
| 1343 InterfaceType enclosingType = _enclosingClass.type; | 1351 InterfaceType enclosingType = _enclosingClass.type; |
| 1344 overriddenFT = _inheritanceManager | 1352 overriddenFT = |
| 1345 .substituteTypeArgumentsInMemberFromInheritance( | 1353 _inheritanceManager.substituteTypeArgumentsInMemberFromInheritance( |
| 1346 overriddenFT, executableElementName, enclosingType); | 1354 overriddenFT, executableElementName, enclosingType); |
| 1347 if (overridingFT == null || overriddenFT == null) { | 1355 if (overridingFT == null || overriddenFT == null) { |
| 1348 return false; | 1356 return false; |
| 1349 } | 1357 } |
| 1350 | 1358 |
| 1351 // Handle generic function type parameters. | 1359 // Handle generic function type parameters. |
| 1352 // TODO(jmesserly): this duplicates some code in isSubtypeOf and most of | 1360 // TODO(jmesserly): this duplicates some code in isSubtypeOf and most of |
| 1353 // _isGenericFunctionSubtypeOf. Ideally, we'd let TypeSystem produce | 1361 // _isGenericFunctionSubtypeOf. Ideally, we'd let TypeSystem produce |
| 1354 // an error message once it's ready to "return false". | 1362 // an error message once it's ready to "return false". |
| 1355 if (!overridingFT.boundTypeParameters.isEmpty) { | 1363 if (!overridingFT.boundTypeParameters.isEmpty) { |
| 1356 if (overriddenFT.boundTypeParameters.isEmpty) { | 1364 if (overriddenFT.boundTypeParameters.isEmpty) { |
| 1357 overriddenFT = _typeSystem.instantiateToBounds(overriddenFT); | 1365 overriddenFT = _typeSystem.instantiateToBounds(overriddenFT); |
| 1358 } else { | 1366 } else { |
| 1359 List<TypeParameterElement> params1 = overridingFT.boundTypeParameters; | 1367 List<TypeParameterElement> params1 = overridingFT.boundTypeParameters; |
| 1360 List<TypeParameterElement> params2 = overriddenFT.boundTypeParameters; | 1368 List<TypeParameterElement> params2 = overriddenFT.boundTypeParameters; |
| 1361 int count = params1.length; | 1369 int count = params1.length; |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1459 // SWC.INVALID_METHOD_OVERRIDE_RETURN_TYPE | 1467 // SWC.INVALID_METHOD_OVERRIDE_RETURN_TYPE |
| 1460 if (overriddenFTReturnType != VoidTypeImpl.instance && | 1468 if (overriddenFTReturnType != VoidTypeImpl.instance && |
| 1461 !_typeSystem.isAssignableTo( | 1469 !_typeSystem.isAssignableTo( |
| 1462 overridingFTReturnType, overriddenFTReturnType)) { | 1470 overridingFTReturnType, overriddenFTReturnType)) { |
| 1463 _errorReporter.reportTypeErrorForNode( | 1471 _errorReporter.reportTypeErrorForNode( |
| 1464 !isGetter | 1472 !isGetter |
| 1465 ? StaticWarningCode.INVALID_METHOD_OVERRIDE_RETURN_TYPE | 1473 ? StaticWarningCode.INVALID_METHOD_OVERRIDE_RETURN_TYPE |
| 1466 : StaticWarningCode.INVALID_GETTER_OVERRIDE_RETURN_TYPE, | 1474 : StaticWarningCode.INVALID_GETTER_OVERRIDE_RETURN_TYPE, |
| 1467 errorNameTarget, | 1475 errorNameTarget, |
| 1468 [ | 1476 [ |
| 1469 overridingFTReturnType, | 1477 overridingFTReturnType, |
| 1470 overriddenFTReturnType, | 1478 overriddenFTReturnType, |
| 1471 overriddenExecutable.enclosingElement.displayName | 1479 overriddenExecutable.enclosingElement.displayName |
| 1472 ]); | 1480 ]); |
| 1473 return true; | 1481 return true; |
| 1474 } | 1482 } |
| 1475 // SWC.INVALID_METHOD_OVERRIDE_NORMAL_PARAM_TYPE | 1483 // SWC.INVALID_METHOD_OVERRIDE_NORMAL_PARAM_TYPE |
| 1476 if (parameterLocations == null) { | 1484 if (parameterLocations == null) { |
| 1477 return false; | 1485 return false; |
| 1478 } | 1486 } |
| 1479 int parameterIndex = 0; | 1487 int parameterIndex = 0; |
| 1480 for (int i = 0; i < overridingNormalPT.length; i++) { | 1488 for (int i = 0; i < overridingNormalPT.length; i++) { |
| 1481 if (!_typeSystem.isAssignableTo( | 1489 if (!_typeSystem.isAssignableTo( |
| 1482 overridingNormalPT[i], overriddenNormalPT[i])) { | 1490 overridingNormalPT[i], overriddenNormalPT[i])) { |
| 1483 _errorReporter.reportTypeErrorForNode( | 1491 _errorReporter.reportTypeErrorForNode( |
| 1484 !isSetter | 1492 !isSetter |
| 1485 ? StaticWarningCode.INVALID_METHOD_OVERRIDE_NORMAL_PARAM_TYPE | 1493 ? StaticWarningCode.INVALID_METHOD_OVERRIDE_NORMAL_PARAM_TYPE |
| 1486 : StaticWarningCode.INVALID_SETTER_OVERRIDE_NORMAL_PARAM_TYPE, | 1494 : StaticWarningCode.INVALID_SETTER_OVERRIDE_NORMAL_PARAM_TYPE, |
| 1487 parameterLocations[parameterIndex], | 1495 parameterLocations[parameterIndex], |
| 1488 [ | 1496 [ |
| 1489 overridingNormalPT[i], | 1497 overridingNormalPT[i], |
| 1490 overriddenNormalPT[i], | 1498 overriddenNormalPT[i], |
| 1491 overriddenExecutable.enclosingElement.displayName | 1499 overriddenExecutable.enclosingElement.displayName |
| 1492 ]); | 1500 ]); |
| 1493 return true; | 1501 return true; |
| 1494 } | 1502 } |
| 1495 parameterIndex++; | 1503 parameterIndex++; |
| 1496 } | 1504 } |
| 1497 // SWC.INVALID_METHOD_OVERRIDE_OPTIONAL_PARAM_TYPE | 1505 // SWC.INVALID_METHOD_OVERRIDE_OPTIONAL_PARAM_TYPE |
| 1498 for (int i = 0; i < overriddenPositionalPT.length; i++) { | 1506 for (int i = 0; i < overriddenPositionalPT.length; i++) { |
| 1499 if (!_typeSystem.isAssignableTo( | 1507 if (!_typeSystem.isAssignableTo( |
| 1500 overridingPositionalPT[i], overriddenPositionalPT[i])) { | 1508 overridingPositionalPT[i], overriddenPositionalPT[i])) { |
| 1501 _errorReporter.reportTypeErrorForNode( | 1509 _errorReporter.reportTypeErrorForNode( |
| 1502 StaticWarningCode.INVALID_METHOD_OVERRIDE_OPTIONAL_PARAM_TYPE, | 1510 StaticWarningCode.INVALID_METHOD_OVERRIDE_OPTIONAL_PARAM_TYPE, |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1598 String overriddenParameterName = overriddenParameterElt.name; | 1606 String overriddenParameterName = overriddenParameterElt.name; |
| 1599 if (parameterName != null && | 1607 if (parameterName != null && |
| 1600 parameterName == overriddenParameterName) { | 1608 parameterName == overriddenParameterName) { |
| 1601 EvaluationResultImpl overriddenResult = | 1609 EvaluationResultImpl overriddenResult = |
| 1602 overriddenParameterElt.evaluationResult; | 1610 overriddenParameterElt.evaluationResult; |
| 1603 if (_isUserDefinedObject(overriddenResult)) { | 1611 if (_isUserDefinedObject(overriddenResult)) { |
| 1604 break; | 1612 break; |
| 1605 } | 1613 } |
| 1606 if (!result.equalValues(_typeProvider, overriddenResult)) { | 1614 if (!result.equalValues(_typeProvider, overriddenResult)) { |
| 1607 _errorReporter.reportErrorForNode( | 1615 _errorReporter.reportErrorForNode( |
| 1608 StaticWarningCode.INVALID_OVERRIDE_DIFFERENT_DEFAULT_VALUES_
NAMED, | 1616 StaticWarningCode |
| 1609 formalParameters[i], [ | 1617 .INVALID_OVERRIDE_DIFFERENT_DEFAULT_VALUES_NAMED, |
| 1610 overriddenExecutable.enclosingElement.displayName, | 1618 formalParameters[i], |
| 1611 overriddenExecutable.displayName, | 1619 [ |
| 1612 parameterName | 1620 overriddenExecutable.enclosingElement.displayName, |
| 1613 ]); | 1621 overriddenExecutable.displayName, |
| 1622 parameterName |
| 1623 ]); |
| 1614 foundError = true; | 1624 foundError = true; |
| 1615 } | 1625 } |
| 1616 } | 1626 } |
| 1617 } | 1627 } |
| 1618 } | 1628 } |
| 1619 } else { | 1629 } else { |
| 1620 // Positional parameters, consider the positions when matching the | 1630 // Positional parameters, consider the positions when matching the |
| 1621 // parameterElts to the overriddenParameterElts | 1631 // parameterElts to the overriddenParameterElts |
| 1622 for (int i = 0; | 1632 for (int i = 0; |
| 1623 i < parameterElts.length && i < overriddenParameterElts.length; | 1633 i < parameterElts.length && i < overriddenParameterElts.length; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1635 // default. | 1645 // default. |
| 1636 continue; | 1646 continue; |
| 1637 } | 1647 } |
| 1638 EvaluationResultImpl overriddenResult = | 1648 EvaluationResultImpl overriddenResult = |
| 1639 overriddenParameterElt.evaluationResult; | 1649 overriddenParameterElt.evaluationResult; |
| 1640 if (_isUserDefinedObject(overriddenResult)) { | 1650 if (_isUserDefinedObject(overriddenResult)) { |
| 1641 continue; | 1651 continue; |
| 1642 } | 1652 } |
| 1643 if (!result.equalValues(_typeProvider, overriddenResult)) { | 1653 if (!result.equalValues(_typeProvider, overriddenResult)) { |
| 1644 _errorReporter.reportErrorForNode( | 1654 _errorReporter.reportErrorForNode( |
| 1645 StaticWarningCode.INVALID_OVERRIDE_DIFFERENT_DEFAULT_VALUES_POSI
TIONAL, | 1655 StaticWarningCode |
| 1646 formalParameters[i], [ | 1656 .INVALID_OVERRIDE_DIFFERENT_DEFAULT_VALUES_POSITIONAL, |
| 1647 overriddenExecutable.enclosingElement.displayName, | 1657 formalParameters[i], |
| 1648 overriddenExecutable.displayName | 1658 [ |
| 1649 ]); | 1659 overriddenExecutable.enclosingElement.displayName, |
| 1660 overriddenExecutable.displayName |
| 1661 ]); |
| 1650 foundError = true; | 1662 foundError = true; |
| 1651 } | 1663 } |
| 1652 } | 1664 } |
| 1653 } | 1665 } |
| 1654 } | 1666 } |
| 1655 return foundError; | 1667 return foundError; |
| 1656 } | 1668 } |
| 1657 | 1669 |
| 1658 /** | 1670 /** |
| 1659 * Check the given [executableElement] against override-error codes. This | 1671 * Check the given [executableElement] against override-error codes. This |
| (...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2152 * given [errorCode] on the identifier if it is a keyword. | 2164 * given [errorCode] on the identifier if it is a keyword. |
| 2153 * | 2165 * |
| 2154 * See [CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE_NAME], | 2166 * See [CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE_NAME], |
| 2155 * [CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE_PARAMETER_NAME], and | 2167 * [CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE_PARAMETER_NAME], and |
| 2156 * [CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPEDEF_NAME]. | 2168 * [CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPEDEF_NAME]. |
| 2157 */ | 2169 */ |
| 2158 bool _checkForBuiltInIdentifierAsName( | 2170 bool _checkForBuiltInIdentifierAsName( |
| 2159 SimpleIdentifier identifier, ErrorCode errorCode) { | 2171 SimpleIdentifier identifier, ErrorCode errorCode) { |
| 2160 sc.Token token = identifier.token; | 2172 sc.Token token = identifier.token; |
| 2161 if (token.type == sc.TokenType.KEYWORD) { | 2173 if (token.type == sc.TokenType.KEYWORD) { |
| 2162 _errorReporter.reportErrorForNode( | 2174 _errorReporter |
| 2163 errorCode, identifier, [identifier.name]); | 2175 .reportErrorForNode(errorCode, identifier, [identifier.name]); |
| 2164 return true; | 2176 return true; |
| 2165 } | 2177 } |
| 2166 return false; | 2178 return false; |
| 2167 } | 2179 } |
| 2168 | 2180 |
| 2169 /** | 2181 /** |
| 2170 * Verify that the given [switchCase] is terminated with 'break', 'continue', | 2182 * Verify that the given [switchCase] is terminated with 'break', 'continue', |
| 2171 * 'return' or 'throw'. | 2183 * 'return' or 'throw'. |
| 2172 * | 2184 * |
| 2173 * see [StaticWarningCode.CASE_BLOCK_NOT_TERMINATED]. | 2185 * see [StaticWarningCode.CASE_BLOCK_NOT_TERMINATED]. |
| (...skipping 1080 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3254 * [CompileTimeErrorCode.EXTENDS_DEFERRED_CLASS], | 3266 * [CompileTimeErrorCode.EXTENDS_DEFERRED_CLASS], |
| 3255 * [CompileTimeErrorCode.IMPLEMENTS_DEFERRED_CLASS], and | 3267 * [CompileTimeErrorCode.IMPLEMENTS_DEFERRED_CLASS], and |
| 3256 * [CompileTimeErrorCode.MIXIN_DEFERRED_CLASS]. | 3268 * [CompileTimeErrorCode.MIXIN_DEFERRED_CLASS]. |
| 3257 */ | 3269 */ |
| 3258 bool _checkForExtendsOrImplementsDeferredClass( | 3270 bool _checkForExtendsOrImplementsDeferredClass( |
| 3259 TypeName typeName, ErrorCode errorCode) { | 3271 TypeName typeName, ErrorCode errorCode) { |
| 3260 if (typeName.isSynthetic) { | 3272 if (typeName.isSynthetic) { |
| 3261 return false; | 3273 return false; |
| 3262 } | 3274 } |
| 3263 if (typeName.isDeferred) { | 3275 if (typeName.isDeferred) { |
| 3264 _errorReporter.reportErrorForNode( | 3276 _errorReporter |
| 3265 errorCode, typeName, [typeName.name.name]); | 3277 .reportErrorForNode(errorCode, typeName, [typeName.name.name]); |
| 3266 return true; | 3278 return true; |
| 3267 } | 3279 } |
| 3268 return false; | 3280 return false; |
| 3269 } | 3281 } |
| 3270 | 3282 |
| 3271 /** | 3283 /** |
| 3272 * Verify that the given [typeName] does not extend, implement or mixin | 3284 * Verify that the given [typeName] does not extend, implement or mixin |
| 3273 * classes such as 'num' or 'String'. | 3285 * classes such as 'num' or 'String'. |
| 3274 * | 3286 * |
| 3275 * See [_checkForExtendsDisallowedClass], | 3287 * See [_checkForExtendsDisallowedClass], |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3350 return false; | 3362 return false; |
| 3351 } | 3363 } |
| 3352 if (_typeSystem.isAssignableTo(staticType, fieldType)) { | 3364 if (_typeSystem.isAssignableTo(staticType, fieldType)) { |
| 3353 return false; | 3365 return false; |
| 3354 } | 3366 } |
| 3355 // report problem | 3367 // report problem |
| 3356 if (_isEnclosingConstructorConst) { | 3368 if (_isEnclosingConstructorConst) { |
| 3357 // TODO(paulberry): this error should be based on the actual type of the | 3369 // TODO(paulberry): this error should be based on the actual type of the |
| 3358 // constant, not the static type. See dartbug.com/21119. | 3370 // constant, not the static type. See dartbug.com/21119. |
| 3359 _errorReporter.reportTypeErrorForNode( | 3371 _errorReporter.reportTypeErrorForNode( |
| 3360 CheckedModeCompileTimeErrorCode.CONST_FIELD_INITIALIZER_NOT_ASSIGNABLE
, | 3372 CheckedModeCompileTimeErrorCode |
| 3373 .CONST_FIELD_INITIALIZER_NOT_ASSIGNABLE, |
| 3361 expression, | 3374 expression, |
| 3362 [staticType, fieldType]); | 3375 [staticType, fieldType]); |
| 3363 } | 3376 } |
| 3364 _errorReporter.reportTypeErrorForNode( | 3377 _errorReporter.reportTypeErrorForNode( |
| 3365 StaticWarningCode.FIELD_INITIALIZER_NOT_ASSIGNABLE, | 3378 StaticWarningCode.FIELD_INITIALIZER_NOT_ASSIGNABLE, |
| 3366 expression, | 3379 expression, |
| 3367 [staticType, fieldType]); | 3380 [staticType, fieldType]); |
| 3368 return true; | 3381 return true; |
| 3369 // TODO(brianwilkerson) Define a hint corresponding to these errors and | 3382 // TODO(brianwilkerson) Define a hint corresponding to these errors and |
| 3370 // report it if appropriate. | 3383 // report it if appropriate. |
| (...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3792 superclassElement.getField(executableElementName); | 3805 superclassElement.getField(executableElementName); |
| 3793 if (fieldElt != null) { | 3806 if (fieldElt != null) { |
| 3794 // Ignore if private in a different library - cannot collide. | 3807 // Ignore if private in a different library - cannot collide. |
| 3795 if (executableElementPrivate && | 3808 if (executableElementPrivate && |
| 3796 _currentLibrary != superclassLibrary) { | 3809 _currentLibrary != superclassLibrary) { |
| 3797 continue; | 3810 continue; |
| 3798 } | 3811 } |
| 3799 // instance vs. static | 3812 // instance vs. static |
| 3800 if (fieldElt.isStatic) { | 3813 if (fieldElt.isStatic) { |
| 3801 _errorReporter.reportErrorForNode( | 3814 _errorReporter.reportErrorForNode( |
| 3802 StaticWarningCode.INSTANCE_METHOD_NAME_COLLIDES_WITH_SUPERCLASS_
STATIC, | 3815 StaticWarningCode |
| 3816 .INSTANCE_METHOD_NAME_COLLIDES_WITH_SUPERCLASS_STATIC, |
| 3803 errorNameTarget, | 3817 errorNameTarget, |
| 3804 [executableElementName, fieldElt.enclosingElement.displayName]); | 3818 [executableElementName, fieldElt.enclosingElement.displayName]); |
| 3805 return true; | 3819 return true; |
| 3806 } | 3820 } |
| 3807 } | 3821 } |
| 3808 // Check methods. | 3822 // Check methods. |
| 3809 List<MethodElement> methodElements = superclassElement.methods; | 3823 List<MethodElement> methodElements = superclassElement.methods; |
| 3810 for (MethodElement methodElement in methodElements) { | 3824 for (MethodElement methodElement in methodElements) { |
| 3811 // We need the same name. | 3825 // We need the same name. |
| 3812 if (methodElement.name != executableElementName) { | 3826 if (methodElement.name != executableElementName) { |
| 3813 continue; | 3827 continue; |
| 3814 } | 3828 } |
| 3815 // Ignore if private in a different library - cannot collide. | 3829 // Ignore if private in a different library - cannot collide. |
| 3816 if (executableElementPrivate && | 3830 if (executableElementPrivate && |
| 3817 _currentLibrary != superclassLibrary) { | 3831 _currentLibrary != superclassLibrary) { |
| 3818 continue; | 3832 continue; |
| 3819 } | 3833 } |
| 3820 // instance vs. static | 3834 // instance vs. static |
| 3821 if (methodElement.isStatic) { | 3835 if (methodElement.isStatic) { |
| 3822 _errorReporter.reportErrorForNode( | 3836 _errorReporter.reportErrorForNode( |
| 3823 StaticWarningCode.INSTANCE_METHOD_NAME_COLLIDES_WITH_SUPERCLASS_
STATIC, | 3837 StaticWarningCode |
| 3824 errorNameTarget, [ | 3838 .INSTANCE_METHOD_NAME_COLLIDES_WITH_SUPERCLASS_STATIC, |
| 3825 executableElementName, | 3839 errorNameTarget, |
| 3826 methodElement.enclosingElement.displayName | 3840 [ |
| 3827 ]); | 3841 executableElementName, |
| 3842 methodElement.enclosingElement.displayName |
| 3843 ]); |
| 3828 return true; | 3844 return true; |
| 3829 } | 3845 } |
| 3830 } | 3846 } |
| 3831 superclassType = superclassElement.supertype; | 3847 superclassType = superclassElement.supertype; |
| 3832 superclassElement = | 3848 superclassElement = |
| 3833 superclassType == null ? null : superclassType.element; | 3849 superclassType == null ? null : superclassType.element; |
| 3834 } | 3850 } |
| 3835 } | 3851 } |
| 3836 return false; | 3852 return false; |
| 3837 } | 3853 } |
| (...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4319 return false; | 4335 return false; |
| 4320 } | 4336 } |
| 4321 | 4337 |
| 4322 /** | 4338 /** |
| 4323 * Report the error [CompileTimeErrorCode.MIXIN_HAS_NO_CONSTRUCTORS] if | 4339 * Report the error [CompileTimeErrorCode.MIXIN_HAS_NO_CONSTRUCTORS] if |
| 4324 * appropriate. | 4340 * appropriate. |
| 4325 */ | 4341 */ |
| 4326 void _checkForMixinHasNoConstructors(AstNode node) { | 4342 void _checkForMixinHasNoConstructors(AstNode node) { |
| 4327 if ((_enclosingClass as ClassElementImpl).doesMixinLackConstructors) { | 4343 if ((_enclosingClass as ClassElementImpl).doesMixinLackConstructors) { |
| 4328 ErrorCode errorCode = CompileTimeErrorCode.MIXIN_HAS_NO_CONSTRUCTORS; | 4344 ErrorCode errorCode = CompileTimeErrorCode.MIXIN_HAS_NO_CONSTRUCTORS; |
| 4329 _errorReporter.reportErrorForNode( | 4345 _errorReporter |
| 4330 errorCode, node, [_enclosingClass.supertype]); | 4346 .reportErrorForNode(errorCode, node, [_enclosingClass.supertype]); |
| 4331 } | 4347 } |
| 4332 } | 4348 } |
| 4333 | 4349 |
| 4334 /** | 4350 /** |
| 4335 * Verify that the given mixin has the 'Object' superclass. The [mixinName] is | 4351 * Verify that the given mixin has the 'Object' superclass. The [mixinName] is |
| 4336 * the node to report problem on. The [mixinElement] is the mixing to | 4352 * the node to report problem on. The [mixinElement] is the mixing to |
| 4337 * evaluate. | 4353 * evaluate. |
| 4338 * | 4354 * |
| 4339 * See [CompileTimeErrorCode.MIXIN_INHERITS_FROM_NOT_OBJECT]. | 4355 * See [CompileTimeErrorCode.MIXIN_INHERITS_FROM_NOT_OBJECT]. |
| 4340 */ | 4356 */ |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4649 analysisError = _errorReporter.newErrorWithProperties( | 4665 analysisError = _errorReporter.newErrorWithProperties( |
| 4650 StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_FOUR, | 4666 StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_FOUR, |
| 4651 classNameNode, [ | 4667 classNameNode, [ |
| 4652 stringMembersArray[0], | 4668 stringMembersArray[0], |
| 4653 stringMembersArray[1], | 4669 stringMembersArray[1], |
| 4654 stringMembersArray[2], | 4670 stringMembersArray[2], |
| 4655 stringMembersArray[3] | 4671 stringMembersArray[3] |
| 4656 ]); | 4672 ]); |
| 4657 } else { | 4673 } else { |
| 4658 analysisError = _errorReporter.newErrorWithProperties( | 4674 analysisError = _errorReporter.newErrorWithProperties( |
| 4659 StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_FIVE_PLU
S, | 4675 StaticWarningCode |
| 4660 classNameNode, [ | 4676 .NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_FIVE_PLUS, |
| 4661 stringMembersArray[0], | 4677 classNameNode, |
| 4662 stringMembersArray[1], | 4678 [ |
| 4663 stringMembersArray[2], | 4679 stringMembersArray[0], |
| 4664 stringMembersArray[3], | 4680 stringMembersArray[1], |
| 4665 stringMembersArray.length - 4 | 4681 stringMembersArray[2], |
| 4666 ]); | 4682 stringMembersArray[3], |
| 4683 stringMembersArray.length - 4 |
| 4684 ]); |
| 4667 } | 4685 } |
| 4668 analysisError.setProperty( | 4686 analysisError.setProperty( |
| 4669 ErrorProperty.UNIMPLEMENTED_METHODS, missingOverridesArray); | 4687 ErrorProperty.UNIMPLEMENTED_METHODS, missingOverridesArray); |
| 4670 _errorReporter.reportError(analysisError); | 4688 _errorReporter.reportError(analysisError); |
| 4671 return true; | 4689 return true; |
| 4672 } | 4690 } |
| 4673 | 4691 |
| 4674 /** | 4692 /** |
| 4675 * Check to ensure that the [condition] is of type bool, are. Otherwise an | 4693 * Check to ensure that the [condition] is of type bool, are. Otherwise an |
| 4676 * error is reported on the expression. | 4694 * error is reported on the expression. |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4940 bool errorReported = false; | 4958 bool errorReported = false; |
| 4941 // | 4959 // |
| 4942 // Check for default values in the parameters | 4960 // Check for default values in the parameters |
| 4943 // | 4961 // |
| 4944 ConstructorName redirectedConstructor = declaration.redirectedConstructor; | 4962 ConstructorName redirectedConstructor = declaration.redirectedConstructor; |
| 4945 if (redirectedConstructor != null) { | 4963 if (redirectedConstructor != null) { |
| 4946 for (FormalParameter parameter in declaration.parameters.parameters) { | 4964 for (FormalParameter parameter in declaration.parameters.parameters) { |
| 4947 if (parameter is DefaultFormalParameter && | 4965 if (parameter is DefaultFormalParameter && |
| 4948 parameter.defaultValue != null) { | 4966 parameter.defaultValue != null) { |
| 4949 _errorReporter.reportErrorForNode( | 4967 _errorReporter.reportErrorForNode( |
| 4950 CompileTimeErrorCode.DEFAULT_VALUE_IN_REDIRECTING_FACTORY_CONSTRUC
TOR, | 4968 CompileTimeErrorCode |
| 4969 .DEFAULT_VALUE_IN_REDIRECTING_FACTORY_CONSTRUCTOR, |
| 4951 parameter.identifier); | 4970 parameter.identifier); |
| 4952 errorReported = true; | 4971 errorReported = true; |
| 4953 } | 4972 } |
| 4954 } | 4973 } |
| 4955 } | 4974 } |
| 4956 // check if there are redirected invocations | 4975 // check if there are redirected invocations |
| 4957 int numRedirections = 0; | 4976 int numRedirections = 0; |
| 4958 for (ConstructorInitializer initializer in declaration.initializers) { | 4977 for (ConstructorInitializer initializer in declaration.initializers) { |
| 4959 if (initializer is RedirectingConstructorInvocation) { | 4978 if (initializer is RedirectingConstructorInvocation) { |
| 4960 if (numRedirections > 0) { | 4979 if (numRedirections > 0) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 4972 if (invocation.constructorName != null) { | 4991 if (invocation.constructorName != null) { |
| 4973 constructorStrName += ".${invocation.constructorName.name}"; | 4992 constructorStrName += ".${invocation.constructorName.name}"; |
| 4974 } | 4993 } |
| 4975 _errorReporter.reportErrorForNode( | 4994 _errorReporter.reportErrorForNode( |
| 4976 CompileTimeErrorCode.REDIRECT_GENERATIVE_TO_MISSING_CONSTRUCTOR, | 4995 CompileTimeErrorCode.REDIRECT_GENERATIVE_TO_MISSING_CONSTRUCTOR, |
| 4977 invocation, | 4996 invocation, |
| 4978 [constructorStrName, enclosingTypeName]); | 4997 [constructorStrName, enclosingTypeName]); |
| 4979 } else { | 4998 } else { |
| 4980 if (redirectingElement.isFactory) { | 4999 if (redirectingElement.isFactory) { |
| 4981 _errorReporter.reportErrorForNode( | 5000 _errorReporter.reportErrorForNode( |
| 4982 CompileTimeErrorCode.REDIRECT_GENERATIVE_TO_NON_GENERATIVE_CON
STRUCTOR, | 5001 CompileTimeErrorCode |
| 5002 .REDIRECT_GENERATIVE_TO_NON_GENERATIVE_CONSTRUCTOR, |
| 4983 initializer); | 5003 initializer); |
| 4984 } | 5004 } |
| 4985 } | 5005 } |
| 4986 } | 5006 } |
| 4987 numRedirections++; | 5007 numRedirections++; |
| 4988 } | 5008 } |
| 4989 } | 5009 } |
| 4990 // check for other initializers | 5010 // check for other initializers |
| 4991 if (numRedirections > 0) { | 5011 if (numRedirections > 0) { |
| 4992 for (ConstructorInitializer initializer in declaration.initializers) { | 5012 for (ConstructorInitializer initializer in declaration.initializers) { |
| (...skipping 761 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5754 return staticReturnType; | 5774 return staticReturnType; |
| 5755 } | 5775 } |
| 5756 | 5776 |
| 5757 /** | 5777 /** |
| 5758 * Return the error code that should be used when the given class [element] | 5778 * Return the error code that should be used when the given class [element] |
| 5759 * references itself directly. | 5779 * references itself directly. |
| 5760 */ | 5780 */ |
| 5761 ErrorCode _getBaseCaseErrorCode(ClassElement element) { | 5781 ErrorCode _getBaseCaseErrorCode(ClassElement element) { |
| 5762 InterfaceType supertype = element.supertype; | 5782 InterfaceType supertype = element.supertype; |
| 5763 if (supertype != null && _enclosingClass == supertype.element) { | 5783 if (supertype != null && _enclosingClass == supertype.element) { |
| 5764 return CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_EXTE
NDS; | 5784 return CompileTimeErrorCode |
| 5785 .RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_EXTENDS; |
| 5765 } | 5786 } |
| 5766 List<InterfaceType> mixins = element.mixins; | 5787 List<InterfaceType> mixins = element.mixins; |
| 5767 for (int i = 0; i < mixins.length; i++) { | 5788 for (int i = 0; i < mixins.length; i++) { |
| 5768 if (_enclosingClass == mixins[i].element) { | 5789 if (_enclosingClass == mixins[i].element) { |
| 5769 return CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_WI
TH; | 5790 return CompileTimeErrorCode |
| 5791 .RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_WITH; |
| 5770 } | 5792 } |
| 5771 } | 5793 } |
| 5772 return CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_IMPLEM
ENTS; | 5794 return CompileTimeErrorCode |
| 5795 .RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_IMPLEMENTS; |
| 5773 } | 5796 } |
| 5774 | 5797 |
| 5775 /** | 5798 /** |
| 5776 * Given an [expression] in a switch case whose value is expected to be an | 5799 * Given an [expression] in a switch case whose value is expected to be an |
| 5777 * enum constant, return the name of the constant. | 5800 * enum constant, return the name of the constant. |
| 5778 */ | 5801 */ |
| 5779 String _getConstantName(Expression expression) { | 5802 String _getConstantName(Expression expression) { |
| 5780 // TODO(brianwilkerson) Convert this to return the element representing the | 5803 // TODO(brianwilkerson) Convert this to return the element representing the |
| 5781 // constant. | 5804 // constant. |
| 5782 if (expression is SimpleIdentifier) { | 5805 if (expression is SimpleIdentifier) { |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5872 return false; | 5895 return false; |
| 5873 } | 5896 } |
| 5874 | 5897 |
| 5875 /** | 5898 /** |
| 5876 * Return `true` if the given [element] has direct or indirect reference to | 5899 * Return `true` if the given [element] has direct or indirect reference to |
| 5877 * itself from anywhere except a class element or type parameter bounds. | 5900 * itself from anywhere except a class element or type parameter bounds. |
| 5878 */ | 5901 */ |
| 5879 bool _hasTypedefSelfReference(Element element) { | 5902 bool _hasTypedefSelfReference(Element element) { |
| 5880 Set<Element> checked = new HashSet<Element>(); | 5903 Set<Element> checked = new HashSet<Element>(); |
| 5881 List<Element> toCheck = new List<Element>(); | 5904 List<Element> toCheck = new List<Element>(); |
| 5882 GeneralizingElementVisitor_ErrorVerifier_hasTypedefSelfReference elementVisi
tor = | 5905 GeneralizingElementVisitor_ErrorVerifier_hasTypedefSelfReference |
| 5906 elementVisitor = |
| 5883 new GeneralizingElementVisitor_ErrorVerifier_hasTypedefSelfReference( | 5907 new GeneralizingElementVisitor_ErrorVerifier_hasTypedefSelfReference( |
| 5884 toCheck); | 5908 toCheck); |
| 5885 toCheck.add(element); | 5909 toCheck.add(element); |
| 5886 bool firstIteration = true; | 5910 bool firstIteration = true; |
| 5887 while (true) { | 5911 while (true) { |
| 5888 Element current; | 5912 Element current; |
| 5889 // get next element | 5913 // get next element |
| 5890 while (true) { | 5914 while (true) { |
| 5891 // may be no more elements to check | 5915 // may be no more elements to check |
| 5892 if (toCheck.isEmpty) { | 5916 if (toCheck.isEmpty) { |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6024 } | 6048 } |
| 6025 if (parent is CommentReference) { | 6049 if (parent is CommentReference) { |
| 6026 CommentReference commentReference = parent; | 6050 CommentReference commentReference = parent; |
| 6027 if (commentReference.newKeyword != null) { | 6051 if (commentReference.newKeyword != null) { |
| 6028 return true; | 6052 return true; |
| 6029 } | 6053 } |
| 6030 } | 6054 } |
| 6031 return false; | 6055 return false; |
| 6032 } | 6056 } |
| 6033 | 6057 |
| 6034 bool _isUserDefinedObject(EvaluationResultImpl result) => result == null || | 6058 bool _isUserDefinedObject(EvaluationResultImpl result) => |
| 6059 result == null || |
| 6035 (result.value != null && result.value.isUserDefinedObject); | 6060 (result.value != null && result.value.isUserDefinedObject); |
| 6036 | 6061 |
| 6037 /** | 6062 /** |
| 6038 * Check that the given class [element] is not a superinterface to itself. The | 6063 * Check that the given class [element] is not a superinterface to itself. The |
| 6039 * [path] is a list containing the potentially cyclic implements path. | 6064 * [path] is a list containing the potentially cyclic implements path. |
| 6040 * | 6065 * |
| 6041 * See [CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE], | 6066 * See [CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE], |
| 6042 * [CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_EXTENDS], | 6067 * [CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_EXTENDS], |
| 6043 * [CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_IMPLEMENTS]
, | 6068 * [CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_IMPLEMENTS]
, |
| 6044 * and [CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_WITH]. | 6069 * and [CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_WITH]. |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6175 toCheck.add(type.element); | 6200 toCheck.add(type.element); |
| 6176 // type arguments | 6201 // type arguments |
| 6177 if (type is InterfaceType) { | 6202 if (type is InterfaceType) { |
| 6178 InterfaceType interfaceType = type; | 6203 InterfaceType interfaceType = type; |
| 6179 for (DartType typeArgument in interfaceType.typeArguments) { | 6204 for (DartType typeArgument in interfaceType.typeArguments) { |
| 6180 _addTypeToCheck(typeArgument); | 6205 _addTypeToCheck(typeArgument); |
| 6181 } | 6206 } |
| 6182 } | 6207 } |
| 6183 } | 6208 } |
| 6184 } | 6209 } |
| OLD | NEW |