| 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 1107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1118 * See [StaticTypeWarningCode.EXPECTED_TWO_MAP_TYPE_ARGUMENTS]. | 1118 * See [StaticTypeWarningCode.EXPECTED_TWO_MAP_TYPE_ARGUMENTS]. |
| 1119 */ | 1119 */ |
| 1120 bool _checkExpectedTwoMapTypeArguments(TypeArgumentList typeArguments) { | 1120 bool _checkExpectedTwoMapTypeArguments(TypeArgumentList typeArguments) { |
| 1121 // check number of type arguments | 1121 // check number of type arguments |
| 1122 int num = typeArguments.arguments.length; | 1122 int num = typeArguments.arguments.length; |
| 1123 if (num == 2) { | 1123 if (num == 2) { |
| 1124 return false; | 1124 return false; |
| 1125 } | 1125 } |
| 1126 // report problem | 1126 // report problem |
| 1127 _errorReporter.reportErrorForNode( | 1127 _errorReporter.reportErrorForNode( |
| 1128 StaticTypeWarningCode.EXPECTED_TWO_MAP_TYPE_ARGUMENTS, typeArguments, | 1128 StaticTypeWarningCode.EXPECTED_TWO_MAP_TYPE_ARGUMENTS, |
| 1129 typeArguments, |
| 1129 [num]); | 1130 [num]); |
| 1130 return true; | 1131 return true; |
| 1131 } | 1132 } |
| 1132 | 1133 |
| 1133 /** | 1134 /** |
| 1134 * Verify that the given [constructor] declaration does not violate any of the | 1135 * Verify that the given [constructor] declaration does not violate any of the |
| 1135 * error codes relating to the initialization of fields in the enclosing | 1136 * error codes relating to the initialization of fields in the enclosing |
| 1136 * class. | 1137 * class. |
| 1137 * | 1138 * |
| 1138 * See [_initialFieldElementsMap], | 1139 * See [_initialFieldElementsMap], |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1164 if (parameter is FieldFormalParameter) { | 1165 if (parameter is FieldFormalParameter) { |
| 1165 FieldElement fieldElement = | 1166 FieldElement fieldElement = |
| 1166 (parameter.element as FieldFormalParameterElementImpl).field; | 1167 (parameter.element as FieldFormalParameterElementImpl).field; |
| 1167 INIT_STATE state = fieldElementsMap[fieldElement]; | 1168 INIT_STATE state = fieldElementsMap[fieldElement]; |
| 1168 if (state == INIT_STATE.NOT_INIT) { | 1169 if (state == INIT_STATE.NOT_INIT) { |
| 1169 fieldElementsMap[fieldElement] = INIT_STATE.INIT_IN_FIELD_FORMAL; | 1170 fieldElementsMap[fieldElement] = INIT_STATE.INIT_IN_FIELD_FORMAL; |
| 1170 } else if (state == INIT_STATE.INIT_IN_DECLARATION) { | 1171 } else if (state == INIT_STATE.INIT_IN_DECLARATION) { |
| 1171 if (fieldElement.isFinal || fieldElement.isConst) { | 1172 if (fieldElement.isFinal || fieldElement.isConst) { |
| 1172 _errorReporter.reportErrorForNode( | 1173 _errorReporter.reportErrorForNode( |
| 1173 StaticWarningCode.FINAL_INITIALIZED_IN_DECLARATION_AND_CONSTRUCT
OR, | 1174 StaticWarningCode.FINAL_INITIALIZED_IN_DECLARATION_AND_CONSTRUCT
OR, |
| 1174 formalParameter.identifier, [fieldElement.displayName]); | 1175 formalParameter.identifier, |
| 1176 [fieldElement.displayName]); |
| 1175 foundError = true; | 1177 foundError = true; |
| 1176 } | 1178 } |
| 1177 } else if (state == INIT_STATE.INIT_IN_FIELD_FORMAL) { | 1179 } else if (state == INIT_STATE.INIT_IN_FIELD_FORMAL) { |
| 1178 if (fieldElement.isFinal || fieldElement.isConst) { | 1180 if (fieldElement.isFinal || fieldElement.isConst) { |
| 1179 _errorReporter.reportErrorForNode( | 1181 _errorReporter.reportErrorForNode( |
| 1180 CompileTimeErrorCode.FINAL_INITIALIZED_MULTIPLE_TIMES, | 1182 CompileTimeErrorCode.FINAL_INITIALIZED_MULTIPLE_TIMES, |
| 1181 formalParameter.identifier, [fieldElement.displayName]); | 1183 formalParameter.identifier, |
| 1184 [fieldElement.displayName]); |
| 1182 foundError = true; | 1185 foundError = true; |
| 1183 } | 1186 } |
| 1184 } | 1187 } |
| 1185 } | 1188 } |
| 1186 } | 1189 } |
| 1187 // Visit all of the initializers | 1190 // Visit all of the initializers |
| 1188 NodeList<ConstructorInitializer> initializers = constructor.initializers; | 1191 NodeList<ConstructorInitializer> initializers = constructor.initializers; |
| 1189 for (ConstructorInitializer constructorInitializer in initializers) { | 1192 for (ConstructorInitializer constructorInitializer in initializers) { |
| 1190 if (constructorInitializer is RedirectingConstructorInvocation) { | 1193 if (constructorInitializer is RedirectingConstructorInvocation) { |
| 1191 return false; | 1194 return false; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1208 foundError = true; | 1211 foundError = true; |
| 1209 } | 1212 } |
| 1210 } else if (state == INIT_STATE.INIT_IN_FIELD_FORMAL) { | 1213 } else if (state == INIT_STATE.INIT_IN_FIELD_FORMAL) { |
| 1211 _errorReporter.reportErrorForNode( | 1214 _errorReporter.reportErrorForNode( |
| 1212 CompileTimeErrorCode.FIELD_INITIALIZED_IN_PARAMETER_AND_INITIALI
ZER, | 1215 CompileTimeErrorCode.FIELD_INITIALIZED_IN_PARAMETER_AND_INITIALI
ZER, |
| 1213 fieldName); | 1216 fieldName); |
| 1214 foundError = true; | 1217 foundError = true; |
| 1215 } else if (state == INIT_STATE.INIT_IN_INITIALIZERS) { | 1218 } else if (state == INIT_STATE.INIT_IN_INITIALIZERS) { |
| 1216 _errorReporter.reportErrorForNode( | 1219 _errorReporter.reportErrorForNode( |
| 1217 CompileTimeErrorCode.FIELD_INITIALIZED_BY_MULTIPLE_INITIALIZERS, | 1220 CompileTimeErrorCode.FIELD_INITIALIZED_BY_MULTIPLE_INITIALIZERS, |
| 1218 fieldName, [fieldElement.displayName]); | 1221 fieldName, |
| 1222 [fieldElement.displayName]); |
| 1219 foundError = true; | 1223 foundError = true; |
| 1220 } | 1224 } |
| 1221 } | 1225 } |
| 1222 } | 1226 } |
| 1223 } | 1227 } |
| 1224 // Prepare a list of not initialized fields. | 1228 // Prepare a list of not initialized fields. |
| 1225 List<FieldElement> notInitFinalFields = <FieldElement>[]; | 1229 List<FieldElement> notInitFinalFields = <FieldElement>[]; |
| 1226 fieldElementsMap.forEach((FieldElement fieldElement, INIT_STATE state) { | 1230 fieldElementsMap.forEach((FieldElement fieldElement, INIT_STATE state) { |
| 1227 if (state == INIT_STATE.NOT_INIT) { | 1231 if (state == INIT_STATE.NOT_INIT) { |
| 1228 if (fieldElement.isFinal) { | 1232 if (fieldElement.isFinal) { |
| 1229 notInitFinalFields.add(fieldElement); | 1233 notInitFinalFields.add(fieldElement); |
| 1230 } | 1234 } |
| 1231 } | 1235 } |
| 1232 }); | 1236 }); |
| 1233 // Visit all of the states in the map to ensure that none were never | 1237 // Visit all of the states in the map to ensure that none were never |
| 1234 // initialized. | 1238 // initialized. |
| 1235 fieldElementsMap.forEach((FieldElement fieldElement, INIT_STATE state) { | 1239 fieldElementsMap.forEach((FieldElement fieldElement, INIT_STATE state) { |
| 1236 if (state == INIT_STATE.NOT_INIT) { | 1240 if (state == INIT_STATE.NOT_INIT) { |
| 1237 if (fieldElement.isConst) { | 1241 if (fieldElement.isConst) { |
| 1238 _errorReporter.reportErrorForNode( | 1242 _errorReporter.reportErrorForNode( |
| 1239 CompileTimeErrorCode.CONST_NOT_INITIALIZED, | 1243 CompileTimeErrorCode.CONST_NOT_INITIALIZED, |
| 1240 constructor.returnType, [fieldElement.name]); | 1244 constructor.returnType, |
| 1245 [fieldElement.name]); |
| 1241 foundError = true; | 1246 foundError = true; |
| 1242 } | 1247 } |
| 1243 } | 1248 } |
| 1244 }); | 1249 }); |
| 1245 if (notInitFinalFields.isNotEmpty) { | 1250 if (notInitFinalFields.isNotEmpty) { |
| 1246 foundError = true; | 1251 foundError = true; |
| 1247 AnalysisErrorWithProperties analysisError; | 1252 AnalysisErrorWithProperties analysisError; |
| 1248 if (notInitFinalFields.length == 1) { | 1253 if (notInitFinalFields.length == 1) { |
| 1249 analysisError = _errorReporter.newErrorWithProperties( | 1254 analysisError = _errorReporter.newErrorWithProperties( |
| 1250 StaticWarningCode.FINAL_NOT_INITIALIZED_CONSTRUCTOR_1, | 1255 StaticWarningCode.FINAL_NOT_INITIALIZED_CONSTRUCTOR_1, |
| 1251 constructor.returnType, [notInitFinalFields[0].name]); | 1256 constructor.returnType, |
| 1257 [notInitFinalFields[0].name]); |
| 1252 } else if (notInitFinalFields.length == 2) { | 1258 } else if (notInitFinalFields.length == 2) { |
| 1253 analysisError = _errorReporter.newErrorWithProperties( | 1259 analysisError = _errorReporter.newErrorWithProperties( |
| 1254 StaticWarningCode.FINAL_NOT_INITIALIZED_CONSTRUCTOR_2, | 1260 StaticWarningCode.FINAL_NOT_INITIALIZED_CONSTRUCTOR_2, |
| 1255 constructor.returnType, [ | 1261 constructor.returnType, |
| 1256 notInitFinalFields[0].name, | 1262 [notInitFinalFields[0].name, notInitFinalFields[1].name]); |
| 1257 notInitFinalFields[1].name | |
| 1258 ]); | |
| 1259 } else { | 1263 } else { |
| 1260 analysisError = _errorReporter.newErrorWithProperties( | 1264 analysisError = _errorReporter.newErrorWithProperties( |
| 1261 StaticWarningCode.FINAL_NOT_INITIALIZED_CONSTRUCTOR_3_PLUS, | 1265 StaticWarningCode.FINAL_NOT_INITIALIZED_CONSTRUCTOR_3_PLUS, |
| 1262 constructor.returnType, [ | 1266 constructor.returnType, [ |
| 1263 notInitFinalFields[0].name, | 1267 notInitFinalFields[0].name, |
| 1264 notInitFinalFields[1].name, | 1268 notInitFinalFields[1].name, |
| 1265 notInitFinalFields.length - 2 | 1269 notInitFinalFields.length - 2 |
| 1266 ]); | 1270 ]); |
| 1267 } | 1271 } |
| 1268 analysisError.setProperty( | 1272 analysisError.setProperty( |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1285 * [StaticWarningCode.INVALID_GETTER_OVERRIDE_RETURN_TYPE], | 1289 * [StaticWarningCode.INVALID_GETTER_OVERRIDE_RETURN_TYPE], |
| 1286 * [StaticWarningCode.INVALID_METHOD_OVERRIDE_RETURN_TYPE], | 1290 * [StaticWarningCode.INVALID_METHOD_OVERRIDE_RETURN_TYPE], |
| 1287 * [StaticWarningCode.INVALID_METHOD_OVERRIDE_NORMAL_PARAM_TYPE], | 1291 * [StaticWarningCode.INVALID_METHOD_OVERRIDE_NORMAL_PARAM_TYPE], |
| 1288 * [StaticWarningCode.INVALID_SETTER_OVERRIDE_NORMAL_PARAM_TYPE], | 1292 * [StaticWarningCode.INVALID_SETTER_OVERRIDE_NORMAL_PARAM_TYPE], |
| 1289 * [StaticWarningCode.INVALID_METHOD_OVERRIDE_OPTIONAL_PARAM_TYPE], | 1293 * [StaticWarningCode.INVALID_METHOD_OVERRIDE_OPTIONAL_PARAM_TYPE], |
| 1290 * [StaticWarningCode.INVALID_METHOD_OVERRIDE_NAMED_PARAM_TYPE], and | 1294 * [StaticWarningCode.INVALID_METHOD_OVERRIDE_NAMED_PARAM_TYPE], and |
| 1291 * [StaticWarningCode.INVALID_OVERRIDE_DIFFERENT_DEFAULT_VALUES]. | 1295 * [StaticWarningCode.INVALID_OVERRIDE_DIFFERENT_DEFAULT_VALUES]. |
| 1292 */ | 1296 */ |
| 1293 bool _checkForAllInvalidOverrideErrorCodes( | 1297 bool _checkForAllInvalidOverrideErrorCodes( |
| 1294 ExecutableElement executableElement, | 1298 ExecutableElement executableElement, |
| 1295 ExecutableElement overriddenExecutable, List<ParameterElement> parameters, | 1299 ExecutableElement overriddenExecutable, |
| 1296 List<AstNode> parameterLocations, SimpleIdentifier errorNameTarget) { | 1300 List<ParameterElement> parameters, |
| 1301 List<AstNode> parameterLocations, |
| 1302 SimpleIdentifier errorNameTarget) { |
| 1297 bool isGetter = false; | 1303 bool isGetter = false; |
| 1298 bool isSetter = false; | 1304 bool isSetter = false; |
| 1299 if (executableElement is PropertyAccessorElement) { | 1305 if (executableElement is PropertyAccessorElement) { |
| 1300 PropertyAccessorElement accessorElement = executableElement; | 1306 PropertyAccessorElement accessorElement = executableElement; |
| 1301 isGetter = accessorElement.isGetter; | 1307 isGetter = accessorElement.isGetter; |
| 1302 isSetter = accessorElement.isSetter; | 1308 isSetter = accessorElement.isSetter; |
| 1303 } | 1309 } |
| 1304 String executableElementName = executableElement.name; | 1310 String executableElementName = executableElement.name; |
| 1305 FunctionType overridingFT = executableElement.type; | 1311 FunctionType overridingFT = executableElement.type; |
| 1306 FunctionType overriddenFT = overriddenExecutable.type; | 1312 FunctionType overriddenFT = overriddenExecutable.type; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1348 StaticWarningCode.INVALID_OVERRIDE_NAMED, errorNameTarget, [ | 1354 StaticWarningCode.INVALID_OVERRIDE_NAMED, errorNameTarget, [ |
| 1349 overriddenParamName, | 1355 overriddenParamName, |
| 1350 overriddenExecutable.enclosingElement.displayName | 1356 overriddenExecutable.enclosingElement.displayName |
| 1351 ]); | 1357 ]); |
| 1352 return true; | 1358 return true; |
| 1353 } | 1359 } |
| 1354 } | 1360 } |
| 1355 // SWC.INVALID_METHOD_OVERRIDE_RETURN_TYPE | 1361 // SWC.INVALID_METHOD_OVERRIDE_RETURN_TYPE |
| 1356 if (overriddenFTReturnType != VoidTypeImpl.instance && | 1362 if (overriddenFTReturnType != VoidTypeImpl.instance && |
| 1357 !overridingFTReturnType.isAssignableTo(overriddenFTReturnType)) { | 1363 !overridingFTReturnType.isAssignableTo(overriddenFTReturnType)) { |
| 1358 _errorReporter.reportTypeErrorForNode(!isGetter | 1364 _errorReporter.reportTypeErrorForNode( |
| 1365 !isGetter |
| 1359 ? StaticWarningCode.INVALID_METHOD_OVERRIDE_RETURN_TYPE | 1366 ? StaticWarningCode.INVALID_METHOD_OVERRIDE_RETURN_TYPE |
| 1360 : StaticWarningCode.INVALID_GETTER_OVERRIDE_RETURN_TYPE, | 1367 : StaticWarningCode.INVALID_GETTER_OVERRIDE_RETURN_TYPE, |
| 1361 errorNameTarget, [ | 1368 errorNameTarget, |
| 1369 [ |
| 1362 overridingFTReturnType, | 1370 overridingFTReturnType, |
| 1363 overriddenFTReturnType, | 1371 overriddenFTReturnType, |
| 1364 overriddenExecutable.enclosingElement.displayName | 1372 overriddenExecutable.enclosingElement.displayName |
| 1365 ]); | 1373 ]); |
| 1366 return true; | 1374 return true; |
| 1367 } | 1375 } |
| 1368 // SWC.INVALID_METHOD_OVERRIDE_NORMAL_PARAM_TYPE | 1376 // SWC.INVALID_METHOD_OVERRIDE_NORMAL_PARAM_TYPE |
| 1369 if (parameterLocations == null) { | 1377 if (parameterLocations == null) { |
| 1370 return false; | 1378 return false; |
| 1371 } | 1379 } |
| 1372 int parameterIndex = 0; | 1380 int parameterIndex = 0; |
| 1373 for (int i = 0; i < overridingNormalPT.length; i++) { | 1381 for (int i = 0; i < overridingNormalPT.length; i++) { |
| 1374 if (!overridingNormalPT[i].isAssignableTo(overriddenNormalPT[i])) { | 1382 if (!overridingNormalPT[i].isAssignableTo(overriddenNormalPT[i])) { |
| 1375 _errorReporter.reportTypeErrorForNode(!isSetter | 1383 _errorReporter.reportTypeErrorForNode( |
| 1384 !isSetter |
| 1376 ? StaticWarningCode.INVALID_METHOD_OVERRIDE_NORMAL_PARAM_TYPE | 1385 ? StaticWarningCode.INVALID_METHOD_OVERRIDE_NORMAL_PARAM_TYPE |
| 1377 : StaticWarningCode.INVALID_SETTER_OVERRIDE_NORMAL_PARAM_TYPE, | 1386 : StaticWarningCode.INVALID_SETTER_OVERRIDE_NORMAL_PARAM_TYPE, |
| 1378 parameterLocations[parameterIndex], [ | 1387 parameterLocations[parameterIndex], |
| 1388 [ |
| 1379 overridingNormalPT[i], | 1389 overridingNormalPT[i], |
| 1380 overriddenNormalPT[i], | 1390 overriddenNormalPT[i], |
| 1381 overriddenExecutable.enclosingElement.displayName | 1391 overriddenExecutable.enclosingElement.displayName |
| 1382 ]); | 1392 ]); |
| 1383 return true; | 1393 return true; |
| 1384 } | 1394 } |
| 1385 parameterIndex++; | 1395 parameterIndex++; |
| 1386 } | 1396 } |
| 1387 // SWC.INVALID_METHOD_OVERRIDE_OPTIONAL_PARAM_TYPE | 1397 // SWC.INVALID_METHOD_OVERRIDE_OPTIONAL_PARAM_TYPE |
| 1388 for (int i = 0; i < overriddenPositionalPT.length; i++) { | 1398 for (int i = 0; i < overriddenPositionalPT.length; i++) { |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1548 /** | 1558 /** |
| 1549 * Check the given [executableElement] against override-error codes. This | 1559 * Check the given [executableElement] against override-error codes. This |
| 1550 * method computes the given executableElement is overriding and calls | 1560 * method computes the given executableElement is overriding and calls |
| 1551 * [_checkForAllInvalidOverrideErrorCodes] when the [InheritanceManager] | 1561 * [_checkForAllInvalidOverrideErrorCodes] when the [InheritanceManager] |
| 1552 * returns a [MultiplyInheritedExecutableElement], this method loops through | 1562 * returns a [MultiplyInheritedExecutableElement], this method loops through |
| 1553 * the list in the [MultiplyInheritedExecutableElement]. The [parameters] are | 1563 * the list in the [MultiplyInheritedExecutableElement]. The [parameters] are |
| 1554 * the parameters of the executable element. The [errorNameTarget] is the node | 1564 * the parameters of the executable element. The [errorNameTarget] is the node |
| 1555 * to report problems on. | 1565 * to report problems on. |
| 1556 */ | 1566 */ |
| 1557 bool _checkForAllInvalidOverrideErrorCodesForExecutable( | 1567 bool _checkForAllInvalidOverrideErrorCodesForExecutable( |
| 1558 ExecutableElement executableElement, List<ParameterElement> parameters, | 1568 ExecutableElement executableElement, |
| 1559 List<AstNode> parameterLocations, SimpleIdentifier errorNameTarget) { | 1569 List<ParameterElement> parameters, |
| 1570 List<AstNode> parameterLocations, |
| 1571 SimpleIdentifier errorNameTarget) { |
| 1560 // | 1572 // |
| 1561 // Compute the overridden executable from the InheritanceManager | 1573 // Compute the overridden executable from the InheritanceManager |
| 1562 // | 1574 // |
| 1563 List<ExecutableElement> overriddenExecutables = _inheritanceManager | 1575 List<ExecutableElement> overriddenExecutables = _inheritanceManager |
| 1564 .lookupOverrides(_enclosingClass, executableElement.name); | 1576 .lookupOverrides(_enclosingClass, executableElement.name); |
| 1565 if (_checkForInstanceMethodNameCollidesWithSuperclassStatic( | 1577 if (_checkForInstanceMethodNameCollidesWithSuperclassStatic( |
| 1566 executableElement, errorNameTarget)) { | 1578 executableElement, errorNameTarget)) { |
| 1567 return true; | 1579 return true; |
| 1568 } | 1580 } |
| 1569 for (ExecutableElement overriddenElement in overriddenExecutables) { | 1581 for (ExecutableElement overriddenElement in overriddenExecutables) { |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1714 // | 1726 // |
| 1715 // Prepare the constructor name | 1727 // Prepare the constructor name |
| 1716 // | 1728 // |
| 1717 String constructorStrName = constructorTypeName.name.name; | 1729 String constructorStrName = constructorTypeName.name.name; |
| 1718 if (redirectedConstructor.name != null) { | 1730 if (redirectedConstructor.name != null) { |
| 1719 constructorStrName += ".${redirectedConstructor.name.name}"; | 1731 constructorStrName += ".${redirectedConstructor.name.name}"; |
| 1720 } | 1732 } |
| 1721 ErrorCode errorCode = (declaration.constKeyword != null | 1733 ErrorCode errorCode = (declaration.constKeyword != null |
| 1722 ? CompileTimeErrorCode.REDIRECT_TO_MISSING_CONSTRUCTOR | 1734 ? CompileTimeErrorCode.REDIRECT_TO_MISSING_CONSTRUCTOR |
| 1723 : StaticWarningCode.REDIRECT_TO_MISSING_CONSTRUCTOR); | 1735 : StaticWarningCode.REDIRECT_TO_MISSING_CONSTRUCTOR); |
| 1724 _errorReporter.reportErrorForNode(errorCode, redirectedConstructor, [ | 1736 _errorReporter.reportErrorForNode(errorCode, redirectedConstructor, |
| 1725 constructorStrName, | 1737 [constructorStrName, redirectedType.displayName]); |
| 1726 redirectedType.displayName | |
| 1727 ]); | |
| 1728 return true; | 1738 return true; |
| 1729 } | 1739 } |
| 1730 return false; | 1740 return false; |
| 1731 } | 1741 } |
| 1732 FunctionType redirectedType = redirectedElement.type; | 1742 FunctionType redirectedType = redirectedElement.type; |
| 1733 DartType redirectedReturnType = redirectedType.returnType; | 1743 DartType redirectedReturnType = redirectedType.returnType; |
| 1734 // | 1744 // |
| 1735 // Report specific problem when return type is incompatible | 1745 // Report specific problem when return type is incompatible |
| 1736 // | 1746 // |
| 1737 FunctionType constructorType = declaration.element.type; | 1747 FunctionType constructorType = declaration.element.type; |
| 1738 DartType constructorReturnType = constructorType.returnType; | 1748 DartType constructorReturnType = constructorType.returnType; |
| 1739 if (!redirectedReturnType.isAssignableTo(constructorReturnType)) { | 1749 if (!redirectedReturnType.isAssignableTo(constructorReturnType)) { |
| 1740 _errorReporter.reportErrorForNode( | 1750 _errorReporter.reportErrorForNode( |
| 1741 StaticWarningCode.REDIRECT_TO_INVALID_RETURN_TYPE, | 1751 StaticWarningCode.REDIRECT_TO_INVALID_RETURN_TYPE, |
| 1742 redirectedConstructor, [redirectedReturnType, constructorReturnType]); | 1752 redirectedConstructor, |
| 1753 [redirectedReturnType, constructorReturnType]); |
| 1743 return true; | 1754 return true; |
| 1744 } | 1755 } |
| 1745 // | 1756 // |
| 1746 // Check parameters | 1757 // Check parameters |
| 1747 // | 1758 // |
| 1748 if (!redirectedType.isSubtypeOf(constructorType)) { | 1759 if (!redirectedType.isSubtypeOf(constructorType)) { |
| 1749 _errorReporter.reportErrorForNode( | 1760 _errorReporter.reportErrorForNode( |
| 1750 StaticWarningCode.REDIRECT_TO_INVALID_FUNCTION_TYPE, | 1761 StaticWarningCode.REDIRECT_TO_INVALID_FUNCTION_TYPE, |
| 1751 redirectedConstructor, [redirectedType, constructorType]); | 1762 redirectedConstructor, |
| 1763 [redirectedType, constructorType]); |
| 1752 return true; | 1764 return true; |
| 1753 } | 1765 } |
| 1754 return false; | 1766 return false; |
| 1755 } | 1767 } |
| 1756 | 1768 |
| 1757 /** | 1769 /** |
| 1758 * Check that the return [statement] of the form <i>return e;</i> is not in a | 1770 * Check that the return [statement] of the form <i>return e;</i> is not in a |
| 1759 * generative constructor. | 1771 * generative constructor. |
| 1760 * | 1772 * |
| 1761 * Check that return statements without expressions are not in a generative | 1773 * Check that return statements without expressions are not in a generative |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1823 return false; | 1835 return false; |
| 1824 } | 1836 } |
| 1825 // check exported names | 1837 // check exported names |
| 1826 Namespace namespace = | 1838 Namespace namespace = |
| 1827 new NamespaceBuilder().createExportNamespaceForDirective(exportElement); | 1839 new NamespaceBuilder().createExportNamespaceForDirective(exportElement); |
| 1828 Map<String, Element> definedNames = namespace.definedNames; | 1840 Map<String, Element> definedNames = namespace.definedNames; |
| 1829 for (String name in definedNames.keys) { | 1841 for (String name in definedNames.keys) { |
| 1830 Element element = definedNames[name]; | 1842 Element element = definedNames[name]; |
| 1831 Element prevElement = _exportedElements[name]; | 1843 Element prevElement = _exportedElements[name]; |
| 1832 if (element != null && prevElement != null && prevElement != element) { | 1844 if (element != null && prevElement != null && prevElement != element) { |
| 1833 _errorReporter.reportErrorForNode(CompileTimeErrorCode.AMBIGUOUS_EXPORT, | 1845 _errorReporter.reportErrorForNode( |
| 1834 directive, [ | 1846 CompileTimeErrorCode.AMBIGUOUS_EXPORT, directive, [ |
| 1835 name, | 1847 name, |
| 1836 prevElement.library.definingCompilationUnit.displayName, | 1848 prevElement.library.definingCompilationUnit.displayName, |
| 1837 element.library.definingCompilationUnit.displayName | 1849 element.library.definingCompilationUnit.displayName |
| 1838 ]); | 1850 ]); |
| 1839 return true; | 1851 return true; |
| 1840 } else { | 1852 } else { |
| 1841 _exportedElements[name] = element; | 1853 _exportedElements[name] = element; |
| 1842 } | 1854 } |
| 1843 } | 1855 } |
| 1844 return false; | 1856 return false; |
| 1845 } | 1857 } |
| 1846 | 1858 |
| 1847 /** | 1859 /** |
| 1848 * Verify that the given [expression] can be assigned to its corresponding | 1860 * Verify that the given [expression] can be assigned to its corresponding |
| 1849 * parameters. The [expectedStaticType] is the expected static type of the | 1861 * parameters. The [expectedStaticType] is the expected static type of the |
| 1850 * parameter. The [actualStaticType] is the actual static type of the | 1862 * parameter. The [actualStaticType] is the actual static type of the |
| 1851 * argument. | 1863 * argument. |
| 1852 * | 1864 * |
| 1853 * This method corresponds to | 1865 * This method corresponds to |
| 1854 * [BestPracticesVerifier.checkForArgumentTypeNotAssignable]. | 1866 * [BestPracticesVerifier.checkForArgumentTypeNotAssignable]. |
| 1855 * | 1867 * |
| 1856 * See [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE], | 1868 * See [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE], |
| 1857 * [CompileTimeErrorCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE], | 1869 * [CompileTimeErrorCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE], |
| 1858 * [StaticWarningCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE], | 1870 * [StaticWarningCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE], |
| 1859 * [CompileTimeErrorCode.MAP_KEY_TYPE_NOT_ASSIGNABLE], | 1871 * [CompileTimeErrorCode.MAP_KEY_TYPE_NOT_ASSIGNABLE], |
| 1860 * [CompileTimeErrorCode.MAP_VALUE_TYPE_NOT_ASSIGNABLE], | 1872 * [CompileTimeErrorCode.MAP_VALUE_TYPE_NOT_ASSIGNABLE], |
| 1861 * [StaticWarningCode.MAP_KEY_TYPE_NOT_ASSIGNABLE], and | 1873 * [StaticWarningCode.MAP_KEY_TYPE_NOT_ASSIGNABLE], and |
| 1862 * [StaticWarningCode.MAP_VALUE_TYPE_NOT_ASSIGNABLE]. | 1874 * [StaticWarningCode.MAP_VALUE_TYPE_NOT_ASSIGNABLE]. |
| 1863 */ | 1875 */ |
| 1864 bool _checkForArgumentTypeNotAssignable(Expression expression, | 1876 bool _checkForArgumentTypeNotAssignable( |
| 1865 DartType expectedStaticType, DartType actualStaticType, | 1877 Expression expression, |
| 1878 DartType expectedStaticType, |
| 1879 DartType actualStaticType, |
| 1866 ErrorCode errorCode) { | 1880 ErrorCode errorCode) { |
| 1867 // | 1881 // |
| 1868 // Warning case: test static type information | 1882 // Warning case: test static type information |
| 1869 // | 1883 // |
| 1870 if (actualStaticType != null && expectedStaticType != null) { | 1884 if (actualStaticType != null && expectedStaticType != null) { |
| 1871 if (!actualStaticType.isAssignableTo(expectedStaticType)) { | 1885 if (!actualStaticType.isAssignableTo(expectedStaticType)) { |
| 1872 _errorReporter.reportTypeErrorForNode( | 1886 _errorReporter.reportTypeErrorForNode( |
| 1873 errorCode, expression, [actualStaticType, expectedStaticType]); | 1887 errorCode, expression, [actualStaticType, expectedStaticType]); |
| 1874 return true; | 1888 return true; |
| 1875 } | 1889 } |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1906 * | 1920 * |
| 1907 * See [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE], | 1921 * See [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE], |
| 1908 * [CompileTimeErrorCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE], | 1922 * [CompileTimeErrorCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE], |
| 1909 * [StaticWarningCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE], | 1923 * [StaticWarningCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE], |
| 1910 * [CompileTimeErrorCode.MAP_KEY_TYPE_NOT_ASSIGNABLE], | 1924 * [CompileTimeErrorCode.MAP_KEY_TYPE_NOT_ASSIGNABLE], |
| 1911 * [CompileTimeErrorCode.MAP_VALUE_TYPE_NOT_ASSIGNABLE], | 1925 * [CompileTimeErrorCode.MAP_VALUE_TYPE_NOT_ASSIGNABLE], |
| 1912 * [StaticWarningCode.MAP_KEY_TYPE_NOT_ASSIGNABLE], and | 1926 * [StaticWarningCode.MAP_KEY_TYPE_NOT_ASSIGNABLE], and |
| 1913 * [StaticWarningCode.MAP_VALUE_TYPE_NOT_ASSIGNABLE]. | 1927 * [StaticWarningCode.MAP_VALUE_TYPE_NOT_ASSIGNABLE]. |
| 1914 */ | 1928 */ |
| 1915 bool _checkForArgumentTypeNotAssignableWithExpectedTypes( | 1929 bool _checkForArgumentTypeNotAssignableWithExpectedTypes( |
| 1916 Expression expression, DartType expectedStaticType, | 1930 Expression expression, |
| 1917 ErrorCode errorCode) => _checkForArgumentTypeNotAssignable( | 1931 DartType expectedStaticType, |
| 1932 ErrorCode errorCode) => |
| 1933 _checkForArgumentTypeNotAssignable( |
| 1918 expression, expectedStaticType, getStaticType(expression), errorCode); | 1934 expression, expectedStaticType, getStaticType(expression), errorCode); |
| 1919 | 1935 |
| 1920 /** | 1936 /** |
| 1921 * Verify that the arguments in the given [argumentList] can be assigned to | 1937 * Verify that the arguments in the given [argumentList] can be assigned to |
| 1922 * their corresponding parameters. | 1938 * their corresponding parameters. |
| 1923 * | 1939 * |
| 1924 * This method corresponds to | 1940 * This method corresponds to |
| 1925 * [BestPracticesVerifier.checkForArgumentTypesNotAssignableInList]. | 1941 * [BestPracticesVerifier.checkForArgumentTypesNotAssignableInList]. |
| 1926 * | 1942 * |
| 1927 * See [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]. | 1943 * See [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]. |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1992 if (element.isConst) { | 2008 if (element.isConst) { |
| 1993 _errorReporter.reportErrorForNode( | 2009 _errorReporter.reportErrorForNode( |
| 1994 StaticWarningCode.ASSIGNMENT_TO_CONST, expression); | 2010 StaticWarningCode.ASSIGNMENT_TO_CONST, expression); |
| 1995 return true; | 2011 return true; |
| 1996 } | 2012 } |
| 1997 if (element.isFinal) { | 2013 if (element.isFinal) { |
| 1998 if (element is FieldElementImpl && | 2014 if (element is FieldElementImpl && |
| 1999 element.setter == null && | 2015 element.setter == null && |
| 2000 element.isSynthetic) { | 2016 element.isSynthetic) { |
| 2001 _errorReporter.reportErrorForNode( | 2017 _errorReporter.reportErrorForNode( |
| 2002 StaticWarningCode.ASSIGNMENT_TO_FINAL_NO_SETTER, highlightedNode, | 2018 StaticWarningCode.ASSIGNMENT_TO_FINAL_NO_SETTER, |
| 2019 highlightedNode, |
| 2003 [element.name, element.enclosingElement.displayName]); | 2020 [element.name, element.enclosingElement.displayName]); |
| 2004 return true; | 2021 return true; |
| 2005 } | 2022 } |
| 2006 _errorReporter.reportErrorForNode(StaticWarningCode.ASSIGNMENT_TO_FINAL, | 2023 _errorReporter.reportErrorForNode(StaticWarningCode.ASSIGNMENT_TO_FINAL, |
| 2007 highlightedNode, [element.name]); | 2024 highlightedNode, [element.name]); |
| 2008 return true; | 2025 return true; |
| 2009 } | 2026 } |
| 2010 return false; | 2027 return false; |
| 2011 } | 2028 } |
| 2012 if (element is FunctionElement) { | 2029 if (element is FunctionElement) { |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2127 memberName, _currentLibrary); | 2144 memberName, _currentLibrary); |
| 2128 } else if (method.isSetter) { | 2145 } else if (method.isSetter) { |
| 2129 overriddenMember = _enclosingClass.lookUpInheritedConcreteSetter( | 2146 overriddenMember = _enclosingClass.lookUpInheritedConcreteSetter( |
| 2130 memberName, _currentLibrary); | 2147 memberName, _currentLibrary); |
| 2131 } else { | 2148 } else { |
| 2132 overriddenMember = _enclosingClass.lookUpInheritedConcreteMethod( | 2149 overriddenMember = _enclosingClass.lookUpInheritedConcreteMethod( |
| 2133 memberName, _currentLibrary); | 2150 memberName, _currentLibrary); |
| 2134 } | 2151 } |
| 2135 if (overriddenMember == null) { | 2152 if (overriddenMember == null) { |
| 2136 _errorReporter.reportErrorForNode( | 2153 _errorReporter.reportErrorForNode( |
| 2137 StaticWarningCode.CONCRETE_CLASS_WITH_ABSTRACT_MEMBER, nameNode, [ | 2154 StaticWarningCode.CONCRETE_CLASS_WITH_ABSTRACT_MEMBER, |
| 2138 memberName, | 2155 nameNode, |
| 2139 _enclosingClass.displayName | 2156 [memberName, _enclosingClass.displayName]); |
| 2140 ]); | |
| 2141 return true; | 2157 return true; |
| 2142 } | 2158 } |
| 2143 } | 2159 } |
| 2144 return false; | 2160 return false; |
| 2145 } | 2161 } |
| 2146 | 2162 |
| 2147 /** | 2163 /** |
| 2148 * Verify all possible conflicts of the given [constructor]'s name with other | 2164 * Verify all possible conflicts of the given [constructor]'s name with other |
| 2149 * constructors and members of the same class. The [constructorElement] is the | 2165 * constructors and members of the same class. The [constructorElement] is the |
| 2150 * constructor's element. | 2166 * constructor's element. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 2165 for (ConstructorElement otherConstructor in constructors) { | 2181 for (ConstructorElement otherConstructor in constructors) { |
| 2166 if (identical(otherConstructor, constructorElement)) { | 2182 if (identical(otherConstructor, constructorElement)) { |
| 2167 continue; | 2183 continue; |
| 2168 } | 2184 } |
| 2169 if (name == otherConstructor.name) { | 2185 if (name == otherConstructor.name) { |
| 2170 if (name == null || name.length == 0) { | 2186 if (name == null || name.length == 0) { |
| 2171 _errorReporter.reportErrorForNode( | 2187 _errorReporter.reportErrorForNode( |
| 2172 CompileTimeErrorCode.DUPLICATE_CONSTRUCTOR_DEFAULT, constructor); | 2188 CompileTimeErrorCode.DUPLICATE_CONSTRUCTOR_DEFAULT, constructor); |
| 2173 } else { | 2189 } else { |
| 2174 _errorReporter.reportErrorForNode( | 2190 _errorReporter.reportErrorForNode( |
| 2175 CompileTimeErrorCode.DUPLICATE_CONSTRUCTOR_NAME, constructor, | 2191 CompileTimeErrorCode.DUPLICATE_CONSTRUCTOR_NAME, |
| 2192 constructor, |
| 2176 [name]); | 2193 [name]); |
| 2177 } | 2194 } |
| 2178 return true; | 2195 return true; |
| 2179 } | 2196 } |
| 2180 } | 2197 } |
| 2181 // conflict with class member | 2198 // conflict with class member |
| 2182 if (constructorName != null && | 2199 if (constructorName != null && |
| 2183 constructorElement != null && | 2200 constructorElement != null && |
| 2184 !constructorName.isSynthetic) { | 2201 !constructorName.isSynthetic) { |
| 2185 // fields | 2202 // fields |
| 2186 FieldElement field = classElement.getField(name); | 2203 FieldElement field = classElement.getField(name); |
| 2187 if (field != null) { | 2204 if (field != null) { |
| 2188 _errorReporter.reportErrorForNode( | 2205 _errorReporter.reportErrorForNode( |
| 2189 CompileTimeErrorCode.CONFLICTING_CONSTRUCTOR_NAME_AND_FIELD, | 2206 CompileTimeErrorCode.CONFLICTING_CONSTRUCTOR_NAME_AND_FIELD, |
| 2190 constructor, [name]); | 2207 constructor, |
| 2208 [name]); |
| 2191 return true; | 2209 return true; |
| 2192 } | 2210 } |
| 2193 // methods | 2211 // methods |
| 2194 MethodElement method = classElement.getMethod(name); | 2212 MethodElement method = classElement.getMethod(name); |
| 2195 if (method != null) { | 2213 if (method != null) { |
| 2196 _errorReporter.reportErrorForNode( | 2214 _errorReporter.reportErrorForNode( |
| 2197 CompileTimeErrorCode.CONFLICTING_CONSTRUCTOR_NAME_AND_METHOD, | 2215 CompileTimeErrorCode.CONFLICTING_CONSTRUCTOR_NAME_AND_METHOD, |
| 2198 constructor, [name]); | 2216 constructor, |
| 2217 [name]); |
| 2199 return true; | 2218 return true; |
| 2200 } | 2219 } |
| 2201 } | 2220 } |
| 2202 return false; | 2221 return false; |
| 2203 } | 2222 } |
| 2204 | 2223 |
| 2205 /** | 2224 /** |
| 2206 * Verify that the [_enclosingClass] does not have a method and getter pair | 2225 * Verify that the [_enclosingClass] does not have a method and getter pair |
| 2207 * with the same name on, via inheritance. | 2226 * with the same name on, via inheritance. |
| 2208 * | 2227 * |
| (...skipping 10 matching lines...) Expand all Loading... |
| 2219 String name = method.name; | 2238 String name = method.name; |
| 2220 // find inherited property accessor (and can be only getter) | 2239 // find inherited property accessor (and can be only getter) |
| 2221 ExecutableElement inherited = | 2240 ExecutableElement inherited = |
| 2222 _inheritanceManager.lookupInheritance(_enclosingClass, name); | 2241 _inheritanceManager.lookupInheritance(_enclosingClass, name); |
| 2223 if (inherited is! PropertyAccessorElement) { | 2242 if (inherited is! PropertyAccessorElement) { |
| 2224 continue; | 2243 continue; |
| 2225 } | 2244 } |
| 2226 // report problem | 2245 // report problem |
| 2227 hasProblem = true; | 2246 hasProblem = true; |
| 2228 _errorReporter.reportErrorForOffset( | 2247 _errorReporter.reportErrorForOffset( |
| 2229 CompileTimeErrorCode.CONFLICTING_GETTER_AND_METHOD, method.nameOffset, | 2248 CompileTimeErrorCode.CONFLICTING_GETTER_AND_METHOD, |
| 2249 method.nameOffset, |
| 2230 name.length, [ | 2250 name.length, [ |
| 2231 _enclosingClass.displayName, | 2251 _enclosingClass.displayName, |
| 2232 inherited.enclosingElement.displayName, | 2252 inherited.enclosingElement.displayName, |
| 2233 name | 2253 name |
| 2234 ]); | 2254 ]); |
| 2235 } | 2255 } |
| 2236 // getter declared in the enclosing class vs. inherited method | 2256 // getter declared in the enclosing class vs. inherited method |
| 2237 for (PropertyAccessorElement accessor in _enclosingClass.accessors) { | 2257 for (PropertyAccessorElement accessor in _enclosingClass.accessors) { |
| 2238 if (!accessor.isGetter) { | 2258 if (!accessor.isGetter) { |
| 2239 continue; | 2259 continue; |
| 2240 } | 2260 } |
| 2241 String name = accessor.name; | 2261 String name = accessor.name; |
| 2242 // find inherited method | 2262 // find inherited method |
| 2243 ExecutableElement inherited = | 2263 ExecutableElement inherited = |
| 2244 _inheritanceManager.lookupInheritance(_enclosingClass, name); | 2264 _inheritanceManager.lookupInheritance(_enclosingClass, name); |
| 2245 if (inherited is! MethodElement) { | 2265 if (inherited is! MethodElement) { |
| 2246 continue; | 2266 continue; |
| 2247 } | 2267 } |
| 2248 // report problem | 2268 // report problem |
| 2249 hasProblem = true; | 2269 hasProblem = true; |
| 2250 _errorReporter.reportErrorForOffset( | 2270 _errorReporter.reportErrorForOffset( |
| 2251 CompileTimeErrorCode.CONFLICTING_METHOD_AND_GETTER, | 2271 CompileTimeErrorCode.CONFLICTING_METHOD_AND_GETTER, |
| 2252 accessor.nameOffset, name.length, [ | 2272 accessor.nameOffset, |
| 2273 name.length, [ |
| 2253 _enclosingClass.displayName, | 2274 _enclosingClass.displayName, |
| 2254 inherited.enclosingElement.displayName, | 2275 inherited.enclosingElement.displayName, |
| 2255 name | 2276 name |
| 2256 ]); | 2277 ]); |
| 2257 } | 2278 } |
| 2258 // done | 2279 // done |
| 2259 return hasProblem; | 2280 return hasProblem; |
| 2260 } | 2281 } |
| 2261 | 2282 |
| 2262 /** | 2283 /** |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2308 } | 2329 } |
| 2309 // prepare "super" type to report its name | 2330 // prepare "super" type to report its name |
| 2310 ClassElement superElementClass = | 2331 ClassElement superElementClass = |
| 2311 superElement.enclosingElement as ClassElement; | 2332 superElement.enclosingElement as ClassElement; |
| 2312 InterfaceType superElementType = superElementClass.type; | 2333 InterfaceType superElementType = superElementClass.type; |
| 2313 // report problem | 2334 // report problem |
| 2314 hasProblem = true; | 2335 hasProblem = true; |
| 2315 if (getter) { | 2336 if (getter) { |
| 2316 _errorReporter.reportErrorForElement( | 2337 _errorReporter.reportErrorForElement( |
| 2317 StaticWarningCode.CONFLICTING_INSTANCE_GETTER_AND_SUPERCLASS_MEMBER, | 2338 StaticWarningCode.CONFLICTING_INSTANCE_GETTER_AND_SUPERCLASS_MEMBER, |
| 2318 accessor, [superElementType.displayName]); | 2339 accessor, |
| 2340 [superElementType.displayName]); |
| 2319 } else { | 2341 } else { |
| 2320 _errorReporter.reportErrorForElement( | 2342 _errorReporter.reportErrorForElement( |
| 2321 StaticWarningCode.CONFLICTING_INSTANCE_SETTER_AND_SUPERCLASS_MEMBER, | 2343 StaticWarningCode.CONFLICTING_INSTANCE_SETTER_AND_SUPERCLASS_MEMBER, |
| 2322 accessor, [superElementType.displayName]); | 2344 accessor, |
| 2345 [superElementType.displayName]); |
| 2323 } | 2346 } |
| 2324 } | 2347 } |
| 2325 // done | 2348 // done |
| 2326 return hasProblem; | 2349 return hasProblem; |
| 2327 } | 2350 } |
| 2328 | 2351 |
| 2329 /** | 2352 /** |
| 2330 * Verify that the enclosing class does not have a setter with the same name | 2353 * Verify that the enclosing class does not have a setter with the same name |
| 2331 * as the given instance method declaration. | 2354 * as the given instance method declaration. |
| 2332 * | 2355 * |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2394 addThisMemberToTheMap = false; | 2417 addThisMemberToTheMap = false; |
| 2395 } | 2418 } |
| 2396 } else if (isSetter) { | 2419 } else if (isSetter) { |
| 2397 String methodName = name.name; | 2420 String methodName = name.name; |
| 2398 ClassMember conflictingMethod = memberHashMap[methodName]; | 2421 ClassMember conflictingMethod = memberHashMap[methodName]; |
| 2399 if (conflictingMethod != null && | 2422 if (conflictingMethod != null && |
| 2400 conflictingMethod is MethodDeclaration && | 2423 conflictingMethod is MethodDeclaration && |
| 2401 !conflictingMethod.isGetter) { | 2424 !conflictingMethod.isGetter) { |
| 2402 // report problem | 2425 // report problem |
| 2403 _errorReporter.reportErrorForNode( | 2426 _errorReporter.reportErrorForNode( |
| 2404 StaticWarningCode.CONFLICTING_INSTANCE_METHOD_SETTER2, name, [ | 2427 StaticWarningCode.CONFLICTING_INSTANCE_METHOD_SETTER2, |
| 2405 _enclosingClass.displayName, | 2428 name, |
| 2406 name.name | 2429 [_enclosingClass.displayName, name.name]); |
| 2407 ]); | |
| 2408 foundError = true; | 2430 foundError = true; |
| 2409 addThisMemberToTheMap = false; | 2431 addThisMemberToTheMap = false; |
| 2410 } | 2432 } |
| 2411 } | 2433 } |
| 2412 // Finally, add this member into the HashMap. | 2434 // Finally, add this member into the HashMap. |
| 2413 if (addThisMemberToTheMap) { | 2435 if (addThisMemberToTheMap) { |
| 2414 if (method.isSetter) { | 2436 if (method.isSetter) { |
| 2415 memberHashMap["${name.name}="] = method; | 2437 memberHashMap["${name.name}="] = method; |
| 2416 } else { | 2438 } else { |
| 2417 memberHashMap[name.name] = method; | 2439 memberHashMap[name.name] = method; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2453 // OK, also static | 2475 // OK, also static |
| 2454 if (setter.isStatic) { | 2476 if (setter.isStatic) { |
| 2455 return false; | 2477 return false; |
| 2456 } | 2478 } |
| 2457 // prepare "setter" type to report its name | 2479 // prepare "setter" type to report its name |
| 2458 ClassElement setterClass = setter.enclosingElement as ClassElement; | 2480 ClassElement setterClass = setter.enclosingElement as ClassElement; |
| 2459 InterfaceType setterType = setterClass.type; | 2481 InterfaceType setterType = setterClass.type; |
| 2460 // report problem | 2482 // report problem |
| 2461 _errorReporter.reportErrorForNode( | 2483 _errorReporter.reportErrorForNode( |
| 2462 StaticWarningCode.CONFLICTING_STATIC_GETTER_AND_INSTANCE_SETTER, | 2484 StaticWarningCode.CONFLICTING_STATIC_GETTER_AND_INSTANCE_SETTER, |
| 2463 nameNode, [setterType.displayName]); | 2485 nameNode, |
| 2486 [setterType.displayName]); |
| 2464 return true; | 2487 return true; |
| 2465 } | 2488 } |
| 2466 | 2489 |
| 2467 /** | 2490 /** |
| 2468 * Verify that the enclosing class does not have an instance member with the | 2491 * Verify that the enclosing class does not have an instance member with the |
| 2469 * same name as the given static [method] declaration. | 2492 * same name as the given static [method] declaration. |
| 2470 * | 2493 * |
| 2471 * See [StaticWarningCode.CONFLICTING_STATIC_SETTER_AND_INSTANCE_MEMBER]. | 2494 * See [StaticWarningCode.CONFLICTING_STATIC_SETTER_AND_INSTANCE_MEMBER]. |
| 2472 */ | 2495 */ |
| 2473 bool _checkForConflictingStaticSetterAndInstanceMember( | 2496 bool _checkForConflictingStaticSetterAndInstanceMember( |
| (...skipping 27 matching lines...) Expand all Loading... |
| 2501 // OK, also static | 2524 // OK, also static |
| 2502 if (member.isStatic) { | 2525 if (member.isStatic) { |
| 2503 return false; | 2526 return false; |
| 2504 } | 2527 } |
| 2505 // prepare "member" type to report its name | 2528 // prepare "member" type to report its name |
| 2506 ClassElement memberClass = member.enclosingElement as ClassElement; | 2529 ClassElement memberClass = member.enclosingElement as ClassElement; |
| 2507 InterfaceType memberType = memberClass.type; | 2530 InterfaceType memberType = memberClass.type; |
| 2508 // report problem | 2531 // report problem |
| 2509 _errorReporter.reportErrorForNode( | 2532 _errorReporter.reportErrorForNode( |
| 2510 StaticWarningCode.CONFLICTING_STATIC_SETTER_AND_INSTANCE_MEMBER, | 2533 StaticWarningCode.CONFLICTING_STATIC_SETTER_AND_INSTANCE_MEMBER, |
| 2511 nameNode, [memberType.displayName]); | 2534 nameNode, |
| 2535 [memberType.displayName]); |
| 2512 return true; | 2536 return true; |
| 2513 } | 2537 } |
| 2514 | 2538 |
| 2515 /** | 2539 /** |
| 2516 * Verify all conflicts between type variable and enclosing class. | 2540 * Verify all conflicts between type variable and enclosing class. |
| 2517 * TODO(scheglov) | 2541 * TODO(scheglov) |
| 2518 * | 2542 * |
| 2519 * See [CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_CLASS], and | 2543 * See [CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_CLASS], and |
| 2520 * [CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_MEMBER]. | 2544 * [CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_MEMBER]. |
| 2521 */ | 2545 */ |
| 2522 bool _checkForConflictingTypeVariableErrorCodes( | 2546 bool _checkForConflictingTypeVariableErrorCodes( |
| 2523 ClassDeclaration declaration) { | 2547 ClassDeclaration declaration) { |
| 2524 bool problemReported = false; | 2548 bool problemReported = false; |
| 2525 for (TypeParameterElement typeParameter in _enclosingClass.typeParameters) { | 2549 for (TypeParameterElement typeParameter in _enclosingClass.typeParameters) { |
| 2526 String name = typeParameter.name; | 2550 String name = typeParameter.name; |
| 2527 // name is same as the name of the enclosing class | 2551 // name is same as the name of the enclosing class |
| 2528 if (_enclosingClass.name == name) { | 2552 if (_enclosingClass.name == name) { |
| 2529 _errorReporter.reportErrorForOffset( | 2553 _errorReporter.reportErrorForOffset( |
| 2530 CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_CLASS, | 2554 CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_CLASS, |
| 2531 typeParameter.nameOffset, name.length, [name]); | 2555 typeParameter.nameOffset, |
| 2556 name.length, |
| 2557 [name]); |
| 2532 problemReported = true; | 2558 problemReported = true; |
| 2533 } | 2559 } |
| 2534 // check members | 2560 // check members |
| 2535 if (_enclosingClass.getMethod(name) != null || | 2561 if (_enclosingClass.getMethod(name) != null || |
| 2536 _enclosingClass.getGetter(name) != null || | 2562 _enclosingClass.getGetter(name) != null || |
| 2537 _enclosingClass.getSetter(name) != null) { | 2563 _enclosingClass.getSetter(name) != null) { |
| 2538 _errorReporter.reportErrorForOffset( | 2564 _errorReporter.reportErrorForOffset( |
| 2539 CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_MEMBER, | 2565 CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_MEMBER, |
| 2540 typeParameter.nameOffset, name.length, [name]); | 2566 typeParameter.nameOffset, |
| 2567 name.length, |
| 2568 [name]); |
| 2541 problemReported = true; | 2569 problemReported = true; |
| 2542 } | 2570 } |
| 2543 } | 2571 } |
| 2544 return problemReported; | 2572 return problemReported; |
| 2545 } | 2573 } |
| 2546 | 2574 |
| 2547 /** | 2575 /** |
| 2548 * Verify that if the given [constructor] declaration is 'const' then there | 2576 * Verify that if the given [constructor] declaration is 'const' then there |
| 2549 * are no invocations of non-'const' super constructors. | 2577 * are no invocations of non-'const' super constructors. |
| 2550 * | 2578 * |
| (...skipping 18 matching lines...) Expand all Loading... |
| 2569 // try to find and check super constructor invocation | 2597 // try to find and check super constructor invocation |
| 2570 for (ConstructorInitializer initializer in constructor.initializers) { | 2598 for (ConstructorInitializer initializer in constructor.initializers) { |
| 2571 if (initializer is SuperConstructorInvocation) { | 2599 if (initializer is SuperConstructorInvocation) { |
| 2572 SuperConstructorInvocation superInvocation = initializer; | 2600 SuperConstructorInvocation superInvocation = initializer; |
| 2573 ConstructorElement element = superInvocation.staticElement; | 2601 ConstructorElement element = superInvocation.staticElement; |
| 2574 if (element == null || element.isConst) { | 2602 if (element == null || element.isConst) { |
| 2575 return false; | 2603 return false; |
| 2576 } | 2604 } |
| 2577 _errorReporter.reportErrorForNode( | 2605 _errorReporter.reportErrorForNode( |
| 2578 CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_NON_CONST_SUPER, | 2606 CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_NON_CONST_SUPER, |
| 2579 superInvocation, [element.enclosingElement.displayName]); | 2607 superInvocation, |
| 2608 [element.enclosingElement.displayName]); |
| 2580 return true; | 2609 return true; |
| 2581 } | 2610 } |
| 2582 } | 2611 } |
| 2583 // no explicit super constructor invocation, check default constructor | 2612 // no explicit super constructor invocation, check default constructor |
| 2584 InterfaceType supertype = _enclosingClass.supertype; | 2613 InterfaceType supertype = _enclosingClass.supertype; |
| 2585 if (supertype == null) { | 2614 if (supertype == null) { |
| 2586 return false; | 2615 return false; |
| 2587 } | 2616 } |
| 2588 if (supertype.isObject) { | 2617 if (supertype.isObject) { |
| 2589 return false; | 2618 return false; |
| 2590 } | 2619 } |
| 2591 ConstructorElement unnamedConstructor = | 2620 ConstructorElement unnamedConstructor = |
| 2592 supertype.element.unnamedConstructor; | 2621 supertype.element.unnamedConstructor; |
| 2593 if (unnamedConstructor == null) { | 2622 if (unnamedConstructor == null) { |
| 2594 return false; | 2623 return false; |
| 2595 } | 2624 } |
| 2596 if (unnamedConstructor.isConst) { | 2625 if (unnamedConstructor.isConst) { |
| 2597 return false; | 2626 return false; |
| 2598 } | 2627 } |
| 2599 // default constructor is not 'const', report problem | 2628 // default constructor is not 'const', report problem |
| 2600 _errorReporter.reportErrorForNode( | 2629 _errorReporter.reportErrorForNode( |
| 2601 CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_NON_CONST_SUPER, | 2630 CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_NON_CONST_SUPER, |
| 2602 constructor.returnType, [supertype.displayName]); | 2631 constructor.returnType, |
| 2632 [supertype.displayName]); |
| 2603 return true; | 2633 return true; |
| 2604 } | 2634 } |
| 2605 | 2635 |
| 2606 /** | 2636 /** |
| 2607 * Verify that if the given [constructor] declaration is 'const' then there | 2637 * Verify that if the given [constructor] declaration is 'const' then there |
| 2608 * are no non-final instance variable. The [constructorElement] is the | 2638 * are no non-final instance variable. The [constructorElement] is the |
| 2609 * constructor element. | 2639 * constructor element. |
| 2610 * | 2640 * |
| 2611 * See [CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_NON_FINAL_FIELD]. | 2641 * See [CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_NON_FINAL_FIELD]. |
| 2612 */ | 2642 */ |
| (...skipping 20 matching lines...) Expand all Loading... |
| 2633 * creating a deferred type. The [constructorName] is the constructor name, | 2663 * creating a deferred type. The [constructorName] is the constructor name, |
| 2634 * always non-`null`. The [typeName] is the name of the type defining the | 2664 * always non-`null`. The [typeName] is the name of the type defining the |
| 2635 * constructor, always non-`null`. | 2665 * constructor, always non-`null`. |
| 2636 * | 2666 * |
| 2637 * See [CompileTimeErrorCode.CONST_DEFERRED_CLASS]. | 2667 * See [CompileTimeErrorCode.CONST_DEFERRED_CLASS]. |
| 2638 */ | 2668 */ |
| 2639 bool _checkForConstDeferredClass(InstanceCreationExpression expression, | 2669 bool _checkForConstDeferredClass(InstanceCreationExpression expression, |
| 2640 ConstructorName constructorName, TypeName typeName) { | 2670 ConstructorName constructorName, TypeName typeName) { |
| 2641 if (typeName.isDeferred) { | 2671 if (typeName.isDeferred) { |
| 2642 _errorReporter.reportErrorForNode( | 2672 _errorReporter.reportErrorForNode( |
| 2643 CompileTimeErrorCode.CONST_DEFERRED_CLASS, constructorName, | 2673 CompileTimeErrorCode.CONST_DEFERRED_CLASS, |
| 2674 constructorName, |
| 2644 [typeName.name.name]); | 2675 [typeName.name.name]); |
| 2645 return true; | 2676 return true; |
| 2646 } | 2677 } |
| 2647 return false; | 2678 return false; |
| 2648 } | 2679 } |
| 2649 | 2680 |
| 2650 /** | 2681 /** |
| 2651 * Verify that the given throw [expression] is not enclosed in a 'const' | 2682 * Verify that the given throw [expression] is not enclosed in a 'const' |
| 2652 * constructor declaration. | 2683 * constructor declaration. |
| 2653 * | 2684 * |
| (...skipping 26 matching lines...) Expand all Loading... |
| 2680 * Verify that the given instance creation [expression] is not being invoked | 2711 * Verify that the given instance creation [expression] is not being invoked |
| 2681 * on an abstract class. The [typeName] is the [TypeName] of the | 2712 * on an abstract class. The [typeName] is the [TypeName] of the |
| 2682 * [ConstructorName] from the [InstanceCreationExpression], this is the AST | 2713 * [ConstructorName] from the [InstanceCreationExpression], this is the AST |
| 2683 * node that the error is attached to. The [type] is the type being | 2714 * node that the error is attached to. The [type] is the type being |
| 2684 * constructed with this [InstanceCreationExpression]. | 2715 * constructed with this [InstanceCreationExpression]. |
| 2685 * | 2716 * |
| 2686 * See [StaticWarningCode.CONST_WITH_ABSTRACT_CLASS], and | 2717 * See [StaticWarningCode.CONST_WITH_ABSTRACT_CLASS], and |
| 2687 * [StaticWarningCode.NEW_WITH_ABSTRACT_CLASS]. | 2718 * [StaticWarningCode.NEW_WITH_ABSTRACT_CLASS]. |
| 2688 */ | 2719 */ |
| 2689 bool _checkForConstOrNewWithAbstractClass( | 2720 bool _checkForConstOrNewWithAbstractClass( |
| 2690 InstanceCreationExpression expression, TypeName typeName, | 2721 InstanceCreationExpression expression, |
| 2722 TypeName typeName, |
| 2691 InterfaceType type) { | 2723 InterfaceType type) { |
| 2692 if (type.element.isAbstract) { | 2724 if (type.element.isAbstract) { |
| 2693 ConstructorElement element = expression.staticElement; | 2725 ConstructorElement element = expression.staticElement; |
| 2694 if (element != null && !element.isFactory) { | 2726 if (element != null && !element.isFactory) { |
| 2695 if ((expression.keyword as sc.KeywordToken).keyword == | 2727 if ((expression.keyword as sc.KeywordToken).keyword == |
| 2696 sc.Keyword.CONST) { | 2728 sc.Keyword.CONST) { |
| 2697 _errorReporter.reportErrorForNode( | 2729 _errorReporter.reportErrorForNode( |
| 2698 StaticWarningCode.CONST_WITH_ABSTRACT_CLASS, typeName); | 2730 StaticWarningCode.CONST_WITH_ABSTRACT_CLASS, typeName); |
| 2699 } else { | 2731 } else { |
| 2700 _errorReporter.reportErrorForNode( | 2732 _errorReporter.reportErrorForNode( |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2784 * constructor name, always non-`null`. The [typeName] is the name of the type | 2816 * constructor name, always non-`null`. The [typeName] is the name of the type |
| 2785 * defining the constructor, always non-`null`. | 2817 * defining the constructor, always non-`null`. |
| 2786 * | 2818 * |
| 2787 * This method assumes that the instance creation was tested to be 'const' | 2819 * This method assumes that the instance creation was tested to be 'const' |
| 2788 * before being called. | 2820 * before being called. |
| 2789 * | 2821 * |
| 2790 * See [CompileTimeErrorCode.CONST_WITH_UNDEFINED_CONSTRUCTOR], and | 2822 * See [CompileTimeErrorCode.CONST_WITH_UNDEFINED_CONSTRUCTOR], and |
| 2791 * [CompileTimeErrorCode.CONST_WITH_UNDEFINED_CONSTRUCTOR_DEFAULT]. | 2823 * [CompileTimeErrorCode.CONST_WITH_UNDEFINED_CONSTRUCTOR_DEFAULT]. |
| 2792 */ | 2824 */ |
| 2793 bool _checkForConstWithUndefinedConstructor( | 2825 bool _checkForConstWithUndefinedConstructor( |
| 2794 InstanceCreationExpression expression, ConstructorName constructorName, | 2826 InstanceCreationExpression expression, |
| 2827 ConstructorName constructorName, |
| 2795 TypeName typeName) { | 2828 TypeName typeName) { |
| 2796 // OK if resolved | 2829 // OK if resolved |
| 2797 if (expression.staticElement != null) { | 2830 if (expression.staticElement != null) { |
| 2798 return false; | 2831 return false; |
| 2799 } | 2832 } |
| 2800 DartType type = typeName.type; | 2833 DartType type = typeName.type; |
| 2801 if (type is InterfaceType) { | 2834 if (type is InterfaceType) { |
| 2802 ClassElement element = type.element; | 2835 ClassElement element = type.element; |
| 2803 if (element != null && element.isEnum) { | 2836 if (element != null && element.isEnum) { |
| 2804 // We have already reported the error. | 2837 // We have already reported the error. |
| 2805 return false; | 2838 return false; |
| 2806 } | 2839 } |
| 2807 } | 2840 } |
| 2808 Identifier className = typeName.name; | 2841 Identifier className = typeName.name; |
| 2809 // report as named or default constructor absence | 2842 // report as named or default constructor absence |
| 2810 SimpleIdentifier name = constructorName.name; | 2843 SimpleIdentifier name = constructorName.name; |
| 2811 if (name != null) { | 2844 if (name != null) { |
| 2812 _errorReporter.reportErrorForNode( | 2845 _errorReporter.reportErrorForNode( |
| 2813 CompileTimeErrorCode.CONST_WITH_UNDEFINED_CONSTRUCTOR, name, [ | 2846 CompileTimeErrorCode.CONST_WITH_UNDEFINED_CONSTRUCTOR, |
| 2814 className, | 2847 name, |
| 2815 name | 2848 [className, name]); |
| 2816 ]); | |
| 2817 } else { | 2849 } else { |
| 2818 _errorReporter.reportErrorForNode( | 2850 _errorReporter.reportErrorForNode( |
| 2819 CompileTimeErrorCode.CONST_WITH_UNDEFINED_CONSTRUCTOR_DEFAULT, | 2851 CompileTimeErrorCode.CONST_WITH_UNDEFINED_CONSTRUCTOR_DEFAULT, |
| 2820 constructorName, [className]); | 2852 constructorName, |
| 2853 [className]); |
| 2821 } | 2854 } |
| 2822 return true; | 2855 return true; |
| 2823 } | 2856 } |
| 2824 | 2857 |
| 2825 /** | 2858 /** |
| 2826 * Verify that there are no default parameters in the given function type | 2859 * Verify that there are no default parameters in the given function type |
| 2827 * [alias]. | 2860 * [alias]. |
| 2828 * | 2861 * |
| 2829 * See [CompileTimeErrorCode.DEFAULT_VALUE_IN_FUNCTION_TYPE_ALIAS]. | 2862 * See [CompileTimeErrorCode.DEFAULT_VALUE_IN_FUNCTION_TYPE_ALIAS]. |
| 2830 */ | 2863 */ |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2961 String displayName; | 2994 String displayName; |
| 2962 Element enclosingElement = inheritedMember.enclosingElement; | 2995 Element enclosingElement = inheritedMember.enclosingElement; |
| 2963 if (enclosingElement.source == _enclosingClass.source) { | 2996 if (enclosingElement.source == _enclosingClass.source) { |
| 2964 displayName = enclosingElement.displayName; | 2997 displayName = enclosingElement.displayName; |
| 2965 } else { | 2998 } else { |
| 2966 displayName = enclosingElement.getExtendedDisplayName(null); | 2999 displayName = enclosingElement.getExtendedDisplayName(null); |
| 2967 } | 3000 } |
| 2968 // report problem | 3001 // report problem |
| 2969 _errorReporter.reportErrorForOffset( | 3002 _errorReporter.reportErrorForOffset( |
| 2970 CompileTimeErrorCode.DUPLICATE_DEFINITION_INHERITANCE, | 3003 CompileTimeErrorCode.DUPLICATE_DEFINITION_INHERITANCE, |
| 2971 staticMember.nameOffset, name.length, [name, displayName]); | 3004 staticMember.nameOffset, |
| 3005 name.length, |
| 3006 [name, displayName]); |
| 2972 return true; | 3007 return true; |
| 2973 } | 3008 } |
| 2974 | 3009 |
| 2975 /** | 3010 /** |
| 2976 * Verify that if the given list [literal] has type arguments then there is | 3011 * Verify that if the given list [literal] has type arguments then there is |
| 2977 * exactly one. The [typeArguments] are the type arguments. | 3012 * exactly one. The [typeArguments] are the type arguments. |
| 2978 * | 3013 * |
| 2979 * See [StaticTypeWarningCode.EXPECTED_ONE_LIST_TYPE_ARGUMENTS]. | 3014 * See [StaticTypeWarningCode.EXPECTED_ONE_LIST_TYPE_ARGUMENTS]. |
| 2980 */ | 3015 */ |
| 2981 bool _checkForExpectedOneListTypeArgument( | 3016 bool _checkForExpectedOneListTypeArgument( |
| 2982 ListLiteral literal, TypeArgumentList typeArguments) { | 3017 ListLiteral literal, TypeArgumentList typeArguments) { |
| 2983 // check number of type arguments | 3018 // check number of type arguments |
| 2984 int num = typeArguments.arguments.length; | 3019 int num = typeArguments.arguments.length; |
| 2985 if (num == 1) { | 3020 if (num == 1) { |
| 2986 return false; | 3021 return false; |
| 2987 } | 3022 } |
| 2988 // report problem | 3023 // report problem |
| 2989 _errorReporter.reportErrorForNode( | 3024 _errorReporter.reportErrorForNode( |
| 2990 StaticTypeWarningCode.EXPECTED_ONE_LIST_TYPE_ARGUMENTS, typeArguments, | 3025 StaticTypeWarningCode.EXPECTED_ONE_LIST_TYPE_ARGUMENTS, |
| 3026 typeArguments, |
| 2991 [num]); | 3027 [num]); |
| 2992 return true; | 3028 return true; |
| 2993 } | 3029 } |
| 2994 | 3030 |
| 2995 /** | 3031 /** |
| 2996 * Verify that the given export [directive] has a unique name among other | 3032 * Verify that the given export [directive] has a unique name among other |
| 2997 * exported libraries. The [exportElement] is the [ExportElement] retrieved | 3033 * exported libraries. The [exportElement] is the [ExportElement] retrieved |
| 2998 * from the node, if the element in the node was `null`, then this method is | 3034 * from the node, if the element in the node was `null`, then this method is |
| 2999 * not called. The [exportedLibrary] is the library element containing the | 3035 * not called. The [exportedLibrary] is the library element containing the |
| 3000 * exported element. | 3036 * exported element. |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3046 String uri = exportElement.uri; | 3082 String uri = exportElement.uri; |
| 3047 SdkLibrary sdkLibrary = sdk.getSdkLibrary(uri); | 3083 SdkLibrary sdkLibrary = sdk.getSdkLibrary(uri); |
| 3048 if (sdkLibrary == null) { | 3084 if (sdkLibrary == null) { |
| 3049 return false; | 3085 return false; |
| 3050 } | 3086 } |
| 3051 if (!sdkLibrary.isInternal) { | 3087 if (!sdkLibrary.isInternal) { |
| 3052 return false; | 3088 return false; |
| 3053 } | 3089 } |
| 3054 // report problem | 3090 // report problem |
| 3055 _errorReporter.reportErrorForNode( | 3091 _errorReporter.reportErrorForNode( |
| 3056 CompileTimeErrorCode.EXPORT_INTERNAL_LIBRARY, directive, | 3092 CompileTimeErrorCode.EXPORT_INTERNAL_LIBRARY, |
| 3093 directive, |
| 3057 [directive.uri]); | 3094 [directive.uri]); |
| 3058 return true; | 3095 return true; |
| 3059 } | 3096 } |
| 3060 | 3097 |
| 3061 /** | 3098 /** |
| 3062 * Verify that the given extends [clause] does not extend a deferred class. | 3099 * Verify that the given extends [clause] does not extend a deferred class. |
| 3063 * | 3100 * |
| 3064 * See [CompileTimeErrorCode.EXTENDS_DEFERRED_CLASS]. | 3101 * See [CompileTimeErrorCode.EXTENDS_DEFERRED_CLASS]. |
| 3065 */ | 3102 */ |
| 3066 bool _checkForExtendsDeferredClass(ExtendsClause clause) { | 3103 bool _checkForExtendsDeferredClass(ExtendsClause clause) { |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3215 } | 3252 } |
| 3216 if (staticType.isAssignableTo(fieldType)) { | 3253 if (staticType.isAssignableTo(fieldType)) { |
| 3217 return false; | 3254 return false; |
| 3218 } | 3255 } |
| 3219 // report problem | 3256 // report problem |
| 3220 if (_isEnclosingConstructorConst) { | 3257 if (_isEnclosingConstructorConst) { |
| 3221 // TODO(paulberry): this error should be based on the actual type of the | 3258 // TODO(paulberry): this error should be based on the actual type of the |
| 3222 // constant, not the static type. See dartbug.com/21119. | 3259 // constant, not the static type. See dartbug.com/21119. |
| 3223 _errorReporter.reportTypeErrorForNode( | 3260 _errorReporter.reportTypeErrorForNode( |
| 3224 CheckedModeCompileTimeErrorCode.CONST_FIELD_INITIALIZER_NOT_ASSIGNABLE
, | 3261 CheckedModeCompileTimeErrorCode.CONST_FIELD_INITIALIZER_NOT_ASSIGNABLE
, |
| 3225 expression, [staticType, fieldType]); | 3262 expression, |
| 3263 [staticType, fieldType]); |
| 3226 } | 3264 } |
| 3227 _errorReporter.reportTypeErrorForNode( | 3265 _errorReporter.reportTypeErrorForNode( |
| 3228 StaticWarningCode.FIELD_INITIALIZER_NOT_ASSIGNABLE, expression, [ | 3266 StaticWarningCode.FIELD_INITIALIZER_NOT_ASSIGNABLE, |
| 3229 staticType, | 3267 expression, |
| 3230 fieldType | 3268 [staticType, fieldType]); |
| 3231 ]); | |
| 3232 return true; | 3269 return true; |
| 3233 // TODO(brianwilkerson) Define a hint corresponding to these errors and | 3270 // TODO(brianwilkerson) Define a hint corresponding to these errors and |
| 3234 // report it if appropriate. | 3271 // report it if appropriate. |
| 3235 // // test the propagated type of the expression | 3272 // // test the propagated type of the expression |
| 3236 // Type propagatedType = expression.getPropagatedType(); | 3273 // Type propagatedType = expression.getPropagatedType(); |
| 3237 // if (propagatedType != null && propagatedType.isAssignableTo(fieldType)
) { | 3274 // if (propagatedType != null && propagatedType.isAssignableTo(fieldType)
) { |
| 3238 // return false; | 3275 // return false; |
| 3239 // } | 3276 // } |
| 3240 // // report problem | 3277 // // report problem |
| 3241 // if (isEnclosingConstructorConst) { | 3278 // if (isEnclosingConstructorConst) { |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3301 if (_isInNativeClass) { | 3338 if (_isInNativeClass) { |
| 3302 return false; | 3339 return false; |
| 3303 } | 3340 } |
| 3304 bool foundError = false; | 3341 bool foundError = false; |
| 3305 if (!list.isSynthetic) { | 3342 if (!list.isSynthetic) { |
| 3306 NodeList<VariableDeclaration> variables = list.variables; | 3343 NodeList<VariableDeclaration> variables = list.variables; |
| 3307 for (VariableDeclaration variable in variables) { | 3344 for (VariableDeclaration variable in variables) { |
| 3308 if (variable.initializer == null) { | 3345 if (variable.initializer == null) { |
| 3309 if (list.isConst) { | 3346 if (list.isConst) { |
| 3310 _errorReporter.reportErrorForNode( | 3347 _errorReporter.reportErrorForNode( |
| 3311 CompileTimeErrorCode.CONST_NOT_INITIALIZED, variable.name, | 3348 CompileTimeErrorCode.CONST_NOT_INITIALIZED, |
| 3349 variable.name, |
| 3312 [variable.name.name]); | 3350 [variable.name.name]); |
| 3313 } else if (list.isFinal) { | 3351 } else if (list.isFinal) { |
| 3314 _errorReporter.reportErrorForNode( | 3352 _errorReporter.reportErrorForNode( |
| 3315 StaticWarningCode.FINAL_NOT_INITIALIZED, variable.name, | 3353 StaticWarningCode.FINAL_NOT_INITIALIZED, |
| 3354 variable.name, |
| 3316 [variable.name.name]); | 3355 [variable.name.name]); |
| 3317 } | 3356 } |
| 3318 foundError = true; | 3357 foundError = true; |
| 3319 } | 3358 } |
| 3320 } | 3359 } |
| 3321 } | 3360 } |
| 3322 return foundError; | 3361 return foundError; |
| 3323 } | 3362 } |
| 3324 | 3363 |
| 3325 /** | 3364 /** |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3553 String uri = importElement.uri; | 3592 String uri = importElement.uri; |
| 3554 SdkLibrary sdkLibrary = sdk.getSdkLibrary(uri); | 3593 SdkLibrary sdkLibrary = sdk.getSdkLibrary(uri); |
| 3555 if (sdkLibrary == null) { | 3594 if (sdkLibrary == null) { |
| 3556 return false; | 3595 return false; |
| 3557 } | 3596 } |
| 3558 if (!sdkLibrary.isInternal) { | 3597 if (!sdkLibrary.isInternal) { |
| 3559 return false; | 3598 return false; |
| 3560 } | 3599 } |
| 3561 // report problem | 3600 // report problem |
| 3562 _errorReporter.reportErrorForNode( | 3601 _errorReporter.reportErrorForNode( |
| 3563 CompileTimeErrorCode.IMPORT_INTERNAL_LIBRARY, directive, | 3602 CompileTimeErrorCode.IMPORT_INTERNAL_LIBRARY, |
| 3603 directive, |
| 3564 [directive.uri]); | 3604 [directive.uri]); |
| 3565 return true; | 3605 return true; |
| 3566 } | 3606 } |
| 3567 | 3607 |
| 3568 /** | 3608 /** |
| 3569 * For each class declaration, this method is called which verifies that all | 3609 * For each class declaration, this method is called which verifies that all |
| 3570 * inherited members are inherited consistently. | 3610 * inherited members are inherited consistently. |
| 3571 * | 3611 * |
| 3572 * See [StaticTypeWarningCode.INCONSISTENT_METHOD_INHERITANCE]. | 3612 * See [StaticTypeWarningCode.INCONSISTENT_METHOD_INHERITANCE]. |
| 3573 */ | 3613 */ |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3612 // OK, top-level element | 3652 // OK, top-level element |
| 3613 if (executableElement.enclosingElement is! ClassElement) { | 3653 if (executableElement.enclosingElement is! ClassElement) { |
| 3614 return false; | 3654 return false; |
| 3615 } | 3655 } |
| 3616 // OK, instance member | 3656 // OK, instance member |
| 3617 if (!executableElement.isStatic) { | 3657 if (!executableElement.isStatic) { |
| 3618 return false; | 3658 return false; |
| 3619 } | 3659 } |
| 3620 // report problem | 3660 // report problem |
| 3621 _errorReporter.reportErrorForNode( | 3661 _errorReporter.reportErrorForNode( |
| 3622 StaticTypeWarningCode.INSTANCE_ACCESS_TO_STATIC_MEMBER, name, | 3662 StaticTypeWarningCode.INSTANCE_ACCESS_TO_STATIC_MEMBER, |
| 3663 name, |
| 3623 [name.name]); | 3664 [name.name]); |
| 3624 return true; | 3665 return true; |
| 3625 } | 3666 } |
| 3626 | 3667 |
| 3627 /** | 3668 /** |
| 3628 * Check whether the given [executableElement] collides with the name of a | 3669 * Check whether the given [executableElement] collides with the name of a |
| 3629 * static method in one of its superclasses, and reports the appropriate | 3670 * static method in one of its superclasses, and reports the appropriate |
| 3630 * warning if it does. The [errorNameTarget] is the node to report problems | 3671 * warning if it does. The [errorNameTarget] is the node to report problems |
| 3631 * on. | 3672 * on. |
| 3632 * | 3673 * |
| (...skipping 20 matching lines...) Expand all Loading... |
| 3653 if (fieldElt != null) { | 3694 if (fieldElt != null) { |
| 3654 // Ignore if private in a different library - cannot collide. | 3695 // Ignore if private in a different library - cannot collide. |
| 3655 if (executableElementPrivate && | 3696 if (executableElementPrivate && |
| 3656 _currentLibrary != superclassLibrary) { | 3697 _currentLibrary != superclassLibrary) { |
| 3657 continue; | 3698 continue; |
| 3658 } | 3699 } |
| 3659 // instance vs. static | 3700 // instance vs. static |
| 3660 if (fieldElt.isStatic) { | 3701 if (fieldElt.isStatic) { |
| 3661 _errorReporter.reportErrorForNode( | 3702 _errorReporter.reportErrorForNode( |
| 3662 StaticWarningCode.INSTANCE_METHOD_NAME_COLLIDES_WITH_SUPERCLASS_
STATIC, | 3703 StaticWarningCode.INSTANCE_METHOD_NAME_COLLIDES_WITH_SUPERCLASS_
STATIC, |
| 3663 errorNameTarget, [ | 3704 errorNameTarget, |
| 3664 executableElementName, | 3705 [executableElementName, fieldElt.enclosingElement.displayName]); |
| 3665 fieldElt.enclosingElement.displayName | |
| 3666 ]); | |
| 3667 return true; | 3706 return true; |
| 3668 } | 3707 } |
| 3669 } | 3708 } |
| 3670 // Check methods. | 3709 // Check methods. |
| 3671 List<MethodElement> methodElements = superclassElement.methods; | 3710 List<MethodElement> methodElements = superclassElement.methods; |
| 3672 for (MethodElement methodElement in methodElements) { | 3711 for (MethodElement methodElement in methodElements) { |
| 3673 // We need the same name. | 3712 // We need the same name. |
| 3674 if (methodElement.name != executableElementName) { | 3713 if (methodElement.name != executableElementName) { |
| 3675 continue; | 3714 continue; |
| 3676 } | 3715 } |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3744 if (lhs == null || rhs == null) { | 3783 if (lhs == null || rhs == null) { |
| 3745 return false; | 3784 return false; |
| 3746 } | 3785 } |
| 3747 VariableElement leftVariableElement = getVariableElement(lhs); | 3786 VariableElement leftVariableElement = getVariableElement(lhs); |
| 3748 DartType leftType = (leftVariableElement == null) | 3787 DartType leftType = (leftVariableElement == null) |
| 3749 ? getStaticType(lhs) | 3788 ? getStaticType(lhs) |
| 3750 : leftVariableElement.type; | 3789 : leftVariableElement.type; |
| 3751 DartType staticRightType = getStaticType(rhs); | 3790 DartType staticRightType = getStaticType(rhs); |
| 3752 if (!staticRightType.isAssignableTo(leftType)) { | 3791 if (!staticRightType.isAssignableTo(leftType)) { |
| 3753 _errorReporter.reportTypeErrorForNode( | 3792 _errorReporter.reportTypeErrorForNode( |
| 3754 StaticTypeWarningCode.INVALID_ASSIGNMENT, rhs, [ | 3793 StaticTypeWarningCode.INVALID_ASSIGNMENT, |
| 3755 staticRightType, | 3794 rhs, |
| 3756 leftType | 3795 [staticRightType, leftType]); |
| 3757 ]); | |
| 3758 return true; | 3796 return true; |
| 3759 } | 3797 } |
| 3760 return false; | 3798 return false; |
| 3761 } | 3799 } |
| 3762 | 3800 |
| 3763 /** | 3801 /** |
| 3764 * Given an [assignment] using a compound assignment operator, this verifies | 3802 * Given an [assignment] using a compound assignment operator, this verifies |
| 3765 * that the given assignment is valid. The [lhs] is the left hand side | 3803 * that the given assignment is valid. The [lhs] is the left hand side |
| 3766 * expression. The [rhs] is the right hand side expression. | 3804 * expression. The [rhs] is the right hand side expression. |
| 3767 * | 3805 * |
| (...skipping 30 matching lines...) Expand all Loading... |
| 3798 * [ConstructorFieldInitializer]. The [staticElement] is the static element | 3836 * [ConstructorFieldInitializer]. The [staticElement] is the static element |
| 3799 * from the name in the [ConstructorFieldInitializer]. | 3837 * from the name in the [ConstructorFieldInitializer]. |
| 3800 */ | 3838 */ |
| 3801 void _checkForInvalidField(ConstructorFieldInitializer initializer, | 3839 void _checkForInvalidField(ConstructorFieldInitializer initializer, |
| 3802 SimpleIdentifier fieldName, Element staticElement) { | 3840 SimpleIdentifier fieldName, Element staticElement) { |
| 3803 if (staticElement is FieldElement) { | 3841 if (staticElement is FieldElement) { |
| 3804 FieldElement fieldElement = staticElement; | 3842 FieldElement fieldElement = staticElement; |
| 3805 if (fieldElement.isSynthetic) { | 3843 if (fieldElement.isSynthetic) { |
| 3806 _errorReporter.reportErrorForNode( | 3844 _errorReporter.reportErrorForNode( |
| 3807 CompileTimeErrorCode.INITIALIZER_FOR_NON_EXISTENT_FIELD, | 3845 CompileTimeErrorCode.INITIALIZER_FOR_NON_EXISTENT_FIELD, |
| 3808 initializer, [fieldName]); | 3846 initializer, |
| 3847 [fieldName]); |
| 3809 } else if (fieldElement.isStatic) { | 3848 } else if (fieldElement.isStatic) { |
| 3810 _errorReporter.reportErrorForNode( | 3849 _errorReporter.reportErrorForNode( |
| 3811 CompileTimeErrorCode.INITIALIZER_FOR_STATIC_FIELD, initializer, | 3850 CompileTimeErrorCode.INITIALIZER_FOR_STATIC_FIELD, |
| 3851 initializer, |
| 3812 [fieldName]); | 3852 [fieldName]); |
| 3813 } | 3853 } |
| 3814 } else { | 3854 } else { |
| 3815 _errorReporter.reportErrorForNode( | 3855 _errorReporter.reportErrorForNode( |
| 3816 CompileTimeErrorCode.INITIALIZER_FOR_NON_EXISTENT_FIELD, initializer, | 3856 CompileTimeErrorCode.INITIALIZER_FOR_NON_EXISTENT_FIELD, |
| 3857 initializer, |
| 3817 [fieldName]); | 3858 [fieldName]); |
| 3818 return; | 3859 return; |
| 3819 } | 3860 } |
| 3820 } | 3861 } |
| 3821 | 3862 |
| 3822 /** | 3863 /** |
| 3823 * Check to see whether the given function [body] has a modifier associated | 3864 * Check to see whether the given function [body] has a modifier associated |
| 3824 * with it, and report it as an error if it does. | 3865 * with it, and report it as an error if it does. |
| 3825 */ | 3866 */ |
| 3826 bool _checkForInvalidModifierOnBody( | 3867 bool _checkForInvalidModifierOnBody( |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3878 if (typeNames.length < 1) { | 3919 if (typeNames.length < 1) { |
| 3879 return false; | 3920 return false; |
| 3880 } | 3921 } |
| 3881 DartType listElementType = typeNames[0].type; | 3922 DartType listElementType = typeNames[0].type; |
| 3882 // Check every list element. | 3923 // Check every list element. |
| 3883 bool hasProblems = false; | 3924 bool hasProblems = false; |
| 3884 for (Expression element in literal.elements) { | 3925 for (Expression element in literal.elements) { |
| 3885 if (literal.constKeyword != null) { | 3926 if (literal.constKeyword != null) { |
| 3886 // TODO(paulberry): this error should be based on the actual type of the | 3927 // TODO(paulberry): this error should be based on the actual type of the |
| 3887 // list element, not the static type. See dartbug.com/21119. | 3928 // list element, not the static type. See dartbug.com/21119. |
| 3888 if (_checkForArgumentTypeNotAssignableWithExpectedTypes(element, | 3929 if (_checkForArgumentTypeNotAssignableWithExpectedTypes( |
| 3930 element, |
| 3889 listElementType, | 3931 listElementType, |
| 3890 CheckedModeCompileTimeErrorCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE)) { | 3932 CheckedModeCompileTimeErrorCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE)) { |
| 3891 hasProblems = true; | 3933 hasProblems = true; |
| 3892 } | 3934 } |
| 3893 } | 3935 } |
| 3894 if (_checkForArgumentTypeNotAssignableWithExpectedTypes(element, | 3936 if (_checkForArgumentTypeNotAssignableWithExpectedTypes( |
| 3937 element, |
| 3895 listElementType, | 3938 listElementType, |
| 3896 StaticWarningCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE)) { | 3939 StaticWarningCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE)) { |
| 3897 hasProblems = true; | 3940 hasProblems = true; |
| 3898 } | 3941 } |
| 3899 } | 3942 } |
| 3900 return hasProblems; | 3943 return hasProblems; |
| 3901 } | 3944 } |
| 3902 | 3945 |
| 3903 /** | 3946 /** |
| 3904 * Verify that the key/value of entries of the given map [literal] are | 3947 * Verify that the key/value of entries of the given map [literal] are |
| (...skipping 20 matching lines...) Expand all Loading... |
| 3925 for (MapLiteralEntry entry in entries) { | 3968 for (MapLiteralEntry entry in entries) { |
| 3926 Expression key = entry.key; | 3969 Expression key = entry.key; |
| 3927 Expression value = entry.value; | 3970 Expression value = entry.value; |
| 3928 if (literal.constKeyword != null) { | 3971 if (literal.constKeyword != null) { |
| 3929 // TODO(paulberry): this error should be based on the actual type of the | 3972 // TODO(paulberry): this error should be based on the actual type of the |
| 3930 // list element, not the static type. See dartbug.com/21119. | 3973 // list element, not the static type. See dartbug.com/21119. |
| 3931 if (_checkForArgumentTypeNotAssignableWithExpectedTypes(key, keyType, | 3974 if (_checkForArgumentTypeNotAssignableWithExpectedTypes(key, keyType, |
| 3932 CheckedModeCompileTimeErrorCode.MAP_KEY_TYPE_NOT_ASSIGNABLE)) { | 3975 CheckedModeCompileTimeErrorCode.MAP_KEY_TYPE_NOT_ASSIGNABLE)) { |
| 3933 hasProblems = true; | 3976 hasProblems = true; |
| 3934 } | 3977 } |
| 3935 if (_checkForArgumentTypeNotAssignableWithExpectedTypes(value, | 3978 if (_checkForArgumentTypeNotAssignableWithExpectedTypes( |
| 3979 value, |
| 3936 valueType, | 3980 valueType, |
| 3937 CheckedModeCompileTimeErrorCode.MAP_VALUE_TYPE_NOT_ASSIGNABLE)) { | 3981 CheckedModeCompileTimeErrorCode.MAP_VALUE_TYPE_NOT_ASSIGNABLE)) { |
| 3938 hasProblems = true; | 3982 hasProblems = true; |
| 3939 } | 3983 } |
| 3940 } | 3984 } |
| 3941 if (_checkForArgumentTypeNotAssignableWithExpectedTypes( | 3985 if (_checkForArgumentTypeNotAssignableWithExpectedTypes( |
| 3942 key, keyType, StaticWarningCode.MAP_KEY_TYPE_NOT_ASSIGNABLE)) { | 3986 key, keyType, StaticWarningCode.MAP_KEY_TYPE_NOT_ASSIGNABLE)) { |
| 3943 hasProblems = true; | 3987 hasProblems = true; |
| 3944 } | 3988 } |
| 3945 if (_checkForArgumentTypeNotAssignableWithExpectedTypes( | 3989 if (_checkForArgumentTypeNotAssignableWithExpectedTypes( |
| (...skipping 16 matching lines...) Expand all Loading... |
| 3962 } | 4006 } |
| 3963 String className = _enclosingClass.name; | 4007 String className = _enclosingClass.name; |
| 3964 if (className == null) { | 4008 if (className == null) { |
| 3965 return false; | 4009 return false; |
| 3966 } | 4010 } |
| 3967 bool problemReported = false; | 4011 bool problemReported = false; |
| 3968 // check accessors | 4012 // check accessors |
| 3969 for (PropertyAccessorElement accessor in _enclosingClass.accessors) { | 4013 for (PropertyAccessorElement accessor in _enclosingClass.accessors) { |
| 3970 if (className == accessor.name) { | 4014 if (className == accessor.name) { |
| 3971 _errorReporter.reportErrorForOffset( | 4015 _errorReporter.reportErrorForOffset( |
| 3972 CompileTimeErrorCode.MEMBER_WITH_CLASS_NAME, accessor.nameOffset, | 4016 CompileTimeErrorCode.MEMBER_WITH_CLASS_NAME, |
| 4017 accessor.nameOffset, |
| 3973 className.length); | 4018 className.length); |
| 3974 problemReported = true; | 4019 problemReported = true; |
| 3975 } | 4020 } |
| 3976 } | 4021 } |
| 3977 // don't check methods, they would be constructors | 4022 // don't check methods, they would be constructors |
| 3978 // done | 4023 // done |
| 3979 return problemReported; | 4024 return problemReported; |
| 3980 } | 4025 } |
| 3981 | 4026 |
| 3982 /** | 4027 /** |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4048 getterType = _getGetterType(counterpartAccessor); | 4093 getterType = _getGetterType(counterpartAccessor); |
| 4049 } | 4094 } |
| 4050 // If either types are not assignable to each other, report an error | 4095 // If either types are not assignable to each other, report an error |
| 4051 // (if the getter is null, it is dynamic which is assignable to everything). | 4096 // (if the getter is null, it is dynamic which is assignable to everything). |
| 4052 if (setterType != null && | 4097 if (setterType != null && |
| 4053 getterType != null && | 4098 getterType != null && |
| 4054 !getterType.isAssignableTo(setterType)) { | 4099 !getterType.isAssignableTo(setterType)) { |
| 4055 if (enclosingClassForCounterpart == null) { | 4100 if (enclosingClassForCounterpart == null) { |
| 4056 _errorReporter.reportTypeErrorForNode( | 4101 _errorReporter.reportTypeErrorForNode( |
| 4057 StaticWarningCode.MISMATCHED_GETTER_AND_SETTER_TYPES, | 4102 StaticWarningCode.MISMATCHED_GETTER_AND_SETTER_TYPES, |
| 4058 accessorDeclaration, [accessorTextName, setterType, getterType]); | 4103 accessorDeclaration, |
| 4104 [accessorTextName, setterType, getterType]); |
| 4059 return true; | 4105 return true; |
| 4060 } else { | 4106 } else { |
| 4061 _errorReporter.reportTypeErrorForNode( | 4107 _errorReporter.reportTypeErrorForNode( |
| 4062 StaticWarningCode.MISMATCHED_GETTER_AND_SETTER_TYPES_FROM_SUPERTYPE, | 4108 StaticWarningCode.MISMATCHED_GETTER_AND_SETTER_TYPES_FROM_SUPERTYPE, |
| 4063 accessorDeclaration, [ | 4109 accessorDeclaration, [ |
| 4064 accessorTextName, | 4110 accessorTextName, |
| 4065 setterType, | 4111 setterType, |
| 4066 getterType, | 4112 getterType, |
| 4067 enclosingClassForCounterpart.displayName | 4113 enclosingClassForCounterpart.displayName |
| 4068 ]); | 4114 ]); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4114 } | 4160 } |
| 4115 } | 4161 } |
| 4116 int nameCount = constantNames.length; | 4162 int nameCount = constantNames.length; |
| 4117 if (nameCount == 0) { | 4163 if (nameCount == 0) { |
| 4118 return false; | 4164 return false; |
| 4119 } | 4165 } |
| 4120 for (int i = 0; i < nameCount; i++) { | 4166 for (int i = 0; i < nameCount; i++) { |
| 4121 int offset = statement.offset; | 4167 int offset = statement.offset; |
| 4122 int end = statement.rightParenthesis.end; | 4168 int end = statement.rightParenthesis.end; |
| 4123 _errorReporter.reportErrorForOffset( | 4169 _errorReporter.reportErrorForOffset( |
| 4124 CompileTimeErrorCode.MISSING_ENUM_CONSTANT_IN_SWITCH, offset, | 4170 CompileTimeErrorCode.MISSING_ENUM_CONSTANT_IN_SWITCH, |
| 4125 end - offset, [constantNames[i]]); | 4171 offset, |
| 4172 end - offset, |
| 4173 [constantNames[i]]); |
| 4126 } | 4174 } |
| 4127 return true; | 4175 return true; |
| 4128 } | 4176 } |
| 4129 | 4177 |
| 4130 /** | 4178 /** |
| 4131 * Verify that the given function [body] does not contain return statements | 4179 * Verify that the given function [body] does not contain return statements |
| 4132 * that both have and do not have return values. | 4180 * that both have and do not have return values. |
| 4133 * | 4181 * |
| 4134 * See [StaticWarningCode.MIXED_RETURN_TYPES]. | 4182 * See [StaticWarningCode.MIXED_RETURN_TYPES]. |
| 4135 */ | 4183 */ |
| (...skipping 22 matching lines...) Expand all Loading... |
| 4158 * constructor. The [mixinName] is the node to report problem on. The | 4206 * constructor. The [mixinName] is the node to report problem on. The |
| 4159 * [mixinElement] is the mixing to evaluate. | 4207 * [mixinElement] is the mixing to evaluate. |
| 4160 * | 4208 * |
| 4161 * See [CompileTimeErrorCode.MIXIN_DECLARES_CONSTRUCTOR]. | 4209 * See [CompileTimeErrorCode.MIXIN_DECLARES_CONSTRUCTOR]. |
| 4162 */ | 4210 */ |
| 4163 bool _checkForMixinDeclaresConstructor( | 4211 bool _checkForMixinDeclaresConstructor( |
| 4164 TypeName mixinName, ClassElement mixinElement) { | 4212 TypeName mixinName, ClassElement mixinElement) { |
| 4165 for (ConstructorElement constructor in mixinElement.constructors) { | 4213 for (ConstructorElement constructor in mixinElement.constructors) { |
| 4166 if (!constructor.isSynthetic && !constructor.isFactory) { | 4214 if (!constructor.isSynthetic && !constructor.isFactory) { |
| 4167 _errorReporter.reportErrorForNode( | 4215 _errorReporter.reportErrorForNode( |
| 4168 CompileTimeErrorCode.MIXIN_DECLARES_CONSTRUCTOR, mixinName, | 4216 CompileTimeErrorCode.MIXIN_DECLARES_CONSTRUCTOR, |
| 4217 mixinName, |
| 4169 [mixinElement.name]); | 4218 [mixinElement.name]); |
| 4170 return true; | 4219 return true; |
| 4171 } | 4220 } |
| 4172 } | 4221 } |
| 4173 return false; | 4222 return false; |
| 4174 } | 4223 } |
| 4175 | 4224 |
| 4176 /** | 4225 /** |
| 4177 * Report the error [CompileTimeErrorCode.MIXIN_HAS_NO_CONSTRUCTORS] if | 4226 * Report the error [CompileTimeErrorCode.MIXIN_HAS_NO_CONSTRUCTORS] if |
| 4178 * appropriate. | 4227 * appropriate. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 4192 * | 4241 * |
| 4193 * See [CompileTimeErrorCode.MIXIN_INHERITS_FROM_NOT_OBJECT]. | 4242 * See [CompileTimeErrorCode.MIXIN_INHERITS_FROM_NOT_OBJECT]. |
| 4194 */ | 4243 */ |
| 4195 bool _checkForMixinInheritsNotFromObject( | 4244 bool _checkForMixinInheritsNotFromObject( |
| 4196 TypeName mixinName, ClassElement mixinElement) { | 4245 TypeName mixinName, ClassElement mixinElement) { |
| 4197 InterfaceType mixinSupertype = mixinElement.supertype; | 4246 InterfaceType mixinSupertype = mixinElement.supertype; |
| 4198 if (mixinSupertype != null) { | 4247 if (mixinSupertype != null) { |
| 4199 if (!mixinSupertype.isObject || | 4248 if (!mixinSupertype.isObject || |
| 4200 !mixinElement.isMixinApplication && mixinElement.mixins.length != 0) { | 4249 !mixinElement.isMixinApplication && mixinElement.mixins.length != 0) { |
| 4201 _errorReporter.reportErrorForNode( | 4250 _errorReporter.reportErrorForNode( |
| 4202 CompileTimeErrorCode.MIXIN_INHERITS_FROM_NOT_OBJECT, mixinName, | 4251 CompileTimeErrorCode.MIXIN_INHERITS_FROM_NOT_OBJECT, |
| 4252 mixinName, |
| 4203 [mixinElement.name]); | 4253 [mixinElement.name]); |
| 4204 return true; | 4254 return true; |
| 4205 } | 4255 } |
| 4206 } | 4256 } |
| 4207 return false; | 4257 return false; |
| 4208 } | 4258 } |
| 4209 | 4259 |
| 4210 /** | 4260 /** |
| 4211 * Verify that the given mixin does not reference 'super'. The [mixinName] is | 4261 * Verify that the given mixin does not reference 'super'. The [mixinName] is |
| 4212 * the node to report problem on. The [mixinElement] is the mixing to | 4262 * the node to report problem on. The [mixinElement] is the mixing to |
| 4213 * evaluate. | 4263 * evaluate. |
| 4214 * | 4264 * |
| 4215 * See [CompileTimeErrorCode.MIXIN_REFERENCES_SUPER]. | 4265 * See [CompileTimeErrorCode.MIXIN_REFERENCES_SUPER]. |
| 4216 */ | 4266 */ |
| 4217 bool _checkForMixinReferencesSuper( | 4267 bool _checkForMixinReferencesSuper( |
| 4218 TypeName mixinName, ClassElement mixinElement) { | 4268 TypeName mixinName, ClassElement mixinElement) { |
| 4219 if (!enableSuperMixins && mixinElement.hasReferenceToSuper) { | 4269 if (!enableSuperMixins && mixinElement.hasReferenceToSuper) { |
| 4220 _errorReporter.reportErrorForNode( | 4270 _errorReporter.reportErrorForNode( |
| 4221 CompileTimeErrorCode.MIXIN_REFERENCES_SUPER, mixinName, | 4271 CompileTimeErrorCode.MIXIN_REFERENCES_SUPER, |
| 4272 mixinName, |
| 4222 [mixinElement.name]); | 4273 [mixinElement.name]); |
| 4223 } | 4274 } |
| 4224 return false; | 4275 return false; |
| 4225 } | 4276 } |
| 4226 | 4277 |
| 4227 /** | 4278 /** |
| 4228 * Verify that the given [constructor] has at most one 'super' initializer. | 4279 * Verify that the given [constructor] has at most one 'super' initializer. |
| 4229 * | 4280 * |
| 4230 * See [CompileTimeErrorCode.MULTIPLE_SUPER_INITIALIZERS]. | 4281 * See [CompileTimeErrorCode.MULTIPLE_SUPER_INITIALIZERS]. |
| 4231 */ | 4282 */ |
| (...skipping 29 matching lines...) Expand all Loading... |
| 4261 * Verify that the given instance creation [expression] invokes an existing | 4312 * Verify that the given instance creation [expression] invokes an existing |
| 4262 * constructor. The [constructorName] is the constructor name. The [typeName] | 4313 * constructor. The [constructorName] is the constructor name. The [typeName] |
| 4263 * is the name of the type defining the constructor. | 4314 * is the name of the type defining the constructor. |
| 4264 * | 4315 * |
| 4265 * This method assumes that the instance creation was tested to be 'new' | 4316 * This method assumes that the instance creation was tested to be 'new' |
| 4266 * before being called. | 4317 * before being called. |
| 4267 * | 4318 * |
| 4268 * See [StaticWarningCode.NEW_WITH_UNDEFINED_CONSTRUCTOR]. | 4319 * See [StaticWarningCode.NEW_WITH_UNDEFINED_CONSTRUCTOR]. |
| 4269 */ | 4320 */ |
| 4270 bool _checkForNewWithUndefinedConstructor( | 4321 bool _checkForNewWithUndefinedConstructor( |
| 4271 InstanceCreationExpression expression, ConstructorName constructorName, | 4322 InstanceCreationExpression expression, |
| 4323 ConstructorName constructorName, |
| 4272 TypeName typeName) { | 4324 TypeName typeName) { |
| 4273 // OK if resolved | 4325 // OK if resolved |
| 4274 if (expression.staticElement != null) { | 4326 if (expression.staticElement != null) { |
| 4275 return false; | 4327 return false; |
| 4276 } | 4328 } |
| 4277 DartType type = typeName.type; | 4329 DartType type = typeName.type; |
| 4278 if (type is InterfaceType) { | 4330 if (type is InterfaceType) { |
| 4279 ClassElement element = type.element; | 4331 ClassElement element = type.element; |
| 4280 if (element != null && element.isEnum) { | 4332 if (element != null && element.isEnum) { |
| 4281 // We have already reported the error. | 4333 // We have already reported the error. |
| 4282 return false; | 4334 return false; |
| 4283 } | 4335 } |
| 4284 } | 4336 } |
| 4285 // prepare class name | 4337 // prepare class name |
| 4286 Identifier className = typeName.name; | 4338 Identifier className = typeName.name; |
| 4287 // report as named or default constructor absence | 4339 // report as named or default constructor absence |
| 4288 SimpleIdentifier name = constructorName.name; | 4340 SimpleIdentifier name = constructorName.name; |
| 4289 if (name != null) { | 4341 if (name != null) { |
| 4290 _errorReporter.reportErrorForNode( | 4342 _errorReporter.reportErrorForNode( |
| 4291 StaticWarningCode.NEW_WITH_UNDEFINED_CONSTRUCTOR, name, [ | 4343 StaticWarningCode.NEW_WITH_UNDEFINED_CONSTRUCTOR, |
| 4292 className, | 4344 name, |
| 4293 name | 4345 [className, name]); |
| 4294 ]); | |
| 4295 } else { | 4346 } else { |
| 4296 _errorReporter.reportErrorForNode( | 4347 _errorReporter.reportErrorForNode( |
| 4297 StaticWarningCode.NEW_WITH_UNDEFINED_CONSTRUCTOR_DEFAULT, | 4348 StaticWarningCode.NEW_WITH_UNDEFINED_CONSTRUCTOR_DEFAULT, |
| 4298 constructorName, [className]); | 4349 constructorName, |
| 4350 [className]); |
| 4299 } | 4351 } |
| 4300 return true; | 4352 return true; |
| 4301 } | 4353 } |
| 4302 | 4354 |
| 4303 /** | 4355 /** |
| 4304 * Check that if the given class [declaration] implicitly calls default | 4356 * Check that if the given class [declaration] implicitly calls default |
| 4305 * constructor of its superclass, there should be such default constructor - | 4357 * constructor of its superclass, there should be such default constructor - |
| 4306 * implicit or explicit. | 4358 * implicit or explicit. |
| 4307 * | 4359 * |
| 4308 * See [CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT]. | 4360 * See [CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT]. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 4324 if (superType == null) { | 4376 if (superType == null) { |
| 4325 return false; | 4377 return false; |
| 4326 } | 4378 } |
| 4327 ClassElement superElement = superType.element; | 4379 ClassElement superElement = superType.element; |
| 4328 // try to find default generative super constructor | 4380 // try to find default generative super constructor |
| 4329 ConstructorElement superUnnamedConstructor = | 4381 ConstructorElement superUnnamedConstructor = |
| 4330 superElement.unnamedConstructor; | 4382 superElement.unnamedConstructor; |
| 4331 if (superUnnamedConstructor != null) { | 4383 if (superUnnamedConstructor != null) { |
| 4332 if (superUnnamedConstructor.isFactory) { | 4384 if (superUnnamedConstructor.isFactory) { |
| 4333 _errorReporter.reportErrorForNode( | 4385 _errorReporter.reportErrorForNode( |
| 4334 CompileTimeErrorCode.NON_GENERATIVE_CONSTRUCTOR, declaration.name, | 4386 CompileTimeErrorCode.NON_GENERATIVE_CONSTRUCTOR, |
| 4387 declaration.name, |
| 4335 [superUnnamedConstructor]); | 4388 [superUnnamedConstructor]); |
| 4336 return true; | 4389 return true; |
| 4337 } | 4390 } |
| 4338 if (superUnnamedConstructor.isDefaultConstructor && | 4391 if (superUnnamedConstructor.isDefaultConstructor && |
| 4339 _enclosingClass | 4392 _enclosingClass |
| 4340 .isSuperConstructorAccessible(superUnnamedConstructor)) { | 4393 .isSuperConstructorAccessible(superUnnamedConstructor)) { |
| 4341 return true; | 4394 return true; |
| 4342 } | 4395 } |
| 4343 } | 4396 } |
| 4344 // report problem | 4397 // report problem |
| 4345 _errorReporter.reportErrorForNode( | 4398 _errorReporter.reportErrorForNode( |
| 4346 CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT, | 4399 CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT, |
| 4347 declaration.name, [superType.displayName]); | 4400 declaration.name, |
| 4401 [superType.displayName]); |
| 4348 return true; | 4402 return true; |
| 4349 } | 4403 } |
| 4350 | 4404 |
| 4351 /** | 4405 /** |
| 4352 * Check that the given class declaration overrides all members required by | 4406 * Check that the given class declaration overrides all members required by |
| 4353 * its superclasses and interfaces. The [classNameNode] is the | 4407 * its superclasses and interfaces. The [classNameNode] is the |
| 4354 * [SimpleIdentifier] to be used if there is a violation, this is either the | 4408 * [SimpleIdentifier] to be used if there is a violation, this is either the |
| 4355 * named from the [ClassDeclaration] or from the [ClassTypeAlias]. | 4409 * named from the [ClassDeclaration] or from the [ClassTypeAlias]. |
| 4356 * | 4410 * |
| 4357 * See [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE], | 4411 * See [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE], |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4479 } else { | 4533 } else { |
| 4480 newStrMember = "$prefix'${missingOverridesArray[i].displayName}'"; | 4534 newStrMember = "$prefix'${missingOverridesArray[i].displayName}'"; |
| 4481 } | 4535 } |
| 4482 stringMembersArrayListSet.add(newStrMember); | 4536 stringMembersArrayListSet.add(newStrMember); |
| 4483 } | 4537 } |
| 4484 List<String> stringMembersArray = new List.from(stringMembersArrayListSet); | 4538 List<String> stringMembersArray = new List.from(stringMembersArrayListSet); |
| 4485 AnalysisErrorWithProperties analysisError; | 4539 AnalysisErrorWithProperties analysisError; |
| 4486 if (stringMembersArray.length == 1) { | 4540 if (stringMembersArray.length == 1) { |
| 4487 analysisError = _errorReporter.newErrorWithProperties( | 4541 analysisError = _errorReporter.newErrorWithProperties( |
| 4488 StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE, | 4542 StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE, |
| 4489 classNameNode, [stringMembersArray[0]]); | 4543 classNameNode, |
| 4544 [stringMembersArray[0]]); |
| 4490 } else if (stringMembersArray.length == 2) { | 4545 } else if (stringMembersArray.length == 2) { |
| 4491 analysisError = _errorReporter.newErrorWithProperties( | 4546 analysisError = _errorReporter.newErrorWithProperties( |
| 4492 StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_TWO, | 4547 StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_TWO, |
| 4493 classNameNode, [stringMembersArray[0], stringMembersArray[1]]); | 4548 classNameNode, |
| 4549 [stringMembersArray[0], stringMembersArray[1]]); |
| 4494 } else if (stringMembersArray.length == 3) { | 4550 } else if (stringMembersArray.length == 3) { |
| 4495 analysisError = _errorReporter.newErrorWithProperties( | 4551 analysisError = _errorReporter.newErrorWithProperties( |
| 4496 StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_THREE, | 4552 StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_THREE, |
| 4497 classNameNode, [ | 4553 classNameNode, [ |
| 4498 stringMembersArray[0], | 4554 stringMembersArray[0], |
| 4499 stringMembersArray[1], | 4555 stringMembersArray[1], |
| 4500 stringMembersArray[2] | 4556 stringMembersArray[2] |
| 4501 ]); | 4557 ]); |
| 4502 } else if (stringMembersArray.length == 4) { | 4558 } else if (stringMembersArray.length == 4) { |
| 4503 analysisError = _errorReporter.newErrorWithProperties( | 4559 analysisError = _errorReporter.newErrorWithProperties( |
| (...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4819 RedirectingConstructorInvocation invocation = initializer; | 4875 RedirectingConstructorInvocation invocation = initializer; |
| 4820 ConstructorElement redirectingElement = invocation.staticElement; | 4876 ConstructorElement redirectingElement = invocation.staticElement; |
| 4821 if (redirectingElement == null) { | 4877 if (redirectingElement == null) { |
| 4822 String enclosingTypeName = _enclosingClass.displayName; | 4878 String enclosingTypeName = _enclosingClass.displayName; |
| 4823 String constructorStrName = enclosingTypeName; | 4879 String constructorStrName = enclosingTypeName; |
| 4824 if (invocation.constructorName != null) { | 4880 if (invocation.constructorName != null) { |
| 4825 constructorStrName += ".${invocation.constructorName.name}"; | 4881 constructorStrName += ".${invocation.constructorName.name}"; |
| 4826 } | 4882 } |
| 4827 _errorReporter.reportErrorForNode( | 4883 _errorReporter.reportErrorForNode( |
| 4828 CompileTimeErrorCode.REDIRECT_GENERATIVE_TO_MISSING_CONSTRUCTOR, | 4884 CompileTimeErrorCode.REDIRECT_GENERATIVE_TO_MISSING_CONSTRUCTOR, |
| 4829 invocation, [constructorStrName, enclosingTypeName]); | 4885 invocation, |
| 4886 [constructorStrName, enclosingTypeName]); |
| 4830 } else { | 4887 } else { |
| 4831 if (redirectingElement.isFactory) { | 4888 if (redirectingElement.isFactory) { |
| 4832 _errorReporter.reportErrorForNode( | 4889 _errorReporter.reportErrorForNode( |
| 4833 CompileTimeErrorCode.REDIRECT_GENERATIVE_TO_NON_GENERATIVE_CON
STRUCTOR, | 4890 CompileTimeErrorCode.REDIRECT_GENERATIVE_TO_NON_GENERATIVE_CON
STRUCTOR, |
| 4834 initializer); | 4891 initializer); |
| 4835 } | 4892 } |
| 4836 } | 4893 } |
| 4837 } | 4894 } |
| 4838 numRedirections++; | 4895 numRedirections++; |
| 4839 } | 4896 } |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4967 staticReturnType, | 5024 staticReturnType, |
| 4968 expectedReturnType, | 5025 expectedReturnType, |
| 4969 _enclosingFunction.displayName | 5026 _enclosingFunction.displayName |
| 4970 ]); | 5027 ]); |
| 4971 return true; | 5028 return true; |
| 4972 } | 5029 } |
| 4973 if (staticReturnType.isAssignableTo(expectedReturnType)) { | 5030 if (staticReturnType.isAssignableTo(expectedReturnType)) { |
| 4974 return false; | 5031 return false; |
| 4975 } | 5032 } |
| 4976 _errorReporter.reportTypeErrorForNode( | 5033 _errorReporter.reportTypeErrorForNode( |
| 4977 StaticTypeWarningCode.RETURN_OF_INVALID_TYPE, returnExpression, [ | 5034 StaticTypeWarningCode.RETURN_OF_INVALID_TYPE, |
| 4978 staticReturnType, | 5035 returnExpression, |
| 4979 expectedReturnType, | 5036 [staticReturnType, expectedReturnType, _enclosingFunction.displayName]); |
| 4980 _enclosingFunction.displayName | |
| 4981 ]); | |
| 4982 return true; | 5037 return true; |
| 4983 // TODO(brianwilkerson) Define a hint corresponding to the warning and | 5038 // TODO(brianwilkerson) Define a hint corresponding to the warning and |
| 4984 // report it if appropriate. | 5039 // report it if appropriate. |
| 4985 // Type propagatedReturnType = returnExpression.getPropagatedType(); | 5040 // Type propagatedReturnType = returnExpression.getPropagatedType(); |
| 4986 // boolean isPropagatedAssignable = propagatedReturnType.isAssignableTo(e
xpectedReturnType); | 5041 // boolean isPropagatedAssignable = propagatedReturnType.isAssignableTo(e
xpectedReturnType); |
| 4987 // if (isStaticAssignable || isPropagatedAssignable) { | 5042 // if (isStaticAssignable || isPropagatedAssignable) { |
| 4988 // return false; | 5043 // return false; |
| 4989 // } | 5044 // } |
| 4990 // errorReporter.reportTypeErrorForNode( | 5045 // errorReporter.reportTypeErrorForNode( |
| 4991 // StaticTypeWarningCode.RETURN_OF_INVALID_TYPE, | 5046 // StaticTypeWarningCode.RETURN_OF_INVALID_TYPE, |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5046 SwitchCase switchCase = switchMember as SwitchCase; | 5101 SwitchCase switchCase = switchMember as SwitchCase; |
| 5047 // prepare 'case' type | 5102 // prepare 'case' type |
| 5048 Expression caseExpression = switchCase.expression; | 5103 Expression caseExpression = switchCase.expression; |
| 5049 DartType caseType = getStaticType(caseExpression); | 5104 DartType caseType = getStaticType(caseExpression); |
| 5050 // check types | 5105 // check types |
| 5051 if (expressionType.isAssignableTo(caseType)) { | 5106 if (expressionType.isAssignableTo(caseType)) { |
| 5052 return false; | 5107 return false; |
| 5053 } | 5108 } |
| 5054 // report problem | 5109 // report problem |
| 5055 _errorReporter.reportErrorForNode( | 5110 _errorReporter.reportErrorForNode( |
| 5056 StaticWarningCode.SWITCH_EXPRESSION_NOT_ASSIGNABLE, expression, [ | 5111 StaticWarningCode.SWITCH_EXPRESSION_NOT_ASSIGNABLE, |
| 5057 expressionType, | 5112 expression, |
| 5058 caseType | 5113 [expressionType, caseType]); |
| 5059 ]); | |
| 5060 return true; | 5114 return true; |
| 5061 } | 5115 } |
| 5062 return false; | 5116 return false; |
| 5063 } | 5117 } |
| 5064 | 5118 |
| 5065 /** | 5119 /** |
| 5066 * Verify that the given function type [alias] does not reference itself | 5120 * Verify that the given function type [alias] does not reference itself |
| 5067 * directly. | 5121 * directly. |
| 5068 * | 5122 * |
| 5069 * See [CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REFERENCE_ITSELF]. | 5123 * See [CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REFERENCE_ITSELF]. |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5176 DartType bound = element.bound; | 5230 DartType bound = element.bound; |
| 5177 if (bound == null) { | 5231 if (bound == null) { |
| 5178 return false; | 5232 return false; |
| 5179 } | 5233 } |
| 5180 // OK, type parameter is not supertype of its bound | 5234 // OK, type parameter is not supertype of its bound |
| 5181 if (!bound.isMoreSpecificThan(element.type)) { | 5235 if (!bound.isMoreSpecificThan(element.type)) { |
| 5182 return false; | 5236 return false; |
| 5183 } | 5237 } |
| 5184 // report problem | 5238 // report problem |
| 5185 _errorReporter.reportErrorForNode( | 5239 _errorReporter.reportErrorForNode( |
| 5186 StaticTypeWarningCode.TYPE_PARAMETER_SUPERTYPE_OF_ITS_BOUND, parameter, | 5240 StaticTypeWarningCode.TYPE_PARAMETER_SUPERTYPE_OF_ITS_BOUND, |
| 5241 parameter, |
| 5187 [element.displayName]); | 5242 [element.displayName]); |
| 5188 return true; | 5243 return true; |
| 5189 } | 5244 } |
| 5190 | 5245 |
| 5191 /** | 5246 /** |
| 5192 * Check that if the given generative [constructor] has neither an explicit | 5247 * Check that if the given generative [constructor] has neither an explicit |
| 5193 * super constructor invocation nor a redirecting constructor invocation, that | 5248 * super constructor invocation nor a redirecting constructor invocation, that |
| 5194 * the superclass has a default generative constructor. | 5249 * the superclass has a default generative constructor. |
| 5195 * | 5250 * |
| 5196 * See [CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALIZER_DEFAULT], | 5251 * See [CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALIZER_DEFAULT], |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5232 if (superType == null) { | 5287 if (superType == null) { |
| 5233 return false; | 5288 return false; |
| 5234 } | 5289 } |
| 5235 ClassElement superElement = superType.element; | 5290 ClassElement superElement = superType.element; |
| 5236 ConstructorElement superUnnamedConstructor = | 5291 ConstructorElement superUnnamedConstructor = |
| 5237 superElement.unnamedConstructor; | 5292 superElement.unnamedConstructor; |
| 5238 if (superUnnamedConstructor != null) { | 5293 if (superUnnamedConstructor != null) { |
| 5239 if (superUnnamedConstructor.isFactory) { | 5294 if (superUnnamedConstructor.isFactory) { |
| 5240 _errorReporter.reportErrorForNode( | 5295 _errorReporter.reportErrorForNode( |
| 5241 CompileTimeErrorCode.NON_GENERATIVE_CONSTRUCTOR, | 5296 CompileTimeErrorCode.NON_GENERATIVE_CONSTRUCTOR, |
| 5242 constructor.returnType, [superUnnamedConstructor]); | 5297 constructor.returnType, |
| 5298 [superUnnamedConstructor]); |
| 5243 return true; | 5299 return true; |
| 5244 } | 5300 } |
| 5245 if (!superUnnamedConstructor.isDefaultConstructor || | 5301 if (!superUnnamedConstructor.isDefaultConstructor || |
| 5246 !_enclosingClass | 5302 !_enclosingClass |
| 5247 .isSuperConstructorAccessible(superUnnamedConstructor)) { | 5303 .isSuperConstructorAccessible(superUnnamedConstructor)) { |
| 5248 int offset; | 5304 int offset; |
| 5249 int length; | 5305 int length; |
| 5250 { | 5306 { |
| 5251 Identifier returnType = constructor.returnType; | 5307 Identifier returnType = constructor.returnType; |
| 5252 SimpleIdentifier name = constructor.name; | 5308 SimpleIdentifier name = constructor.name; |
| 5253 offset = returnType.offset; | 5309 offset = returnType.offset; |
| 5254 length = (name != null ? name.end : returnType.end) - offset; | 5310 length = (name != null ? name.end : returnType.end) - offset; |
| 5255 } | 5311 } |
| 5256 _errorReporter.reportErrorForOffset( | 5312 _errorReporter.reportErrorForOffset( |
| 5257 CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_EXPLICIT, offset, | 5313 CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_EXPLICIT, |
| 5258 length, [superType.displayName]); | 5314 offset, |
| 5315 length, |
| 5316 [superType.displayName]); |
| 5259 } | 5317 } |
| 5260 return false; | 5318 return false; |
| 5261 } | 5319 } |
| 5262 _errorReporter.reportErrorForNode( | 5320 _errorReporter.reportErrorForNode( |
| 5263 CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALIZER_DEFAULT, | 5321 CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALIZER_DEFAULT, |
| 5264 constructor.returnType, [superElement.name]); | 5322 constructor.returnType, |
| 5323 [superElement.name]); |
| 5265 return true; | 5324 return true; |
| 5266 } | 5325 } |
| 5267 | 5326 |
| 5268 /** | 5327 /** |
| 5269 * Check that if the given [name] is a reference to a static member it is | 5328 * Check that if the given [name] is a reference to a static member it is |
| 5270 * defined in the enclosing class rather than in a superclass. | 5329 * defined in the enclosing class rather than in a superclass. |
| 5271 * | 5330 * |
| 5272 * See [StaticTypeWarningCode.UNQUALIFIED_REFERENCE_TO_NON_LOCAL_STATIC_MEMBER
]. | 5331 * See [StaticTypeWarningCode.UNQUALIFIED_REFERENCE_TO_NON_LOCAL_STATIC_MEMBER
]. |
| 5273 */ | 5332 */ |
| 5274 bool _checkForUnqualifiedReferenceToNonLocalStaticMember( | 5333 bool _checkForUnqualifiedReferenceToNonLocalStaticMember( |
| 5275 SimpleIdentifier name) { | 5334 SimpleIdentifier name) { |
| 5276 Element element = name.staticElement; | 5335 Element element = name.staticElement; |
| 5277 if (element == null || element is TypeParameterElement) { | 5336 if (element == null || element is TypeParameterElement) { |
| 5278 return false; | 5337 return false; |
| 5279 } | 5338 } |
| 5280 Element enclosingElement = element.enclosingElement; | 5339 Element enclosingElement = element.enclosingElement; |
| 5281 if (enclosingElement is! ClassElement) { | 5340 if (enclosingElement is! ClassElement) { |
| 5282 return false; | 5341 return false; |
| 5283 } | 5342 } |
| 5284 if ((element is MethodElement && !element.isStatic) || | 5343 if ((element is MethodElement && !element.isStatic) || |
| 5285 (element is PropertyAccessorElement && !element.isStatic)) { | 5344 (element is PropertyAccessorElement && !element.isStatic)) { |
| 5286 return false; | 5345 return false; |
| 5287 } | 5346 } |
| 5288 if (identical(enclosingElement, _enclosingClass)) { | 5347 if (identical(enclosingElement, _enclosingClass)) { |
| 5289 return false; | 5348 return false; |
| 5290 } | 5349 } |
| 5291 _errorReporter.reportErrorForNode( | 5350 _errorReporter.reportErrorForNode( |
| 5292 StaticTypeWarningCode.UNQUALIFIED_REFERENCE_TO_NON_LOCAL_STATIC_MEMBER, | 5351 StaticTypeWarningCode.UNQUALIFIED_REFERENCE_TO_NON_LOCAL_STATIC_MEMBER, |
| 5293 name, [name.name]); | 5352 name, |
| 5353 [name.name]); |
| 5294 return true; | 5354 return true; |
| 5295 } | 5355 } |
| 5296 | 5356 |
| 5297 void _checkForValidField(FieldFormalParameter parameter) { | 5357 void _checkForValidField(FieldFormalParameter parameter) { |
| 5298 ParameterElement element = parameter.element; | 5358 ParameterElement element = parameter.element; |
| 5299 if (element is FieldFormalParameterElement) { | 5359 if (element is FieldFormalParameterElement) { |
| 5300 FieldElement fieldElement = element.field; | 5360 FieldElement fieldElement = element.field; |
| 5301 if (fieldElement == null || fieldElement.isSynthetic) { | 5361 if (fieldElement == null || fieldElement.isSynthetic) { |
| 5302 _errorReporter.reportErrorForNode( | 5362 _errorReporter.reportErrorForNode( |
| 5303 CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_NON_EXISTENT_FIELD, | 5363 CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_NON_EXISTENT_FIELD, |
| 5304 parameter, [parameter.identifier.name]); | 5364 parameter, |
| 5365 [parameter.identifier.name]); |
| 5305 } else { | 5366 } else { |
| 5306 ParameterElement parameterElement = parameter.element; | 5367 ParameterElement parameterElement = parameter.element; |
| 5307 if (parameterElement is FieldFormalParameterElementImpl) { | 5368 if (parameterElement is FieldFormalParameterElementImpl) { |
| 5308 FieldFormalParameterElementImpl fieldFormal = parameterElement; | 5369 FieldFormalParameterElementImpl fieldFormal = parameterElement; |
| 5309 DartType declaredType = fieldFormal.type; | 5370 DartType declaredType = fieldFormal.type; |
| 5310 DartType fieldType = fieldElement.type; | 5371 DartType fieldType = fieldElement.type; |
| 5311 if (fieldElement.isSynthetic) { | 5372 if (fieldElement.isSynthetic) { |
| 5312 _errorReporter.reportErrorForNode( | 5373 _errorReporter.reportErrorForNode( |
| 5313 CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_NON_EXISTENT_FIELD, | 5374 CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_NON_EXISTENT_FIELD, |
| 5314 parameter, [parameter.identifier.name]); | 5375 parameter, |
| 5376 [parameter.identifier.name]); |
| 5315 } else if (fieldElement.isStatic) { | 5377 } else if (fieldElement.isStatic) { |
| 5316 _errorReporter.reportErrorForNode( | 5378 _errorReporter.reportErrorForNode( |
| 5317 CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_STATIC_FIELD, | 5379 CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_STATIC_FIELD, |
| 5318 parameter, [parameter.identifier.name]); | 5380 parameter, |
| 5381 [parameter.identifier.name]); |
| 5319 } else if (declaredType != null && | 5382 } else if (declaredType != null && |
| 5320 fieldType != null && | 5383 fieldType != null && |
| 5321 !declaredType.isAssignableTo(fieldType)) { | 5384 !declaredType.isAssignableTo(fieldType)) { |
| 5322 _errorReporter.reportTypeErrorForNode( | 5385 _errorReporter.reportTypeErrorForNode( |
| 5323 StaticWarningCode.FIELD_INITIALIZING_FORMAL_NOT_ASSIGNABLE, | 5386 StaticWarningCode.FIELD_INITIALIZING_FORMAL_NOT_ASSIGNABLE, |
| 5324 parameter, [declaredType, fieldType]); | 5387 parameter, |
| 5388 [declaredType, fieldType]); |
| 5325 } | 5389 } |
| 5326 } else { | 5390 } else { |
| 5327 if (fieldElement.isSynthetic) { | 5391 if (fieldElement.isSynthetic) { |
| 5328 _errorReporter.reportErrorForNode( | 5392 _errorReporter.reportErrorForNode( |
| 5329 CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_NON_EXISTENT_FIELD, | 5393 CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_NON_EXISTENT_FIELD, |
| 5330 parameter, [parameter.identifier.name]); | 5394 parameter, |
| 5395 [parameter.identifier.name]); |
| 5331 } else if (fieldElement.isStatic) { | 5396 } else if (fieldElement.isStatic) { |
| 5332 _errorReporter.reportErrorForNode( | 5397 _errorReporter.reportErrorForNode( |
| 5333 CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_STATIC_FIELD, | 5398 CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_STATIC_FIELD, |
| 5334 parameter, [parameter.identifier.name]); | 5399 parameter, |
| 5400 [parameter.identifier.name]); |
| 5335 } | 5401 } |
| 5336 } | 5402 } |
| 5337 } | 5403 } |
| 5338 } | 5404 } |
| 5339 // else { | 5405 // else { |
| 5340 // // TODO(jwren) Report error, constructor initializer variable is a top
level element | 5406 // // TODO(jwren) Report error, constructor initializer variable is a top
level element |
| 5341 // // (Either here or in ErrorVerifier.checkForAllFinalInitializedErrorCo
des) | 5407 // // (Either here or in ErrorVerifier.checkForAllFinalInitializedErrorCo
des) |
| 5342 // } | 5408 // } |
| 5343 } | 5409 } |
| 5344 | 5410 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5400 "<<" == name || | 5466 "<<" == name || |
| 5401 ">>" == name || | 5467 ">>" == name || |
| 5402 "[]" == name) { | 5468 "[]" == name) { |
| 5403 expected = 1; | 5469 expected = 1; |
| 5404 } else if ("~" == name) { | 5470 } else if ("~" == name) { |
| 5405 expected = 0; | 5471 expected = 0; |
| 5406 } | 5472 } |
| 5407 if (expected != -1 && numParameters != expected) { | 5473 if (expected != -1 && numParameters != expected) { |
| 5408 _errorReporter.reportErrorForNode( | 5474 _errorReporter.reportErrorForNode( |
| 5409 CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_OPERATOR, | 5475 CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_OPERATOR, |
| 5410 nameNode, [name, expected, numParameters]); | 5476 nameNode, |
| 5477 [name, expected, numParameters]); |
| 5411 return true; | 5478 return true; |
| 5412 } | 5479 } |
| 5413 // check for operator "-" | 5480 // check for operator "-" |
| 5414 if ("-" == name && numParameters > 1) { | 5481 if ("-" == name && numParameters > 1) { |
| 5415 _errorReporter.reportErrorForNode( | 5482 _errorReporter.reportErrorForNode( |
| 5416 CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_OPERATOR_MINUS, | 5483 CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_OPERATOR_MINUS, |
| 5417 nameNode, [numParameters]); | 5484 nameNode, |
| 5485 [numParameters]); |
| 5418 return true; | 5486 return true; |
| 5419 } | 5487 } |
| 5420 // OK | 5488 // OK |
| 5421 return false; | 5489 return false; |
| 5422 } | 5490 } |
| 5423 | 5491 |
| 5424 /** | 5492 /** |
| 5425 * Verify that the given setter [parameterList] has only one required | 5493 * Verify that the given setter [parameterList] has only one required |
| 5426 * parameter. The [setterName] is the name of the setter to report problems | 5494 * parameter. The [setterName] is the name of the setter to report problems |
| 5427 * on. | 5495 * on. |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5469 impliedReturnType = staticYieldedType; | 5537 impliedReturnType = staticYieldedType; |
| 5470 } else if (_enclosingFunction.isAsynchronous) { | 5538 } else if (_enclosingFunction.isAsynchronous) { |
| 5471 impliedReturnType = | 5539 impliedReturnType = |
| 5472 _typeProvider.streamType.substitute4(<DartType>[staticYieldedType]); | 5540 _typeProvider.streamType.substitute4(<DartType>[staticYieldedType]); |
| 5473 } else { | 5541 } else { |
| 5474 impliedReturnType = | 5542 impliedReturnType = |
| 5475 _typeProvider.iterableType.substitute4(<DartType>[staticYieldedType]); | 5543 _typeProvider.iterableType.substitute4(<DartType>[staticYieldedType]); |
| 5476 } | 5544 } |
| 5477 if (!impliedReturnType.isAssignableTo(declaredReturnType)) { | 5545 if (!impliedReturnType.isAssignableTo(declaredReturnType)) { |
| 5478 _errorReporter.reportTypeErrorForNode( | 5546 _errorReporter.reportTypeErrorForNode( |
| 5479 StaticTypeWarningCode.YIELD_OF_INVALID_TYPE, yieldExpression, [ | 5547 StaticTypeWarningCode.YIELD_OF_INVALID_TYPE, |
| 5480 impliedReturnType, | 5548 yieldExpression, |
| 5481 declaredReturnType | 5549 [impliedReturnType, declaredReturnType]); |
| 5482 ]); | |
| 5483 return true; | 5550 return true; |
| 5484 } | 5551 } |
| 5485 if (isYieldEach) { | 5552 if (isYieldEach) { |
| 5486 // Since the declared return type might have been "dynamic", we need to | 5553 // Since the declared return type might have been "dynamic", we need to |
| 5487 // also check that the implied return type is assignable to generic | 5554 // also check that the implied return type is assignable to generic |
| 5488 // Stream/Iterable. | 5555 // Stream/Iterable. |
| 5489 DartType requiredReturnType; | 5556 DartType requiredReturnType; |
| 5490 if (_enclosingFunction.isAsynchronous) { | 5557 if (_enclosingFunction.isAsynchronous) { |
| 5491 requiredReturnType = _typeProvider.streamDynamicType; | 5558 requiredReturnType = _typeProvider.streamDynamicType; |
| 5492 } else { | 5559 } else { |
| 5493 requiredReturnType = _typeProvider.iterableDynamicType; | 5560 requiredReturnType = _typeProvider.iterableDynamicType; |
| 5494 } | 5561 } |
| 5495 if (!impliedReturnType.isAssignableTo(requiredReturnType)) { | 5562 if (!impliedReturnType.isAssignableTo(requiredReturnType)) { |
| 5496 _errorReporter.reportTypeErrorForNode( | 5563 _errorReporter.reportTypeErrorForNode( |
| 5497 StaticTypeWarningCode.YIELD_OF_INVALID_TYPE, yieldExpression, [ | 5564 StaticTypeWarningCode.YIELD_OF_INVALID_TYPE, |
| 5498 impliedReturnType, | 5565 yieldExpression, |
| 5499 requiredReturnType | 5566 [impliedReturnType, requiredReturnType]); |
| 5500 ]); | |
| 5501 return true; | 5567 return true; |
| 5502 } | 5568 } |
| 5503 } | 5569 } |
| 5504 return false; | 5570 return false; |
| 5505 } | 5571 } |
| 5506 | 5572 |
| 5507 /** | 5573 /** |
| 5508 * Verify that if the given class [declaration] implements the class Function | 5574 * Verify that if the given class [declaration] implements the class Function |
| 5509 * that it has a concrete implementation of the call method. | 5575 * that it has a concrete implementation of the call method. |
| 5510 * | 5576 * |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5555 ImplementsClause implementsClause = declaration.implementsClause; | 5621 ImplementsClause implementsClause = declaration.implementsClause; |
| 5556 if (implementsClause == null) { | 5622 if (implementsClause == null) { |
| 5557 return false; | 5623 return false; |
| 5558 } | 5624 } |
| 5559 // check interfaces | 5625 // check interfaces |
| 5560 bool hasProblem = false; | 5626 bool hasProblem = false; |
| 5561 for (TypeName interfaceNode in implementsClause.interfaces) { | 5627 for (TypeName interfaceNode in implementsClause.interfaces) { |
| 5562 if (interfaceNode.type == superType) { | 5628 if (interfaceNode.type == superType) { |
| 5563 hasProblem = true; | 5629 hasProblem = true; |
| 5564 _errorReporter.reportErrorForNode( | 5630 _errorReporter.reportErrorForNode( |
| 5565 CompileTimeErrorCode.IMPLEMENTS_SUPER_CLASS, interfaceNode, | 5631 CompileTimeErrorCode.IMPLEMENTS_SUPER_CLASS, |
| 5632 interfaceNode, |
| 5566 [superType.displayName]); | 5633 [superType.displayName]); |
| 5567 } | 5634 } |
| 5568 } | 5635 } |
| 5569 // done | 5636 // done |
| 5570 return hasProblem; | 5637 return hasProblem; |
| 5571 } | 5638 } |
| 5572 | 5639 |
| 5573 DartType _computeReturnTypeForMethod(Expression returnExpression) { | 5640 DartType _computeReturnTypeForMethod(Expression returnExpression) { |
| 5574 // This method should never be called for generators, since generators are | 5641 // This method should never be called for generators, since generators are |
| 5575 // never allowed to contain return statements with expressions. | 5642 // never allowed to contain return statements with expressions. |
| (...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5876 // "A, B, C, D, A" | 5943 // "A, B, C, D, A" |
| 5877 String separator = ", "; | 5944 String separator = ", "; |
| 5878 StringBuffer buffer = new StringBuffer(); | 5945 StringBuffer buffer = new StringBuffer(); |
| 5879 for (int i = 0; i < size; i++) { | 5946 for (int i = 0; i < size; i++) { |
| 5880 buffer.write(path[i].displayName); | 5947 buffer.write(path[i].displayName); |
| 5881 buffer.write(separator); | 5948 buffer.write(separator); |
| 5882 } | 5949 } |
| 5883 buffer.write(element.displayName); | 5950 buffer.write(element.displayName); |
| 5884 _errorReporter.reportErrorForOffset( | 5951 _errorReporter.reportErrorForOffset( |
| 5885 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE, | 5952 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE, |
| 5886 _enclosingClass.nameOffset, enclosingClassName.length, [ | 5953 _enclosingClass.nameOffset, |
| 5887 enclosingClassName, | 5954 enclosingClassName.length, |
| 5888 buffer.toString() | 5955 [enclosingClassName, buffer.toString()]); |
| 5889 ]); | |
| 5890 return true; | 5956 return true; |
| 5891 } else { | 5957 } else { |
| 5892 // RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_EXTENDS or | 5958 // RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_EXTENDS or |
| 5893 // RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_IMPLEMENTS or | 5959 // RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_IMPLEMENTS or |
| 5894 // RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_WITH | 5960 // RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_WITH |
| 5895 _errorReporter.reportErrorForOffset(_getBaseCaseErrorCode(element), | 5961 _errorReporter.reportErrorForOffset( |
| 5896 _enclosingClass.nameOffset, enclosingClassName.length, | 5962 _getBaseCaseErrorCode(element), |
| 5963 _enclosingClass.nameOffset, |
| 5964 enclosingClassName.length, |
| 5897 [enclosingClassName]); | 5965 [enclosingClassName]); |
| 5898 return true; | 5966 return true; |
| 5899 } | 5967 } |
| 5900 } | 5968 } |
| 5901 if (path.indexOf(element) > 0) { | 5969 if (path.indexOf(element) > 0) { |
| 5902 return false; | 5970 return false; |
| 5903 } | 5971 } |
| 5904 path.add(element); | 5972 path.add(element); |
| 5905 // n-case | 5973 // n-case |
| 5906 InterfaceType supertype = element.supertype; | 5974 InterfaceType supertype = element.supertype; |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5992 toCheck.add(type.element); | 6060 toCheck.add(type.element); |
| 5993 // type arguments | 6061 // type arguments |
| 5994 if (type is InterfaceType) { | 6062 if (type is InterfaceType) { |
| 5995 InterfaceType interfaceType = type; | 6063 InterfaceType interfaceType = type; |
| 5996 for (DartType typeArgument in interfaceType.typeArguments) { | 6064 for (DartType typeArgument in interfaceType.typeArguments) { |
| 5997 _addTypeToCheck(typeArgument); | 6065 _addTypeToCheck(typeArgument); |
| 5998 } | 6066 } |
| 5999 } | 6067 } |
| 6000 } | 6068 } |
| 6001 } | 6069 } |
| OLD | NEW |