Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(349)

Side by Side Diff: pkg/analyzer/lib/src/generated/error_verifier.dart

Issue 1309543011: Add support for assert statements with messages to the analyzer. Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 * The type representing the type 'bool'. 58 * The type representing the type 'bool'.
59 */ 59 */
60 InterfaceType _boolType; 60 InterfaceType _boolType;
61 61
62 /** 62 /**
63 * The type representing the type 'int'. 63 * The type representing the type 'int'.
64 */ 64 */
65 InterfaceType _intType; 65 InterfaceType _intType;
66 66
67 /** 67 /**
68 * The type representing the type `String`.
69 */
70 InterfaceType _stringType;
71
72 /**
68 * The object providing access to the types defined by the language. 73 * The object providing access to the types defined by the language.
69 */ 74 */
70 final TypeProvider _typeProvider; 75 final TypeProvider _typeProvider;
71 76
72 /** 77 /**
73 * The manager for the inheritance mappings. 78 * The manager for the inheritance mappings.
74 */ 79 */
75 final InheritanceManager _inheritanceManager; 80 final InheritanceManager _inheritanceManager;
76 81
77 /** 82 /**
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 this._hasExtUri = _currentLibrary.hasExtUri; 274 this._hasExtUri = _currentLibrary.hasExtUri;
270 _isEnclosingConstructorConst = false; 275 _isEnclosingConstructorConst = false;
271 _isInCatchClause = false; 276 _isInCatchClause = false;
272 _isInStaticVariableDeclaration = false; 277 _isInStaticVariableDeclaration = false;
273 _isInInstanceVariableDeclaration = false; 278 _isInInstanceVariableDeclaration = false;
274 _isInInstanceVariableInitializer = false; 279 _isInInstanceVariableInitializer = false;
275 _isInConstructorInitializer = false; 280 _isInConstructorInitializer = false;
276 _isInStaticMethod = false; 281 _isInStaticMethod = false;
277 _boolType = _typeProvider.boolType; 282 _boolType = _typeProvider.boolType;
278 _intType = _typeProvider.intType; 283 _intType = _typeProvider.intType;
284 _stringType = _typeProvider.stringType;
279 _DISALLOWED_TYPES_TO_EXTEND_OR_IMPLEMENT = _typeProvider.nonSubtypableTypes; 285 _DISALLOWED_TYPES_TO_EXTEND_OR_IMPLEMENT = _typeProvider.nonSubtypableTypes;
280 } 286 }
281 287
282 @override 288 @override
283 Object visitAnnotation(Annotation node) { 289 Object visitAnnotation(Annotation node) {
284 _checkForInvalidAnnotationFromDeferredLibrary(node); 290 _checkForInvalidAnnotationFromDeferredLibrary(node);
285 return super.visitAnnotation(node); 291 return super.visitAnnotation(node);
286 } 292 }
287 293
288 @override 294 @override
289 Object visitArgumentList(ArgumentList node) { 295 Object visitArgumentList(ArgumentList node) {
290 _checkForArgumentTypesNotAssignableInList(node); 296 _checkForArgumentTypesNotAssignableInList(node);
291 return super.visitArgumentList(node); 297 return super.visitArgumentList(node);
292 } 298 }
293 299
294 @override 300 @override
295 Object visitAsExpression(AsExpression node) { 301 Object visitAsExpression(AsExpression node) {
296 _checkForTypeAnnotationDeferredClass(node.type); 302 _checkForTypeAnnotationDeferredClass(node.type);
297 return super.visitAsExpression(node); 303 return super.visitAsExpression(node);
298 } 304 }
299 305
300 @override 306 @override
301 Object visitAssertStatement(AssertStatement node) { 307 Object visitAssertStatement(AssertStatement node) {
302 _checkForNonBoolExpression(node); 308 _checkForNonBoolExpression(node);
309 _checkForNonStringMessage(node);
303 return super.visitAssertStatement(node); 310 return super.visitAssertStatement(node);
304 } 311 }
305 312
306 @override 313 @override
307 Object visitAssignmentExpression(AssignmentExpression node) { 314 Object visitAssignmentExpression(AssignmentExpression node) {
308 sc.TokenType operatorType = node.operator.type; 315 sc.TokenType operatorType = node.operator.type;
309 Expression lhs = node.leftHandSide; 316 Expression lhs = node.leftHandSide;
310 Expression rhs = node.rightHandSide; 317 Expression rhs = node.rightHandSide;
311 if (operatorType == sc.TokenType.EQ || 318 if (operatorType == sc.TokenType.EQ ||
312 operatorType == sc.TokenType.QUESTION_QUESTION_EQ) { 319 operatorType == sc.TokenType.QUESTION_QUESTION_EQ) {
(...skipping 805 matching lines...) Expand 10 before | Expand all | Expand 10 after
1118 * See [StaticTypeWarningCode.EXPECTED_TWO_MAP_TYPE_ARGUMENTS]. 1125 * See [StaticTypeWarningCode.EXPECTED_TWO_MAP_TYPE_ARGUMENTS].
1119 */ 1126 */
1120 bool _checkExpectedTwoMapTypeArguments(TypeArgumentList typeArguments) { 1127 bool _checkExpectedTwoMapTypeArguments(TypeArgumentList typeArguments) {
1121 // check number of type arguments 1128 // check number of type arguments
1122 int num = typeArguments.arguments.length; 1129 int num = typeArguments.arguments.length;
1123 if (num == 2) { 1130 if (num == 2) {
1124 return false; 1131 return false;
1125 } 1132 }
1126 // report problem 1133 // report problem
1127 _errorReporter.reportErrorForNode( 1134 _errorReporter.reportErrorForNode(
1128 StaticTypeWarningCode.EXPECTED_TWO_MAP_TYPE_ARGUMENTS, typeArguments, 1135 StaticTypeWarningCode.EXPECTED_TWO_MAP_TYPE_ARGUMENTS,
1136 typeArguments,
1129 [num]); 1137 [num]);
1130 return true; 1138 return true;
1131 } 1139 }
1132 1140
1133 /** 1141 /**
1134 * Verify that the given [constructor] declaration does not violate any of the 1142 * Verify that the given [constructor] declaration does not violate any of the
1135 * error codes relating to the initialization of fields in the enclosing 1143 * error codes relating to the initialization of fields in the enclosing
1136 * class. 1144 * class.
1137 * 1145 *
1138 * See [_initialFieldElementsMap], 1146 * See [_initialFieldElementsMap],
(...skipping 25 matching lines...) Expand all
1164 if (parameter is FieldFormalParameter) { 1172 if (parameter is FieldFormalParameter) {
1165 FieldElement fieldElement = 1173 FieldElement fieldElement =
1166 (parameter.element as FieldFormalParameterElementImpl).field; 1174 (parameter.element as FieldFormalParameterElementImpl).field;
1167 INIT_STATE state = fieldElementsMap[fieldElement]; 1175 INIT_STATE state = fieldElementsMap[fieldElement];
1168 if (state == INIT_STATE.NOT_INIT) { 1176 if (state == INIT_STATE.NOT_INIT) {
1169 fieldElementsMap[fieldElement] = INIT_STATE.INIT_IN_FIELD_FORMAL; 1177 fieldElementsMap[fieldElement] = INIT_STATE.INIT_IN_FIELD_FORMAL;
1170 } else if (state == INIT_STATE.INIT_IN_DECLARATION) { 1178 } else if (state == INIT_STATE.INIT_IN_DECLARATION) {
1171 if (fieldElement.isFinal || fieldElement.isConst) { 1179 if (fieldElement.isFinal || fieldElement.isConst) {
1172 _errorReporter.reportErrorForNode( 1180 _errorReporter.reportErrorForNode(
1173 StaticWarningCode.FINAL_INITIALIZED_IN_DECLARATION_AND_CONSTRUCT OR, 1181 StaticWarningCode.FINAL_INITIALIZED_IN_DECLARATION_AND_CONSTRUCT OR,
1174 formalParameter.identifier, [fieldElement.displayName]); 1182 formalParameter.identifier,
1183 [fieldElement.displayName]);
1175 foundError = true; 1184 foundError = true;
1176 } 1185 }
1177 } else if (state == INIT_STATE.INIT_IN_FIELD_FORMAL) { 1186 } else if (state == INIT_STATE.INIT_IN_FIELD_FORMAL) {
1178 if (fieldElement.isFinal || fieldElement.isConst) { 1187 if (fieldElement.isFinal || fieldElement.isConst) {
1179 _errorReporter.reportErrorForNode( 1188 _errorReporter.reportErrorForNode(
1180 CompileTimeErrorCode.FINAL_INITIALIZED_MULTIPLE_TIMES, 1189 CompileTimeErrorCode.FINAL_INITIALIZED_MULTIPLE_TIMES,
1181 formalParameter.identifier, [fieldElement.displayName]); 1190 formalParameter.identifier,
1191 [fieldElement.displayName]);
1182 foundError = true; 1192 foundError = true;
1183 } 1193 }
1184 } 1194 }
1185 } 1195 }
1186 } 1196 }
1187 // Visit all of the initializers 1197 // Visit all of the initializers
1188 NodeList<ConstructorInitializer> initializers = constructor.initializers; 1198 NodeList<ConstructorInitializer> initializers = constructor.initializers;
1189 for (ConstructorInitializer constructorInitializer in initializers) { 1199 for (ConstructorInitializer constructorInitializer in initializers) {
1190 if (constructorInitializer is RedirectingConstructorInvocation) { 1200 if (constructorInitializer is RedirectingConstructorInvocation) {
1191 return false; 1201 return false;
(...skipping 16 matching lines...) Expand all
1208 foundError = true; 1218 foundError = true;
1209 } 1219 }
1210 } else if (state == INIT_STATE.INIT_IN_FIELD_FORMAL) { 1220 } else if (state == INIT_STATE.INIT_IN_FIELD_FORMAL) {
1211 _errorReporter.reportErrorForNode( 1221 _errorReporter.reportErrorForNode(
1212 CompileTimeErrorCode.FIELD_INITIALIZED_IN_PARAMETER_AND_INITIALI ZER, 1222 CompileTimeErrorCode.FIELD_INITIALIZED_IN_PARAMETER_AND_INITIALI ZER,
1213 fieldName); 1223 fieldName);
1214 foundError = true; 1224 foundError = true;
1215 } else if (state == INIT_STATE.INIT_IN_INITIALIZERS) { 1225 } else if (state == INIT_STATE.INIT_IN_INITIALIZERS) {
1216 _errorReporter.reportErrorForNode( 1226 _errorReporter.reportErrorForNode(
1217 CompileTimeErrorCode.FIELD_INITIALIZED_BY_MULTIPLE_INITIALIZERS, 1227 CompileTimeErrorCode.FIELD_INITIALIZED_BY_MULTIPLE_INITIALIZERS,
1218 fieldName, [fieldElement.displayName]); 1228 fieldName,
1229 [fieldElement.displayName]);
1219 foundError = true; 1230 foundError = true;
1220 } 1231 }
1221 } 1232 }
1222 } 1233 }
1223 } 1234 }
1224 // Prepare a list of not initialized fields. 1235 // Prepare a list of not initialized fields.
1225 List<FieldElement> notInitFinalFields = <FieldElement>[]; 1236 List<FieldElement> notInitFinalFields = <FieldElement>[];
1226 fieldElementsMap.forEach((FieldElement fieldElement, INIT_STATE state) { 1237 fieldElementsMap.forEach((FieldElement fieldElement, INIT_STATE state) {
1227 if (state == INIT_STATE.NOT_INIT) { 1238 if (state == INIT_STATE.NOT_INIT) {
1228 if (fieldElement.isFinal) { 1239 if (fieldElement.isFinal) {
1229 notInitFinalFields.add(fieldElement); 1240 notInitFinalFields.add(fieldElement);
1230 } 1241 }
1231 } 1242 }
1232 }); 1243 });
1233 // Visit all of the states in the map to ensure that none were never 1244 // Visit all of the states in the map to ensure that none were never
1234 // initialized. 1245 // initialized.
1235 fieldElementsMap.forEach((FieldElement fieldElement, INIT_STATE state) { 1246 fieldElementsMap.forEach((FieldElement fieldElement, INIT_STATE state) {
1236 if (state == INIT_STATE.NOT_INIT) { 1247 if (state == INIT_STATE.NOT_INIT) {
1237 if (fieldElement.isConst) { 1248 if (fieldElement.isConst) {
1238 _errorReporter.reportErrorForNode( 1249 _errorReporter.reportErrorForNode(
1239 CompileTimeErrorCode.CONST_NOT_INITIALIZED, 1250 CompileTimeErrorCode.CONST_NOT_INITIALIZED,
1240 constructor.returnType, [fieldElement.name]); 1251 constructor.returnType,
1252 [fieldElement.name]);
1241 foundError = true; 1253 foundError = true;
1242 } 1254 }
1243 } 1255 }
1244 }); 1256 });
1245 if (notInitFinalFields.isNotEmpty) { 1257 if (notInitFinalFields.isNotEmpty) {
1246 foundError = true; 1258 foundError = true;
1247 AnalysisErrorWithProperties analysisError; 1259 AnalysisErrorWithProperties analysisError;
1248 if (notInitFinalFields.length == 1) { 1260 if (notInitFinalFields.length == 1) {
1249 analysisError = _errorReporter.newErrorWithProperties( 1261 analysisError = _errorReporter.newErrorWithProperties(
1250 StaticWarningCode.FINAL_NOT_INITIALIZED_CONSTRUCTOR_1, 1262 StaticWarningCode.FINAL_NOT_INITIALIZED_CONSTRUCTOR_1,
1251 constructor.returnType, [notInitFinalFields[0].name]); 1263 constructor.returnType,
1264 [notInitFinalFields[0].name]);
1252 } else if (notInitFinalFields.length == 2) { 1265 } else if (notInitFinalFields.length == 2) {
1253 analysisError = _errorReporter.newErrorWithProperties( 1266 analysisError = _errorReporter.newErrorWithProperties(
1254 StaticWarningCode.FINAL_NOT_INITIALIZED_CONSTRUCTOR_2, 1267 StaticWarningCode.FINAL_NOT_INITIALIZED_CONSTRUCTOR_2,
1255 constructor.returnType, [ 1268 constructor.returnType,
1256 notInitFinalFields[0].name, 1269 [notInitFinalFields[0].name, notInitFinalFields[1].name]);
1257 notInitFinalFields[1].name
1258 ]);
1259 } else { 1270 } else {
1260 analysisError = _errorReporter.newErrorWithProperties( 1271 analysisError = _errorReporter.newErrorWithProperties(
1261 StaticWarningCode.FINAL_NOT_INITIALIZED_CONSTRUCTOR_3_PLUS, 1272 StaticWarningCode.FINAL_NOT_INITIALIZED_CONSTRUCTOR_3_PLUS,
1262 constructor.returnType, [ 1273 constructor.returnType, [
1263 notInitFinalFields[0].name, 1274 notInitFinalFields[0].name,
1264 notInitFinalFields[1].name, 1275 notInitFinalFields[1].name,
1265 notInitFinalFields.length - 2 1276 notInitFinalFields.length - 2
1266 ]); 1277 ]);
1267 } 1278 }
1268 analysisError.setProperty( 1279 analysisError.setProperty(
(...skipping 16 matching lines...) Expand all
1285 * [StaticWarningCode.INVALID_GETTER_OVERRIDE_RETURN_TYPE], 1296 * [StaticWarningCode.INVALID_GETTER_OVERRIDE_RETURN_TYPE],
1286 * [StaticWarningCode.INVALID_METHOD_OVERRIDE_RETURN_TYPE], 1297 * [StaticWarningCode.INVALID_METHOD_OVERRIDE_RETURN_TYPE],
1287 * [StaticWarningCode.INVALID_METHOD_OVERRIDE_NORMAL_PARAM_TYPE], 1298 * [StaticWarningCode.INVALID_METHOD_OVERRIDE_NORMAL_PARAM_TYPE],
1288 * [StaticWarningCode.INVALID_SETTER_OVERRIDE_NORMAL_PARAM_TYPE], 1299 * [StaticWarningCode.INVALID_SETTER_OVERRIDE_NORMAL_PARAM_TYPE],
1289 * [StaticWarningCode.INVALID_METHOD_OVERRIDE_OPTIONAL_PARAM_TYPE], 1300 * [StaticWarningCode.INVALID_METHOD_OVERRIDE_OPTIONAL_PARAM_TYPE],
1290 * [StaticWarningCode.INVALID_METHOD_OVERRIDE_NAMED_PARAM_TYPE], and 1301 * [StaticWarningCode.INVALID_METHOD_OVERRIDE_NAMED_PARAM_TYPE], and
1291 * [StaticWarningCode.INVALID_OVERRIDE_DIFFERENT_DEFAULT_VALUES]. 1302 * [StaticWarningCode.INVALID_OVERRIDE_DIFFERENT_DEFAULT_VALUES].
1292 */ 1303 */
1293 bool _checkForAllInvalidOverrideErrorCodes( 1304 bool _checkForAllInvalidOverrideErrorCodes(
1294 ExecutableElement executableElement, 1305 ExecutableElement executableElement,
1295 ExecutableElement overriddenExecutable, List<ParameterElement> parameters, 1306 ExecutableElement overriddenExecutable,
1296 List<AstNode> parameterLocations, SimpleIdentifier errorNameTarget) { 1307 List<ParameterElement> parameters,
1308 List<AstNode> parameterLocations,
1309 SimpleIdentifier errorNameTarget) {
1297 bool isGetter = false; 1310 bool isGetter = false;
1298 bool isSetter = false; 1311 bool isSetter = false;
1299 if (executableElement is PropertyAccessorElement) { 1312 if (executableElement is PropertyAccessorElement) {
1300 PropertyAccessorElement accessorElement = executableElement; 1313 PropertyAccessorElement accessorElement = executableElement;
1301 isGetter = accessorElement.isGetter; 1314 isGetter = accessorElement.isGetter;
1302 isSetter = accessorElement.isSetter; 1315 isSetter = accessorElement.isSetter;
1303 } 1316 }
1304 String executableElementName = executableElement.name; 1317 String executableElementName = executableElement.name;
1305 FunctionType overridingFT = executableElement.type; 1318 FunctionType overridingFT = executableElement.type;
1306 FunctionType overriddenFT = overriddenExecutable.type; 1319 FunctionType overriddenFT = overriddenExecutable.type;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1348 StaticWarningCode.INVALID_OVERRIDE_NAMED, errorNameTarget, [ 1361 StaticWarningCode.INVALID_OVERRIDE_NAMED, errorNameTarget, [
1349 overriddenParamName, 1362 overriddenParamName,
1350 overriddenExecutable.enclosingElement.displayName 1363 overriddenExecutable.enclosingElement.displayName
1351 ]); 1364 ]);
1352 return true; 1365 return true;
1353 } 1366 }
1354 } 1367 }
1355 // SWC.INVALID_METHOD_OVERRIDE_RETURN_TYPE 1368 // SWC.INVALID_METHOD_OVERRIDE_RETURN_TYPE
1356 if (overriddenFTReturnType != VoidTypeImpl.instance && 1369 if (overriddenFTReturnType != VoidTypeImpl.instance &&
1357 !overridingFTReturnType.isAssignableTo(overriddenFTReturnType)) { 1370 !overridingFTReturnType.isAssignableTo(overriddenFTReturnType)) {
1358 _errorReporter.reportTypeErrorForNode(!isGetter 1371 _errorReporter.reportTypeErrorForNode(
1372 !isGetter
1359 ? StaticWarningCode.INVALID_METHOD_OVERRIDE_RETURN_TYPE 1373 ? StaticWarningCode.INVALID_METHOD_OVERRIDE_RETURN_TYPE
1360 : StaticWarningCode.INVALID_GETTER_OVERRIDE_RETURN_TYPE, 1374 : StaticWarningCode.INVALID_GETTER_OVERRIDE_RETURN_TYPE,
1361 errorNameTarget, [ 1375 errorNameTarget,
1376 [
1362 overridingFTReturnType, 1377 overridingFTReturnType,
1363 overriddenFTReturnType, 1378 overriddenFTReturnType,
1364 overriddenExecutable.enclosingElement.displayName 1379 overriddenExecutable.enclosingElement.displayName
1365 ]); 1380 ]);
1366 return true; 1381 return true;
1367 } 1382 }
1368 // SWC.INVALID_METHOD_OVERRIDE_NORMAL_PARAM_TYPE 1383 // SWC.INVALID_METHOD_OVERRIDE_NORMAL_PARAM_TYPE
1369 if (parameterLocations == null) { 1384 if (parameterLocations == null) {
1370 return false; 1385 return false;
1371 } 1386 }
1372 int parameterIndex = 0; 1387 int parameterIndex = 0;
1373 for (int i = 0; i < overridingNormalPT.length; i++) { 1388 for (int i = 0; i < overridingNormalPT.length; i++) {
1374 if (!overridingNormalPT[i].isAssignableTo(overriddenNormalPT[i])) { 1389 if (!overridingNormalPT[i].isAssignableTo(overriddenNormalPT[i])) {
1375 _errorReporter.reportTypeErrorForNode(!isSetter 1390 _errorReporter.reportTypeErrorForNode(
1391 !isSetter
1376 ? StaticWarningCode.INVALID_METHOD_OVERRIDE_NORMAL_PARAM_TYPE 1392 ? StaticWarningCode.INVALID_METHOD_OVERRIDE_NORMAL_PARAM_TYPE
1377 : StaticWarningCode.INVALID_SETTER_OVERRIDE_NORMAL_PARAM_TYPE, 1393 : StaticWarningCode.INVALID_SETTER_OVERRIDE_NORMAL_PARAM_TYPE,
1378 parameterLocations[parameterIndex], [ 1394 parameterLocations[parameterIndex],
1395 [
1379 overridingNormalPT[i], 1396 overridingNormalPT[i],
1380 overriddenNormalPT[i], 1397 overriddenNormalPT[i],
1381 overriddenExecutable.enclosingElement.displayName 1398 overriddenExecutable.enclosingElement.displayName
1382 ]); 1399 ]);
1383 return true; 1400 return true;
1384 } 1401 }
1385 parameterIndex++; 1402 parameterIndex++;
1386 } 1403 }
1387 // SWC.INVALID_METHOD_OVERRIDE_OPTIONAL_PARAM_TYPE 1404 // SWC.INVALID_METHOD_OVERRIDE_OPTIONAL_PARAM_TYPE
1388 for (int i = 0; i < overriddenPositionalPT.length; i++) { 1405 for (int i = 0; i < overriddenPositionalPT.length; i++) {
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
1548 /** 1565 /**
1549 * Check the given [executableElement] against override-error codes. This 1566 * Check the given [executableElement] against override-error codes. This
1550 * method computes the given executableElement is overriding and calls 1567 * method computes the given executableElement is overriding and calls
1551 * [_checkForAllInvalidOverrideErrorCodes] when the [InheritanceManager] 1568 * [_checkForAllInvalidOverrideErrorCodes] when the [InheritanceManager]
1552 * returns a [MultiplyInheritedExecutableElement], this method loops through 1569 * returns a [MultiplyInheritedExecutableElement], this method loops through
1553 * the list in the [MultiplyInheritedExecutableElement]. The [parameters] are 1570 * the list in the [MultiplyInheritedExecutableElement]. The [parameters] are
1554 * the parameters of the executable element. The [errorNameTarget] is the node 1571 * the parameters of the executable element. The [errorNameTarget] is the node
1555 * to report problems on. 1572 * to report problems on.
1556 */ 1573 */
1557 bool _checkForAllInvalidOverrideErrorCodesForExecutable( 1574 bool _checkForAllInvalidOverrideErrorCodesForExecutable(
1558 ExecutableElement executableElement, List<ParameterElement> parameters, 1575 ExecutableElement executableElement,
1559 List<AstNode> parameterLocations, SimpleIdentifier errorNameTarget) { 1576 List<ParameterElement> parameters,
1577 List<AstNode> parameterLocations,
1578 SimpleIdentifier errorNameTarget) {
1560 // 1579 //
1561 // Compute the overridden executable from the InheritanceManager 1580 // Compute the overridden executable from the InheritanceManager
1562 // 1581 //
1563 List<ExecutableElement> overriddenExecutables = _inheritanceManager 1582 List<ExecutableElement> overriddenExecutables = _inheritanceManager
1564 .lookupOverrides(_enclosingClass, executableElement.name); 1583 .lookupOverrides(_enclosingClass, executableElement.name);
1565 if (_checkForInstanceMethodNameCollidesWithSuperclassStatic( 1584 if (_checkForInstanceMethodNameCollidesWithSuperclassStatic(
1566 executableElement, errorNameTarget)) { 1585 executableElement, errorNameTarget)) {
1567 return true; 1586 return true;
1568 } 1587 }
1569 for (ExecutableElement overriddenElement in overriddenExecutables) { 1588 for (ExecutableElement overriddenElement in overriddenExecutables) {
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
1714 // 1733 //
1715 // Prepare the constructor name 1734 // Prepare the constructor name
1716 // 1735 //
1717 String constructorStrName = constructorTypeName.name.name; 1736 String constructorStrName = constructorTypeName.name.name;
1718 if (redirectedConstructor.name != null) { 1737 if (redirectedConstructor.name != null) {
1719 constructorStrName += ".${redirectedConstructor.name.name}"; 1738 constructorStrName += ".${redirectedConstructor.name.name}";
1720 } 1739 }
1721 ErrorCode errorCode = (declaration.constKeyword != null 1740 ErrorCode errorCode = (declaration.constKeyword != null
1722 ? CompileTimeErrorCode.REDIRECT_TO_MISSING_CONSTRUCTOR 1741 ? CompileTimeErrorCode.REDIRECT_TO_MISSING_CONSTRUCTOR
1723 : StaticWarningCode.REDIRECT_TO_MISSING_CONSTRUCTOR); 1742 : StaticWarningCode.REDIRECT_TO_MISSING_CONSTRUCTOR);
1724 _errorReporter.reportErrorForNode(errorCode, redirectedConstructor, [ 1743 _errorReporter.reportErrorForNode(errorCode, redirectedConstructor,
1725 constructorStrName, 1744 [constructorStrName, redirectedType.displayName]);
1726 redirectedType.displayName
1727 ]);
1728 return true; 1745 return true;
1729 } 1746 }
1730 return false; 1747 return false;
1731 } 1748 }
1732 FunctionType redirectedType = redirectedElement.type; 1749 FunctionType redirectedType = redirectedElement.type;
1733 DartType redirectedReturnType = redirectedType.returnType; 1750 DartType redirectedReturnType = redirectedType.returnType;
1734 // 1751 //
1735 // Report specific problem when return type is incompatible 1752 // Report specific problem when return type is incompatible
1736 // 1753 //
1737 FunctionType constructorType = declaration.element.type; 1754 FunctionType constructorType = declaration.element.type;
1738 DartType constructorReturnType = constructorType.returnType; 1755 DartType constructorReturnType = constructorType.returnType;
1739 if (!redirectedReturnType.isAssignableTo(constructorReturnType)) { 1756 if (!redirectedReturnType.isAssignableTo(constructorReturnType)) {
1740 _errorReporter.reportErrorForNode( 1757 _errorReporter.reportErrorForNode(
1741 StaticWarningCode.REDIRECT_TO_INVALID_RETURN_TYPE, 1758 StaticWarningCode.REDIRECT_TO_INVALID_RETURN_TYPE,
1742 redirectedConstructor, [redirectedReturnType, constructorReturnType]); 1759 redirectedConstructor,
1760 [redirectedReturnType, constructorReturnType]);
1743 return true; 1761 return true;
1744 } 1762 }
1745 // 1763 //
1746 // Check parameters 1764 // Check parameters
1747 // 1765 //
1748 if (!redirectedType.isSubtypeOf(constructorType)) { 1766 if (!redirectedType.isSubtypeOf(constructorType)) {
1749 _errorReporter.reportErrorForNode( 1767 _errorReporter.reportErrorForNode(
1750 StaticWarningCode.REDIRECT_TO_INVALID_FUNCTION_TYPE, 1768 StaticWarningCode.REDIRECT_TO_INVALID_FUNCTION_TYPE,
1751 redirectedConstructor, [redirectedType, constructorType]); 1769 redirectedConstructor,
1770 [redirectedType, constructorType]);
1752 return true; 1771 return true;
1753 } 1772 }
1754 return false; 1773 return false;
1755 } 1774 }
1756 1775
1757 /** 1776 /**
1758 * Check that the return [statement] of the form <i>return e;</i> is not in a 1777 * Check that the return [statement] of the form <i>return e;</i> is not in a
1759 * generative constructor. 1778 * generative constructor.
1760 * 1779 *
1761 * Check that return statements without expressions are not in a generative 1780 * Check that return statements without expressions are not in a generative
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
1823 return false; 1842 return false;
1824 } 1843 }
1825 // check exported names 1844 // check exported names
1826 Namespace namespace = 1845 Namespace namespace =
1827 new NamespaceBuilder().createExportNamespaceForDirective(exportElement); 1846 new NamespaceBuilder().createExportNamespaceForDirective(exportElement);
1828 Map<String, Element> definedNames = namespace.definedNames; 1847 Map<String, Element> definedNames = namespace.definedNames;
1829 for (String name in definedNames.keys) { 1848 for (String name in definedNames.keys) {
1830 Element element = definedNames[name]; 1849 Element element = definedNames[name];
1831 Element prevElement = _exportedElements[name]; 1850 Element prevElement = _exportedElements[name];
1832 if (element != null && prevElement != null && prevElement != element) { 1851 if (element != null && prevElement != null && prevElement != element) {
1833 _errorReporter.reportErrorForNode(CompileTimeErrorCode.AMBIGUOUS_EXPORT, 1852 _errorReporter.reportErrorForNode(
1834 directive, [ 1853 CompileTimeErrorCode.AMBIGUOUS_EXPORT, directive, [
1835 name, 1854 name,
1836 prevElement.library.definingCompilationUnit.displayName, 1855 prevElement.library.definingCompilationUnit.displayName,
1837 element.library.definingCompilationUnit.displayName 1856 element.library.definingCompilationUnit.displayName
1838 ]); 1857 ]);
1839 return true; 1858 return true;
1840 } else { 1859 } else {
1841 _exportedElements[name] = element; 1860 _exportedElements[name] = element;
1842 } 1861 }
1843 } 1862 }
1844 return false; 1863 return false;
1845 } 1864 }
1846 1865
1847 /** 1866 /**
1848 * Verify that the given [expression] can be assigned to its corresponding 1867 * Verify that the given [expression] can be assigned to its corresponding
1849 * parameters. The [expectedStaticType] is the expected static type of the 1868 * parameters. The [expectedStaticType] is the expected static type of the
1850 * parameter. The [actualStaticType] is the actual static type of the 1869 * parameter. The [actualStaticType] is the actual static type of the
1851 * argument. 1870 * argument.
1852 * 1871 *
1853 * This method corresponds to 1872 * This method corresponds to
1854 * [BestPracticesVerifier.checkForArgumentTypeNotAssignable]. 1873 * [BestPracticesVerifier.checkForArgumentTypeNotAssignable].
1855 * 1874 *
1856 * See [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE], 1875 * See [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE],
1857 * [CompileTimeErrorCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE], 1876 * [CompileTimeErrorCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE],
1858 * [StaticWarningCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE], 1877 * [StaticWarningCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE],
1859 * [CompileTimeErrorCode.MAP_KEY_TYPE_NOT_ASSIGNABLE], 1878 * [CompileTimeErrorCode.MAP_KEY_TYPE_NOT_ASSIGNABLE],
1860 * [CompileTimeErrorCode.MAP_VALUE_TYPE_NOT_ASSIGNABLE], 1879 * [CompileTimeErrorCode.MAP_VALUE_TYPE_NOT_ASSIGNABLE],
1861 * [StaticWarningCode.MAP_KEY_TYPE_NOT_ASSIGNABLE], and 1880 * [StaticWarningCode.MAP_KEY_TYPE_NOT_ASSIGNABLE], and
1862 * [StaticWarningCode.MAP_VALUE_TYPE_NOT_ASSIGNABLE]. 1881 * [StaticWarningCode.MAP_VALUE_TYPE_NOT_ASSIGNABLE].
1863 */ 1882 */
1864 bool _checkForArgumentTypeNotAssignable(Expression expression, 1883 bool _checkForArgumentTypeNotAssignable(
1865 DartType expectedStaticType, DartType actualStaticType, 1884 Expression expression,
1885 DartType expectedStaticType,
1886 DartType actualStaticType,
1866 ErrorCode errorCode) { 1887 ErrorCode errorCode) {
1867 // 1888 //
1868 // Warning case: test static type information 1889 // Warning case: test static type information
1869 // 1890 //
1870 if (actualStaticType != null && expectedStaticType != null) { 1891 if (actualStaticType != null && expectedStaticType != null) {
1871 if (!actualStaticType.isAssignableTo(expectedStaticType)) { 1892 if (!actualStaticType.isAssignableTo(expectedStaticType)) {
1872 _errorReporter.reportTypeErrorForNode( 1893 _errorReporter.reportTypeErrorForNode(
1873 errorCode, expression, [actualStaticType, expectedStaticType]); 1894 errorCode, expression, [actualStaticType, expectedStaticType]);
1874 return true; 1895 return true;
1875 } 1896 }
(...skipping 30 matching lines...) Expand all
1906 * 1927 *
1907 * See [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE], 1928 * See [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE],
1908 * [CompileTimeErrorCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE], 1929 * [CompileTimeErrorCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE],
1909 * [StaticWarningCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE], 1930 * [StaticWarningCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE],
1910 * [CompileTimeErrorCode.MAP_KEY_TYPE_NOT_ASSIGNABLE], 1931 * [CompileTimeErrorCode.MAP_KEY_TYPE_NOT_ASSIGNABLE],
1911 * [CompileTimeErrorCode.MAP_VALUE_TYPE_NOT_ASSIGNABLE], 1932 * [CompileTimeErrorCode.MAP_VALUE_TYPE_NOT_ASSIGNABLE],
1912 * [StaticWarningCode.MAP_KEY_TYPE_NOT_ASSIGNABLE], and 1933 * [StaticWarningCode.MAP_KEY_TYPE_NOT_ASSIGNABLE], and
1913 * [StaticWarningCode.MAP_VALUE_TYPE_NOT_ASSIGNABLE]. 1934 * [StaticWarningCode.MAP_VALUE_TYPE_NOT_ASSIGNABLE].
1914 */ 1935 */
1915 bool _checkForArgumentTypeNotAssignableWithExpectedTypes( 1936 bool _checkForArgumentTypeNotAssignableWithExpectedTypes(
1916 Expression expression, DartType expectedStaticType, 1937 Expression expression,
1917 ErrorCode errorCode) => _checkForArgumentTypeNotAssignable( 1938 DartType expectedStaticType,
1939 ErrorCode errorCode) =>
1940 _checkForArgumentTypeNotAssignable(
1918 expression, expectedStaticType, getStaticType(expression), errorCode); 1941 expression, expectedStaticType, getStaticType(expression), errorCode);
1919 1942
1920 /** 1943 /**
1921 * Verify that the arguments in the given [argumentList] can be assigned to 1944 * Verify that the arguments in the given [argumentList] can be assigned to
1922 * their corresponding parameters. 1945 * their corresponding parameters.
1923 * 1946 *
1924 * This method corresponds to 1947 * This method corresponds to
1925 * [BestPracticesVerifier.checkForArgumentTypesNotAssignableInList]. 1948 * [BestPracticesVerifier.checkForArgumentTypesNotAssignableInList].
1926 * 1949 *
1927 * See [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]. 1950 * See [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE].
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
1992 if (element.isConst) { 2015 if (element.isConst) {
1993 _errorReporter.reportErrorForNode( 2016 _errorReporter.reportErrorForNode(
1994 StaticWarningCode.ASSIGNMENT_TO_CONST, expression); 2017 StaticWarningCode.ASSIGNMENT_TO_CONST, expression);
1995 return true; 2018 return true;
1996 } 2019 }
1997 if (element.isFinal) { 2020 if (element.isFinal) {
1998 if (element is FieldElementImpl && 2021 if (element is FieldElementImpl &&
1999 element.setter == null && 2022 element.setter == null &&
2000 element.isSynthetic) { 2023 element.isSynthetic) {
2001 _errorReporter.reportErrorForNode( 2024 _errorReporter.reportErrorForNode(
2002 StaticWarningCode.ASSIGNMENT_TO_FINAL_NO_SETTER, highlightedNode, 2025 StaticWarningCode.ASSIGNMENT_TO_FINAL_NO_SETTER,
2026 highlightedNode,
2003 [element.name, element.enclosingElement.displayName]); 2027 [element.name, element.enclosingElement.displayName]);
2004 return true; 2028 return true;
2005 } 2029 }
2006 _errorReporter.reportErrorForNode(StaticWarningCode.ASSIGNMENT_TO_FINAL, 2030 _errorReporter.reportErrorForNode(StaticWarningCode.ASSIGNMENT_TO_FINAL,
2007 highlightedNode, [element.name]); 2031 highlightedNode, [element.name]);
2008 return true; 2032 return true;
2009 } 2033 }
2010 return false; 2034 return false;
2011 } 2035 }
2012 if (element is FunctionElement) { 2036 if (element is FunctionElement) {
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
2127 memberName, _currentLibrary); 2151 memberName, _currentLibrary);
2128 } else if (method.isSetter) { 2152 } else if (method.isSetter) {
2129 overriddenMember = _enclosingClass.lookUpInheritedConcreteSetter( 2153 overriddenMember = _enclosingClass.lookUpInheritedConcreteSetter(
2130 memberName, _currentLibrary); 2154 memberName, _currentLibrary);
2131 } else { 2155 } else {
2132 overriddenMember = _enclosingClass.lookUpInheritedConcreteMethod( 2156 overriddenMember = _enclosingClass.lookUpInheritedConcreteMethod(
2133 memberName, _currentLibrary); 2157 memberName, _currentLibrary);
2134 } 2158 }
2135 if (overriddenMember == null) { 2159 if (overriddenMember == null) {
2136 _errorReporter.reportErrorForNode( 2160 _errorReporter.reportErrorForNode(
2137 StaticWarningCode.CONCRETE_CLASS_WITH_ABSTRACT_MEMBER, nameNode, [ 2161 StaticWarningCode.CONCRETE_CLASS_WITH_ABSTRACT_MEMBER,
2138 memberName, 2162 nameNode,
2139 _enclosingClass.displayName 2163 [memberName, _enclosingClass.displayName]);
2140 ]);
2141 return true; 2164 return true;
2142 } 2165 }
2143 } 2166 }
2144 return false; 2167 return false;
2145 } 2168 }
2146 2169
2147 /** 2170 /**
2148 * Verify all possible conflicts of the given [constructor]'s name with other 2171 * Verify all possible conflicts of the given [constructor]'s name with other
2149 * constructors and members of the same class. The [constructorElement] is the 2172 * constructors and members of the same class. The [constructorElement] is the
2150 * constructor's element. 2173 * constructor's element.
(...skipping 14 matching lines...) Expand all
2165 for (ConstructorElement otherConstructor in constructors) { 2188 for (ConstructorElement otherConstructor in constructors) {
2166 if (identical(otherConstructor, constructorElement)) { 2189 if (identical(otherConstructor, constructorElement)) {
2167 continue; 2190 continue;
2168 } 2191 }
2169 if (name == otherConstructor.name) { 2192 if (name == otherConstructor.name) {
2170 if (name == null || name.length == 0) { 2193 if (name == null || name.length == 0) {
2171 _errorReporter.reportErrorForNode( 2194 _errorReporter.reportErrorForNode(
2172 CompileTimeErrorCode.DUPLICATE_CONSTRUCTOR_DEFAULT, constructor); 2195 CompileTimeErrorCode.DUPLICATE_CONSTRUCTOR_DEFAULT, constructor);
2173 } else { 2196 } else {
2174 _errorReporter.reportErrorForNode( 2197 _errorReporter.reportErrorForNode(
2175 CompileTimeErrorCode.DUPLICATE_CONSTRUCTOR_NAME, constructor, 2198 CompileTimeErrorCode.DUPLICATE_CONSTRUCTOR_NAME,
2199 constructor,
2176 [name]); 2200 [name]);
2177 } 2201 }
2178 return true; 2202 return true;
2179 } 2203 }
2180 } 2204 }
2181 // conflict with class member 2205 // conflict with class member
2182 if (constructorName != null && 2206 if (constructorName != null &&
2183 constructorElement != null && 2207 constructorElement != null &&
2184 !constructorName.isSynthetic) { 2208 !constructorName.isSynthetic) {
2185 // fields 2209 // fields
2186 FieldElement field = classElement.getField(name); 2210 FieldElement field = classElement.getField(name);
2187 if (field != null) { 2211 if (field != null) {
2188 _errorReporter.reportErrorForNode( 2212 _errorReporter.reportErrorForNode(
2189 CompileTimeErrorCode.CONFLICTING_CONSTRUCTOR_NAME_AND_FIELD, 2213 CompileTimeErrorCode.CONFLICTING_CONSTRUCTOR_NAME_AND_FIELD,
2190 constructor, [name]); 2214 constructor,
2215 [name]);
2191 return true; 2216 return true;
2192 } 2217 }
2193 // methods 2218 // methods
2194 MethodElement method = classElement.getMethod(name); 2219 MethodElement method = classElement.getMethod(name);
2195 if (method != null) { 2220 if (method != null) {
2196 _errorReporter.reportErrorForNode( 2221 _errorReporter.reportErrorForNode(
2197 CompileTimeErrorCode.CONFLICTING_CONSTRUCTOR_NAME_AND_METHOD, 2222 CompileTimeErrorCode.CONFLICTING_CONSTRUCTOR_NAME_AND_METHOD,
2198 constructor, [name]); 2223 constructor,
2224 [name]);
2199 return true; 2225 return true;
2200 } 2226 }
2201 } 2227 }
2202 return false; 2228 return false;
2203 } 2229 }
2204 2230
2205 /** 2231 /**
2206 * Verify that the [_enclosingClass] does not have a method and getter pair 2232 * Verify that the [_enclosingClass] does not have a method and getter pair
2207 * with the same name on, via inheritance. 2233 * with the same name on, via inheritance.
2208 * 2234 *
(...skipping 10 matching lines...) Expand all
2219 String name = method.name; 2245 String name = method.name;
2220 // find inherited property accessor (and can be only getter) 2246 // find inherited property accessor (and can be only getter)
2221 ExecutableElement inherited = 2247 ExecutableElement inherited =
2222 _inheritanceManager.lookupInheritance(_enclosingClass, name); 2248 _inheritanceManager.lookupInheritance(_enclosingClass, name);
2223 if (inherited is! PropertyAccessorElement) { 2249 if (inherited is! PropertyAccessorElement) {
2224 continue; 2250 continue;
2225 } 2251 }
2226 // report problem 2252 // report problem
2227 hasProblem = true; 2253 hasProblem = true;
2228 _errorReporter.reportErrorForOffset( 2254 _errorReporter.reportErrorForOffset(
2229 CompileTimeErrorCode.CONFLICTING_GETTER_AND_METHOD, method.nameOffset, 2255 CompileTimeErrorCode.CONFLICTING_GETTER_AND_METHOD,
2256 method.nameOffset,
2230 name.length, [ 2257 name.length, [
2231 _enclosingClass.displayName, 2258 _enclosingClass.displayName,
2232 inherited.enclosingElement.displayName, 2259 inherited.enclosingElement.displayName,
2233 name 2260 name
2234 ]); 2261 ]);
2235 } 2262 }
2236 // getter declared in the enclosing class vs. inherited method 2263 // getter declared in the enclosing class vs. inherited method
2237 for (PropertyAccessorElement accessor in _enclosingClass.accessors) { 2264 for (PropertyAccessorElement accessor in _enclosingClass.accessors) {
2238 if (!accessor.isGetter) { 2265 if (!accessor.isGetter) {
2239 continue; 2266 continue;
2240 } 2267 }
2241 String name = accessor.name; 2268 String name = accessor.name;
2242 // find inherited method 2269 // find inherited method
2243 ExecutableElement inherited = 2270 ExecutableElement inherited =
2244 _inheritanceManager.lookupInheritance(_enclosingClass, name); 2271 _inheritanceManager.lookupInheritance(_enclosingClass, name);
2245 if (inherited is! MethodElement) { 2272 if (inherited is! MethodElement) {
2246 continue; 2273 continue;
2247 } 2274 }
2248 // report problem 2275 // report problem
2249 hasProblem = true; 2276 hasProblem = true;
2250 _errorReporter.reportErrorForOffset( 2277 _errorReporter.reportErrorForOffset(
2251 CompileTimeErrorCode.CONFLICTING_METHOD_AND_GETTER, 2278 CompileTimeErrorCode.CONFLICTING_METHOD_AND_GETTER,
2252 accessor.nameOffset, name.length, [ 2279 accessor.nameOffset,
2280 name.length, [
2253 _enclosingClass.displayName, 2281 _enclosingClass.displayName,
2254 inherited.enclosingElement.displayName, 2282 inherited.enclosingElement.displayName,
2255 name 2283 name
2256 ]); 2284 ]);
2257 } 2285 }
2258 // done 2286 // done
2259 return hasProblem; 2287 return hasProblem;
2260 } 2288 }
2261 2289
2262 /** 2290 /**
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
2308 } 2336 }
2309 // prepare "super" type to report its name 2337 // prepare "super" type to report its name
2310 ClassElement superElementClass = 2338 ClassElement superElementClass =
2311 superElement.enclosingElement as ClassElement; 2339 superElement.enclosingElement as ClassElement;
2312 InterfaceType superElementType = superElementClass.type; 2340 InterfaceType superElementType = superElementClass.type;
2313 // report problem 2341 // report problem
2314 hasProblem = true; 2342 hasProblem = true;
2315 if (getter) { 2343 if (getter) {
2316 _errorReporter.reportErrorForElement( 2344 _errorReporter.reportErrorForElement(
2317 StaticWarningCode.CONFLICTING_INSTANCE_GETTER_AND_SUPERCLASS_MEMBER, 2345 StaticWarningCode.CONFLICTING_INSTANCE_GETTER_AND_SUPERCLASS_MEMBER,
2318 accessor, [superElementType.displayName]); 2346 accessor,
2347 [superElementType.displayName]);
2319 } else { 2348 } else {
2320 _errorReporter.reportErrorForElement( 2349 _errorReporter.reportErrorForElement(
2321 StaticWarningCode.CONFLICTING_INSTANCE_SETTER_AND_SUPERCLASS_MEMBER, 2350 StaticWarningCode.CONFLICTING_INSTANCE_SETTER_AND_SUPERCLASS_MEMBER,
2322 accessor, [superElementType.displayName]); 2351 accessor,
2352 [superElementType.displayName]);
2323 } 2353 }
2324 } 2354 }
2325 // done 2355 // done
2326 return hasProblem; 2356 return hasProblem;
2327 } 2357 }
2328 2358
2329 /** 2359 /**
2330 * Verify that the enclosing class does not have a setter with the same name 2360 * Verify that the enclosing class does not have a setter with the same name
2331 * as the given instance method declaration. 2361 * as the given instance method declaration.
2332 * 2362 *
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
2394 addThisMemberToTheMap = false; 2424 addThisMemberToTheMap = false;
2395 } 2425 }
2396 } else if (isSetter) { 2426 } else if (isSetter) {
2397 String methodName = name.name; 2427 String methodName = name.name;
2398 ClassMember conflictingMethod = memberHashMap[methodName]; 2428 ClassMember conflictingMethod = memberHashMap[methodName];
2399 if (conflictingMethod != null && 2429 if (conflictingMethod != null &&
2400 conflictingMethod is MethodDeclaration && 2430 conflictingMethod is MethodDeclaration &&
2401 !conflictingMethod.isGetter) { 2431 !conflictingMethod.isGetter) {
2402 // report problem 2432 // report problem
2403 _errorReporter.reportErrorForNode( 2433 _errorReporter.reportErrorForNode(
2404 StaticWarningCode.CONFLICTING_INSTANCE_METHOD_SETTER2, name, [ 2434 StaticWarningCode.CONFLICTING_INSTANCE_METHOD_SETTER2,
2405 _enclosingClass.displayName, 2435 name,
2406 name.name 2436 [_enclosingClass.displayName, name.name]);
2407 ]);
2408 foundError = true; 2437 foundError = true;
2409 addThisMemberToTheMap = false; 2438 addThisMemberToTheMap = false;
2410 } 2439 }
2411 } 2440 }
2412 // Finally, add this member into the HashMap. 2441 // Finally, add this member into the HashMap.
2413 if (addThisMemberToTheMap) { 2442 if (addThisMemberToTheMap) {
2414 if (method.isSetter) { 2443 if (method.isSetter) {
2415 memberHashMap["${name.name}="] = method; 2444 memberHashMap["${name.name}="] = method;
2416 } else { 2445 } else {
2417 memberHashMap[name.name] = method; 2446 memberHashMap[name.name] = method;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
2453 // OK, also static 2482 // OK, also static
2454 if (setter.isStatic) { 2483 if (setter.isStatic) {
2455 return false; 2484 return false;
2456 } 2485 }
2457 // prepare "setter" type to report its name 2486 // prepare "setter" type to report its name
2458 ClassElement setterClass = setter.enclosingElement as ClassElement; 2487 ClassElement setterClass = setter.enclosingElement as ClassElement;
2459 InterfaceType setterType = setterClass.type; 2488 InterfaceType setterType = setterClass.type;
2460 // report problem 2489 // report problem
2461 _errorReporter.reportErrorForNode( 2490 _errorReporter.reportErrorForNode(
2462 StaticWarningCode.CONFLICTING_STATIC_GETTER_AND_INSTANCE_SETTER, 2491 StaticWarningCode.CONFLICTING_STATIC_GETTER_AND_INSTANCE_SETTER,
2463 nameNode, [setterType.displayName]); 2492 nameNode,
2493 [setterType.displayName]);
2464 return true; 2494 return true;
2465 } 2495 }
2466 2496
2467 /** 2497 /**
2468 * Verify that the enclosing class does not have an instance member with the 2498 * Verify that the enclosing class does not have an instance member with the
2469 * same name as the given static [method] declaration. 2499 * same name as the given static [method] declaration.
2470 * 2500 *
2471 * See [StaticWarningCode.CONFLICTING_STATIC_SETTER_AND_INSTANCE_MEMBER]. 2501 * See [StaticWarningCode.CONFLICTING_STATIC_SETTER_AND_INSTANCE_MEMBER].
2472 */ 2502 */
2473 bool _checkForConflictingStaticSetterAndInstanceMember( 2503 bool _checkForConflictingStaticSetterAndInstanceMember(
(...skipping 27 matching lines...) Expand all
2501 // OK, also static 2531 // OK, also static
2502 if (member.isStatic) { 2532 if (member.isStatic) {
2503 return false; 2533 return false;
2504 } 2534 }
2505 // prepare "member" type to report its name 2535 // prepare "member" type to report its name
2506 ClassElement memberClass = member.enclosingElement as ClassElement; 2536 ClassElement memberClass = member.enclosingElement as ClassElement;
2507 InterfaceType memberType = memberClass.type; 2537 InterfaceType memberType = memberClass.type;
2508 // report problem 2538 // report problem
2509 _errorReporter.reportErrorForNode( 2539 _errorReporter.reportErrorForNode(
2510 StaticWarningCode.CONFLICTING_STATIC_SETTER_AND_INSTANCE_MEMBER, 2540 StaticWarningCode.CONFLICTING_STATIC_SETTER_AND_INSTANCE_MEMBER,
2511 nameNode, [memberType.displayName]); 2541 nameNode,
2542 [memberType.displayName]);
2512 return true; 2543 return true;
2513 } 2544 }
2514 2545
2515 /** 2546 /**
2516 * Verify all conflicts between type variable and enclosing class. 2547 * Verify all conflicts between type variable and enclosing class.
2517 * TODO(scheglov) 2548 * TODO(scheglov)
2518 * 2549 *
2519 * See [CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_CLASS], and 2550 * See [CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_CLASS], and
2520 * [CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_MEMBER]. 2551 * [CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_MEMBER].
2521 */ 2552 */
2522 bool _checkForConflictingTypeVariableErrorCodes( 2553 bool _checkForConflictingTypeVariableErrorCodes(
2523 ClassDeclaration declaration) { 2554 ClassDeclaration declaration) {
2524 bool problemReported = false; 2555 bool problemReported = false;
2525 for (TypeParameterElement typeParameter in _enclosingClass.typeParameters) { 2556 for (TypeParameterElement typeParameter in _enclosingClass.typeParameters) {
2526 String name = typeParameter.name; 2557 String name = typeParameter.name;
2527 // name is same as the name of the enclosing class 2558 // name is same as the name of the enclosing class
2528 if (_enclosingClass.name == name) { 2559 if (_enclosingClass.name == name) {
2529 _errorReporter.reportErrorForOffset( 2560 _errorReporter.reportErrorForOffset(
2530 CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_CLASS, 2561 CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_CLASS,
2531 typeParameter.nameOffset, name.length, [name]); 2562 typeParameter.nameOffset,
2563 name.length,
2564 [name]);
2532 problemReported = true; 2565 problemReported = true;
2533 } 2566 }
2534 // check members 2567 // check members
2535 if (_enclosingClass.getMethod(name) != null || 2568 if (_enclosingClass.getMethod(name) != null ||
2536 _enclosingClass.getGetter(name) != null || 2569 _enclosingClass.getGetter(name) != null ||
2537 _enclosingClass.getSetter(name) != null) { 2570 _enclosingClass.getSetter(name) != null) {
2538 _errorReporter.reportErrorForOffset( 2571 _errorReporter.reportErrorForOffset(
2539 CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_MEMBER, 2572 CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_MEMBER,
2540 typeParameter.nameOffset, name.length, [name]); 2573 typeParameter.nameOffset,
2574 name.length,
2575 [name]);
2541 problemReported = true; 2576 problemReported = true;
2542 } 2577 }
2543 } 2578 }
2544 return problemReported; 2579 return problemReported;
2545 } 2580 }
2546 2581
2547 /** 2582 /**
2548 * Verify that if the given [constructor] declaration is 'const' then there 2583 * Verify that if the given [constructor] declaration is 'const' then there
2549 * are no invocations of non-'const' super constructors. 2584 * are no invocations of non-'const' super constructors.
2550 * 2585 *
(...skipping 18 matching lines...) Expand all
2569 // try to find and check super constructor invocation 2604 // try to find and check super constructor invocation
2570 for (ConstructorInitializer initializer in constructor.initializers) { 2605 for (ConstructorInitializer initializer in constructor.initializers) {
2571 if (initializer is SuperConstructorInvocation) { 2606 if (initializer is SuperConstructorInvocation) {
2572 SuperConstructorInvocation superInvocation = initializer; 2607 SuperConstructorInvocation superInvocation = initializer;
2573 ConstructorElement element = superInvocation.staticElement; 2608 ConstructorElement element = superInvocation.staticElement;
2574 if (element == null || element.isConst) { 2609 if (element == null || element.isConst) {
2575 return false; 2610 return false;
2576 } 2611 }
2577 _errorReporter.reportErrorForNode( 2612 _errorReporter.reportErrorForNode(
2578 CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_NON_CONST_SUPER, 2613 CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_NON_CONST_SUPER,
2579 superInvocation, [element.enclosingElement.displayName]); 2614 superInvocation,
2615 [element.enclosingElement.displayName]);
2580 return true; 2616 return true;
2581 } 2617 }
2582 } 2618 }
2583 // no explicit super constructor invocation, check default constructor 2619 // no explicit super constructor invocation, check default constructor
2584 InterfaceType supertype = _enclosingClass.supertype; 2620 InterfaceType supertype = _enclosingClass.supertype;
2585 if (supertype == null) { 2621 if (supertype == null) {
2586 return false; 2622 return false;
2587 } 2623 }
2588 if (supertype.isObject) { 2624 if (supertype.isObject) {
2589 return false; 2625 return false;
2590 } 2626 }
2591 ConstructorElement unnamedConstructor = 2627 ConstructorElement unnamedConstructor =
2592 supertype.element.unnamedConstructor; 2628 supertype.element.unnamedConstructor;
2593 if (unnamedConstructor == null) { 2629 if (unnamedConstructor == null) {
2594 return false; 2630 return false;
2595 } 2631 }
2596 if (unnamedConstructor.isConst) { 2632 if (unnamedConstructor.isConst) {
2597 return false; 2633 return false;
2598 } 2634 }
2599 // default constructor is not 'const', report problem 2635 // default constructor is not 'const', report problem
2600 _errorReporter.reportErrorForNode( 2636 _errorReporter.reportErrorForNode(
2601 CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_NON_CONST_SUPER, 2637 CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_NON_CONST_SUPER,
2602 constructor.returnType, [supertype.displayName]); 2638 constructor.returnType,
2639 [supertype.displayName]);
2603 return true; 2640 return true;
2604 } 2641 }
2605 2642
2606 /** 2643 /**
2607 * Verify that if the given [constructor] declaration is 'const' then there 2644 * Verify that if the given [constructor] declaration is 'const' then there
2608 * are no non-final instance variable. The [constructorElement] is the 2645 * are no non-final instance variable. The [constructorElement] is the
2609 * constructor element. 2646 * constructor element.
2610 * 2647 *
2611 * See [CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_NON_FINAL_FIELD]. 2648 * See [CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_NON_FINAL_FIELD].
2612 */ 2649 */
(...skipping 20 matching lines...) Expand all
2633 * creating a deferred type. The [constructorName] is the constructor name, 2670 * creating a deferred type. The [constructorName] is the constructor name,
2634 * always non-`null`. The [typeName] is the name of the type defining the 2671 * always non-`null`. The [typeName] is the name of the type defining the
2635 * constructor, always non-`null`. 2672 * constructor, always non-`null`.
2636 * 2673 *
2637 * See [CompileTimeErrorCode.CONST_DEFERRED_CLASS]. 2674 * See [CompileTimeErrorCode.CONST_DEFERRED_CLASS].
2638 */ 2675 */
2639 bool _checkForConstDeferredClass(InstanceCreationExpression expression, 2676 bool _checkForConstDeferredClass(InstanceCreationExpression expression,
2640 ConstructorName constructorName, TypeName typeName) { 2677 ConstructorName constructorName, TypeName typeName) {
2641 if (typeName.isDeferred) { 2678 if (typeName.isDeferred) {
2642 _errorReporter.reportErrorForNode( 2679 _errorReporter.reportErrorForNode(
2643 CompileTimeErrorCode.CONST_DEFERRED_CLASS, constructorName, 2680 CompileTimeErrorCode.CONST_DEFERRED_CLASS,
2681 constructorName,
2644 [typeName.name.name]); 2682 [typeName.name.name]);
2645 return true; 2683 return true;
2646 } 2684 }
2647 return false; 2685 return false;
2648 } 2686 }
2649 2687
2650 /** 2688 /**
2651 * Verify that the given throw [expression] is not enclosed in a 'const' 2689 * Verify that the given throw [expression] is not enclosed in a 'const'
2652 * constructor declaration. 2690 * constructor declaration.
2653 * 2691 *
(...skipping 26 matching lines...) Expand all
2680 * Verify that the given instance creation [expression] is not being invoked 2718 * Verify that the given instance creation [expression] is not being invoked
2681 * on an abstract class. The [typeName] is the [TypeName] of the 2719 * on an abstract class. The [typeName] is the [TypeName] of the
2682 * [ConstructorName] from the [InstanceCreationExpression], this is the AST 2720 * [ConstructorName] from the [InstanceCreationExpression], this is the AST
2683 * node that the error is attached to. The [type] is the type being 2721 * node that the error is attached to. The [type] is the type being
2684 * constructed with this [InstanceCreationExpression]. 2722 * constructed with this [InstanceCreationExpression].
2685 * 2723 *
2686 * See [StaticWarningCode.CONST_WITH_ABSTRACT_CLASS], and 2724 * See [StaticWarningCode.CONST_WITH_ABSTRACT_CLASS], and
2687 * [StaticWarningCode.NEW_WITH_ABSTRACT_CLASS]. 2725 * [StaticWarningCode.NEW_WITH_ABSTRACT_CLASS].
2688 */ 2726 */
2689 bool _checkForConstOrNewWithAbstractClass( 2727 bool _checkForConstOrNewWithAbstractClass(
2690 InstanceCreationExpression expression, TypeName typeName, 2728 InstanceCreationExpression expression,
2729 TypeName typeName,
2691 InterfaceType type) { 2730 InterfaceType type) {
2692 if (type.element.isAbstract) { 2731 if (type.element.isAbstract) {
2693 ConstructorElement element = expression.staticElement; 2732 ConstructorElement element = expression.staticElement;
2694 if (element != null && !element.isFactory) { 2733 if (element != null && !element.isFactory) {
2695 if ((expression.keyword as sc.KeywordToken).keyword == 2734 if ((expression.keyword as sc.KeywordToken).keyword ==
2696 sc.Keyword.CONST) { 2735 sc.Keyword.CONST) {
2697 _errorReporter.reportErrorForNode( 2736 _errorReporter.reportErrorForNode(
2698 StaticWarningCode.CONST_WITH_ABSTRACT_CLASS, typeName); 2737 StaticWarningCode.CONST_WITH_ABSTRACT_CLASS, typeName);
2699 } else { 2738 } else {
2700 _errorReporter.reportErrorForNode( 2739 _errorReporter.reportErrorForNode(
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
2784 * constructor name, always non-`null`. The [typeName] is the name of the type 2823 * constructor name, always non-`null`. The [typeName] is the name of the type
2785 * defining the constructor, always non-`null`. 2824 * defining the constructor, always non-`null`.
2786 * 2825 *
2787 * This method assumes that the instance creation was tested to be 'const' 2826 * This method assumes that the instance creation was tested to be 'const'
2788 * before being called. 2827 * before being called.
2789 * 2828 *
2790 * See [CompileTimeErrorCode.CONST_WITH_UNDEFINED_CONSTRUCTOR], and 2829 * See [CompileTimeErrorCode.CONST_WITH_UNDEFINED_CONSTRUCTOR], and
2791 * [CompileTimeErrorCode.CONST_WITH_UNDEFINED_CONSTRUCTOR_DEFAULT]. 2830 * [CompileTimeErrorCode.CONST_WITH_UNDEFINED_CONSTRUCTOR_DEFAULT].
2792 */ 2831 */
2793 bool _checkForConstWithUndefinedConstructor( 2832 bool _checkForConstWithUndefinedConstructor(
2794 InstanceCreationExpression expression, ConstructorName constructorName, 2833 InstanceCreationExpression expression,
2834 ConstructorName constructorName,
2795 TypeName typeName) { 2835 TypeName typeName) {
2796 // OK if resolved 2836 // OK if resolved
2797 if (expression.staticElement != null) { 2837 if (expression.staticElement != null) {
2798 return false; 2838 return false;
2799 } 2839 }
2800 DartType type = typeName.type; 2840 DartType type = typeName.type;
2801 if (type is InterfaceType) { 2841 if (type is InterfaceType) {
2802 ClassElement element = type.element; 2842 ClassElement element = type.element;
2803 if (element != null && element.isEnum) { 2843 if (element != null && element.isEnum) {
2804 // We have already reported the error. 2844 // We have already reported the error.
2805 return false; 2845 return false;
2806 } 2846 }
2807 } 2847 }
2808 Identifier className = typeName.name; 2848 Identifier className = typeName.name;
2809 // report as named or default constructor absence 2849 // report as named or default constructor absence
2810 SimpleIdentifier name = constructorName.name; 2850 SimpleIdentifier name = constructorName.name;
2811 if (name != null) { 2851 if (name != null) {
2812 _errorReporter.reportErrorForNode( 2852 _errorReporter.reportErrorForNode(
2813 CompileTimeErrorCode.CONST_WITH_UNDEFINED_CONSTRUCTOR, name, [ 2853 CompileTimeErrorCode.CONST_WITH_UNDEFINED_CONSTRUCTOR,
2814 className, 2854 name,
2815 name 2855 [className, name]);
2816 ]);
2817 } else { 2856 } else {
2818 _errorReporter.reportErrorForNode( 2857 _errorReporter.reportErrorForNode(
2819 CompileTimeErrorCode.CONST_WITH_UNDEFINED_CONSTRUCTOR_DEFAULT, 2858 CompileTimeErrorCode.CONST_WITH_UNDEFINED_CONSTRUCTOR_DEFAULT,
2820 constructorName, [className]); 2859 constructorName,
2860 [className]);
2821 } 2861 }
2822 return true; 2862 return true;
2823 } 2863 }
2824 2864
2825 /** 2865 /**
2826 * Verify that there are no default parameters in the given function type 2866 * Verify that there are no default parameters in the given function type
2827 * [alias]. 2867 * [alias].
2828 * 2868 *
2829 * See [CompileTimeErrorCode.DEFAULT_VALUE_IN_FUNCTION_TYPE_ALIAS]. 2869 * See [CompileTimeErrorCode.DEFAULT_VALUE_IN_FUNCTION_TYPE_ALIAS].
2830 */ 2870 */
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
2961 String displayName; 3001 String displayName;
2962 Element enclosingElement = inheritedMember.enclosingElement; 3002 Element enclosingElement = inheritedMember.enclosingElement;
2963 if (enclosingElement.source == _enclosingClass.source) { 3003 if (enclosingElement.source == _enclosingClass.source) {
2964 displayName = enclosingElement.displayName; 3004 displayName = enclosingElement.displayName;
2965 } else { 3005 } else {
2966 displayName = enclosingElement.getExtendedDisplayName(null); 3006 displayName = enclosingElement.getExtendedDisplayName(null);
2967 } 3007 }
2968 // report problem 3008 // report problem
2969 _errorReporter.reportErrorForOffset( 3009 _errorReporter.reportErrorForOffset(
2970 CompileTimeErrorCode.DUPLICATE_DEFINITION_INHERITANCE, 3010 CompileTimeErrorCode.DUPLICATE_DEFINITION_INHERITANCE,
2971 staticMember.nameOffset, name.length, [name, displayName]); 3011 staticMember.nameOffset,
3012 name.length,
3013 [name, displayName]);
2972 return true; 3014 return true;
2973 } 3015 }
2974 3016
2975 /** 3017 /**
2976 * Verify that if the given list [literal] has type arguments then there is 3018 * Verify that if the given list [literal] has type arguments then there is
2977 * exactly one. The [typeArguments] are the type arguments. 3019 * exactly one. The [typeArguments] are the type arguments.
2978 * 3020 *
2979 * See [StaticTypeWarningCode.EXPECTED_ONE_LIST_TYPE_ARGUMENTS]. 3021 * See [StaticTypeWarningCode.EXPECTED_ONE_LIST_TYPE_ARGUMENTS].
2980 */ 3022 */
2981 bool _checkForExpectedOneListTypeArgument( 3023 bool _checkForExpectedOneListTypeArgument(
2982 ListLiteral literal, TypeArgumentList typeArguments) { 3024 ListLiteral literal, TypeArgumentList typeArguments) {
2983 // check number of type arguments 3025 // check number of type arguments
2984 int num = typeArguments.arguments.length; 3026 int num = typeArguments.arguments.length;
2985 if (num == 1) { 3027 if (num == 1) {
2986 return false; 3028 return false;
2987 } 3029 }
2988 // report problem 3030 // report problem
2989 _errorReporter.reportErrorForNode( 3031 _errorReporter.reportErrorForNode(
2990 StaticTypeWarningCode.EXPECTED_ONE_LIST_TYPE_ARGUMENTS, typeArguments, 3032 StaticTypeWarningCode.EXPECTED_ONE_LIST_TYPE_ARGUMENTS,
3033 typeArguments,
2991 [num]); 3034 [num]);
2992 return true; 3035 return true;
2993 } 3036 }
2994 3037
2995 /** 3038 /**
2996 * Verify that the given export [directive] has a unique name among other 3039 * Verify that the given export [directive] has a unique name among other
2997 * exported libraries. The [exportElement] is the [ExportElement] retrieved 3040 * exported libraries. The [exportElement] is the [ExportElement] retrieved
2998 * from the node, if the element in the node was `null`, then this method is 3041 * 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 3042 * not called. The [exportedLibrary] is the library element containing the
3000 * exported element. 3043 * exported element.
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
3046 String uri = exportElement.uri; 3089 String uri = exportElement.uri;
3047 SdkLibrary sdkLibrary = sdk.getSdkLibrary(uri); 3090 SdkLibrary sdkLibrary = sdk.getSdkLibrary(uri);
3048 if (sdkLibrary == null) { 3091 if (sdkLibrary == null) {
3049 return false; 3092 return false;
3050 } 3093 }
3051 if (!sdkLibrary.isInternal) { 3094 if (!sdkLibrary.isInternal) {
3052 return false; 3095 return false;
3053 } 3096 }
3054 // report problem 3097 // report problem
3055 _errorReporter.reportErrorForNode( 3098 _errorReporter.reportErrorForNode(
3056 CompileTimeErrorCode.EXPORT_INTERNAL_LIBRARY, directive, 3099 CompileTimeErrorCode.EXPORT_INTERNAL_LIBRARY,
3100 directive,
3057 [directive.uri]); 3101 [directive.uri]);
3058 return true; 3102 return true;
3059 } 3103 }
3060 3104
3061 /** 3105 /**
3062 * Verify that the given extends [clause] does not extend a deferred class. 3106 * Verify that the given extends [clause] does not extend a deferred class.
3063 * 3107 *
3064 * See [CompileTimeErrorCode.EXTENDS_DEFERRED_CLASS]. 3108 * See [CompileTimeErrorCode.EXTENDS_DEFERRED_CLASS].
3065 */ 3109 */
3066 bool _checkForExtendsDeferredClass(ExtendsClause clause) { 3110 bool _checkForExtendsDeferredClass(ExtendsClause clause) {
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
3215 } 3259 }
3216 if (staticType.isAssignableTo(fieldType)) { 3260 if (staticType.isAssignableTo(fieldType)) {
3217 return false; 3261 return false;
3218 } 3262 }
3219 // report problem 3263 // report problem
3220 if (_isEnclosingConstructorConst) { 3264 if (_isEnclosingConstructorConst) {
3221 // TODO(paulberry): this error should be based on the actual type of the 3265 // TODO(paulberry): this error should be based on the actual type of the
3222 // constant, not the static type. See dartbug.com/21119. 3266 // constant, not the static type. See dartbug.com/21119.
3223 _errorReporter.reportTypeErrorForNode( 3267 _errorReporter.reportTypeErrorForNode(
3224 CheckedModeCompileTimeErrorCode.CONST_FIELD_INITIALIZER_NOT_ASSIGNABLE , 3268 CheckedModeCompileTimeErrorCode.CONST_FIELD_INITIALIZER_NOT_ASSIGNABLE ,
3225 expression, [staticType, fieldType]); 3269 expression,
3270 [staticType, fieldType]);
3226 } 3271 }
3227 _errorReporter.reportTypeErrorForNode( 3272 _errorReporter.reportTypeErrorForNode(
3228 StaticWarningCode.FIELD_INITIALIZER_NOT_ASSIGNABLE, expression, [ 3273 StaticWarningCode.FIELD_INITIALIZER_NOT_ASSIGNABLE,
3229 staticType, 3274 expression,
3230 fieldType 3275 [staticType, fieldType]);
3231 ]);
3232 return true; 3276 return true;
3233 // TODO(brianwilkerson) Define a hint corresponding to these errors and 3277 // TODO(brianwilkerson) Define a hint corresponding to these errors and
3234 // report it if appropriate. 3278 // report it if appropriate.
3235 // // test the propagated type of the expression 3279 // // test the propagated type of the expression
3236 // Type propagatedType = expression.getPropagatedType(); 3280 // Type propagatedType = expression.getPropagatedType();
3237 // if (propagatedType != null && propagatedType.isAssignableTo(fieldType) ) { 3281 // if (propagatedType != null && propagatedType.isAssignableTo(fieldType) ) {
3238 // return false; 3282 // return false;
3239 // } 3283 // }
3240 // // report problem 3284 // // report problem
3241 // if (isEnclosingConstructorConst) { 3285 // if (isEnclosingConstructorConst) {
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
3301 if (_isInNativeClass) { 3345 if (_isInNativeClass) {
3302 return false; 3346 return false;
3303 } 3347 }
3304 bool foundError = false; 3348 bool foundError = false;
3305 if (!list.isSynthetic) { 3349 if (!list.isSynthetic) {
3306 NodeList<VariableDeclaration> variables = list.variables; 3350 NodeList<VariableDeclaration> variables = list.variables;
3307 for (VariableDeclaration variable in variables) { 3351 for (VariableDeclaration variable in variables) {
3308 if (variable.initializer == null) { 3352 if (variable.initializer == null) {
3309 if (list.isConst) { 3353 if (list.isConst) {
3310 _errorReporter.reportErrorForNode( 3354 _errorReporter.reportErrorForNode(
3311 CompileTimeErrorCode.CONST_NOT_INITIALIZED, variable.name, 3355 CompileTimeErrorCode.CONST_NOT_INITIALIZED,
3356 variable.name,
3312 [variable.name.name]); 3357 [variable.name.name]);
3313 } else if (list.isFinal) { 3358 } else if (list.isFinal) {
3314 _errorReporter.reportErrorForNode( 3359 _errorReporter.reportErrorForNode(
3315 StaticWarningCode.FINAL_NOT_INITIALIZED, variable.name, 3360 StaticWarningCode.FINAL_NOT_INITIALIZED,
3361 variable.name,
3316 [variable.name.name]); 3362 [variable.name.name]);
3317 } 3363 }
3318 foundError = true; 3364 foundError = true;
3319 } 3365 }
3320 } 3366 }
3321 } 3367 }
3322 return foundError; 3368 return foundError;
3323 } 3369 }
3324 3370
3325 /** 3371 /**
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
3553 String uri = importElement.uri; 3599 String uri = importElement.uri;
3554 SdkLibrary sdkLibrary = sdk.getSdkLibrary(uri); 3600 SdkLibrary sdkLibrary = sdk.getSdkLibrary(uri);
3555 if (sdkLibrary == null) { 3601 if (sdkLibrary == null) {
3556 return false; 3602 return false;
3557 } 3603 }
3558 if (!sdkLibrary.isInternal) { 3604 if (!sdkLibrary.isInternal) {
3559 return false; 3605 return false;
3560 } 3606 }
3561 // report problem 3607 // report problem
3562 _errorReporter.reportErrorForNode( 3608 _errorReporter.reportErrorForNode(
3563 CompileTimeErrorCode.IMPORT_INTERNAL_LIBRARY, directive, 3609 CompileTimeErrorCode.IMPORT_INTERNAL_LIBRARY,
3610 directive,
3564 [directive.uri]); 3611 [directive.uri]);
3565 return true; 3612 return true;
3566 } 3613 }
3567 3614
3568 /** 3615 /**
3569 * For each class declaration, this method is called which verifies that all 3616 * For each class declaration, this method is called which verifies that all
3570 * inherited members are inherited consistently. 3617 * inherited members are inherited consistently.
3571 * 3618 *
3572 * See [StaticTypeWarningCode.INCONSISTENT_METHOD_INHERITANCE]. 3619 * See [StaticTypeWarningCode.INCONSISTENT_METHOD_INHERITANCE].
3573 */ 3620 */
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
3612 // OK, top-level element 3659 // OK, top-level element
3613 if (executableElement.enclosingElement is! ClassElement) { 3660 if (executableElement.enclosingElement is! ClassElement) {
3614 return false; 3661 return false;
3615 } 3662 }
3616 // OK, instance member 3663 // OK, instance member
3617 if (!executableElement.isStatic) { 3664 if (!executableElement.isStatic) {
3618 return false; 3665 return false;
3619 } 3666 }
3620 // report problem 3667 // report problem
3621 _errorReporter.reportErrorForNode( 3668 _errorReporter.reportErrorForNode(
3622 StaticTypeWarningCode.INSTANCE_ACCESS_TO_STATIC_MEMBER, name, 3669 StaticTypeWarningCode.INSTANCE_ACCESS_TO_STATIC_MEMBER,
3670 name,
3623 [name.name]); 3671 [name.name]);
3624 return true; 3672 return true;
3625 } 3673 }
3626 3674
3627 /** 3675 /**
3628 * Check whether the given [executableElement] collides with the name of a 3676 * Check whether the given [executableElement] collides with the name of a
3629 * static method in one of its superclasses, and reports the appropriate 3677 * static method in one of its superclasses, and reports the appropriate
3630 * warning if it does. The [errorNameTarget] is the node to report problems 3678 * warning if it does. The [errorNameTarget] is the node to report problems
3631 * on. 3679 * on.
3632 * 3680 *
(...skipping 20 matching lines...) Expand all
3653 if (fieldElt != null) { 3701 if (fieldElt != null) {
3654 // Ignore if private in a different library - cannot collide. 3702 // Ignore if private in a different library - cannot collide.
3655 if (executableElementPrivate && 3703 if (executableElementPrivate &&
3656 _currentLibrary != superclassLibrary) { 3704 _currentLibrary != superclassLibrary) {
3657 continue; 3705 continue;
3658 } 3706 }
3659 // instance vs. static 3707 // instance vs. static
3660 if (fieldElt.isStatic) { 3708 if (fieldElt.isStatic) {
3661 _errorReporter.reportErrorForNode( 3709 _errorReporter.reportErrorForNode(
3662 StaticWarningCode.INSTANCE_METHOD_NAME_COLLIDES_WITH_SUPERCLASS_ STATIC, 3710 StaticWarningCode.INSTANCE_METHOD_NAME_COLLIDES_WITH_SUPERCLASS_ STATIC,
3663 errorNameTarget, [ 3711 errorNameTarget,
3664 executableElementName, 3712 [executableElementName, fieldElt.enclosingElement.displayName]);
3665 fieldElt.enclosingElement.displayName
3666 ]);
3667 return true; 3713 return true;
3668 } 3714 }
3669 } 3715 }
3670 // Check methods. 3716 // Check methods.
3671 List<MethodElement> methodElements = superclassElement.methods; 3717 List<MethodElement> methodElements = superclassElement.methods;
3672 for (MethodElement methodElement in methodElements) { 3718 for (MethodElement methodElement in methodElements) {
3673 // We need the same name. 3719 // We need the same name.
3674 if (methodElement.name != executableElementName) { 3720 if (methodElement.name != executableElementName) {
3675 continue; 3721 continue;
3676 } 3722 }
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
3744 if (lhs == null || rhs == null) { 3790 if (lhs == null || rhs == null) {
3745 return false; 3791 return false;
3746 } 3792 }
3747 VariableElement leftVariableElement = getVariableElement(lhs); 3793 VariableElement leftVariableElement = getVariableElement(lhs);
3748 DartType leftType = (leftVariableElement == null) 3794 DartType leftType = (leftVariableElement == null)
3749 ? getStaticType(lhs) 3795 ? getStaticType(lhs)
3750 : leftVariableElement.type; 3796 : leftVariableElement.type;
3751 DartType staticRightType = getStaticType(rhs); 3797 DartType staticRightType = getStaticType(rhs);
3752 if (!staticRightType.isAssignableTo(leftType)) { 3798 if (!staticRightType.isAssignableTo(leftType)) {
3753 _errorReporter.reportTypeErrorForNode( 3799 _errorReporter.reportTypeErrorForNode(
3754 StaticTypeWarningCode.INVALID_ASSIGNMENT, rhs, [ 3800 StaticTypeWarningCode.INVALID_ASSIGNMENT,
3755 staticRightType, 3801 rhs,
3756 leftType 3802 [staticRightType, leftType]);
3757 ]);
3758 return true; 3803 return true;
3759 } 3804 }
3760 return false; 3805 return false;
3761 } 3806 }
3762 3807
3763 /** 3808 /**
3764 * Given an [assignment] using a compound assignment operator, this verifies 3809 * Given an [assignment] using a compound assignment operator, this verifies
3765 * that the given assignment is valid. The [lhs] is the left hand side 3810 * that the given assignment is valid. The [lhs] is the left hand side
3766 * expression. The [rhs] is the right hand side expression. 3811 * expression. The [rhs] is the right hand side expression.
3767 * 3812 *
(...skipping 30 matching lines...) Expand all
3798 * [ConstructorFieldInitializer]. The [staticElement] is the static element 3843 * [ConstructorFieldInitializer]. The [staticElement] is the static element
3799 * from the name in the [ConstructorFieldInitializer]. 3844 * from the name in the [ConstructorFieldInitializer].
3800 */ 3845 */
3801 void _checkForInvalidField(ConstructorFieldInitializer initializer, 3846 void _checkForInvalidField(ConstructorFieldInitializer initializer,
3802 SimpleIdentifier fieldName, Element staticElement) { 3847 SimpleIdentifier fieldName, Element staticElement) {
3803 if (staticElement is FieldElement) { 3848 if (staticElement is FieldElement) {
3804 FieldElement fieldElement = staticElement; 3849 FieldElement fieldElement = staticElement;
3805 if (fieldElement.isSynthetic) { 3850 if (fieldElement.isSynthetic) {
3806 _errorReporter.reportErrorForNode( 3851 _errorReporter.reportErrorForNode(
3807 CompileTimeErrorCode.INITIALIZER_FOR_NON_EXISTENT_FIELD, 3852 CompileTimeErrorCode.INITIALIZER_FOR_NON_EXISTENT_FIELD,
3808 initializer, [fieldName]); 3853 initializer,
3854 [fieldName]);
3809 } else if (fieldElement.isStatic) { 3855 } else if (fieldElement.isStatic) {
3810 _errorReporter.reportErrorForNode( 3856 _errorReporter.reportErrorForNode(
3811 CompileTimeErrorCode.INITIALIZER_FOR_STATIC_FIELD, initializer, 3857 CompileTimeErrorCode.INITIALIZER_FOR_STATIC_FIELD,
3858 initializer,
3812 [fieldName]); 3859 [fieldName]);
3813 } 3860 }
3814 } else { 3861 } else {
3815 _errorReporter.reportErrorForNode( 3862 _errorReporter.reportErrorForNode(
3816 CompileTimeErrorCode.INITIALIZER_FOR_NON_EXISTENT_FIELD, initializer, 3863 CompileTimeErrorCode.INITIALIZER_FOR_NON_EXISTENT_FIELD,
3864 initializer,
3817 [fieldName]); 3865 [fieldName]);
3818 return; 3866 return;
3819 } 3867 }
3820 } 3868 }
3821 3869
3822 /** 3870 /**
3823 * Check to see whether the given function [body] has a modifier associated 3871 * Check to see whether the given function [body] has a modifier associated
3824 * with it, and report it as an error if it does. 3872 * with it, and report it as an error if it does.
3825 */ 3873 */
3826 bool _checkForInvalidModifierOnBody( 3874 bool _checkForInvalidModifierOnBody(
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
3878 if (typeNames.length < 1) { 3926 if (typeNames.length < 1) {
3879 return false; 3927 return false;
3880 } 3928 }
3881 DartType listElementType = typeNames[0].type; 3929 DartType listElementType = typeNames[0].type;
3882 // Check every list element. 3930 // Check every list element.
3883 bool hasProblems = false; 3931 bool hasProblems = false;
3884 for (Expression element in literal.elements) { 3932 for (Expression element in literal.elements) {
3885 if (literal.constKeyword != null) { 3933 if (literal.constKeyword != null) {
3886 // TODO(paulberry): this error should be based on the actual type of the 3934 // TODO(paulberry): this error should be based on the actual type of the
3887 // list element, not the static type. See dartbug.com/21119. 3935 // list element, not the static type. See dartbug.com/21119.
3888 if (_checkForArgumentTypeNotAssignableWithExpectedTypes(element, 3936 if (_checkForArgumentTypeNotAssignableWithExpectedTypes(
3937 element,
3889 listElementType, 3938 listElementType,
3890 CheckedModeCompileTimeErrorCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE)) { 3939 CheckedModeCompileTimeErrorCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE)) {
3891 hasProblems = true; 3940 hasProblems = true;
3892 } 3941 }
3893 } 3942 }
3894 if (_checkForArgumentTypeNotAssignableWithExpectedTypes(element, 3943 if (_checkForArgumentTypeNotAssignableWithExpectedTypes(
3944 element,
3895 listElementType, 3945 listElementType,
3896 StaticWarningCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE)) { 3946 StaticWarningCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE)) {
3897 hasProblems = true; 3947 hasProblems = true;
3898 } 3948 }
3899 } 3949 }
3900 return hasProblems; 3950 return hasProblems;
3901 } 3951 }
3902 3952
3903 /** 3953 /**
3904 * Verify that the key/value of entries of the given map [literal] are 3954 * Verify that the key/value of entries of the given map [literal] are
(...skipping 20 matching lines...) Expand all
3925 for (MapLiteralEntry entry in entries) { 3975 for (MapLiteralEntry entry in entries) {
3926 Expression key = entry.key; 3976 Expression key = entry.key;
3927 Expression value = entry.value; 3977 Expression value = entry.value;
3928 if (literal.constKeyword != null) { 3978 if (literal.constKeyword != null) {
3929 // TODO(paulberry): this error should be based on the actual type of the 3979 // TODO(paulberry): this error should be based on the actual type of the
3930 // list element, not the static type. See dartbug.com/21119. 3980 // list element, not the static type. See dartbug.com/21119.
3931 if (_checkForArgumentTypeNotAssignableWithExpectedTypes(key, keyType, 3981 if (_checkForArgumentTypeNotAssignableWithExpectedTypes(key, keyType,
3932 CheckedModeCompileTimeErrorCode.MAP_KEY_TYPE_NOT_ASSIGNABLE)) { 3982 CheckedModeCompileTimeErrorCode.MAP_KEY_TYPE_NOT_ASSIGNABLE)) {
3933 hasProblems = true; 3983 hasProblems = true;
3934 } 3984 }
3935 if (_checkForArgumentTypeNotAssignableWithExpectedTypes(value, 3985 if (_checkForArgumentTypeNotAssignableWithExpectedTypes(
3986 value,
3936 valueType, 3987 valueType,
3937 CheckedModeCompileTimeErrorCode.MAP_VALUE_TYPE_NOT_ASSIGNABLE)) { 3988 CheckedModeCompileTimeErrorCode.MAP_VALUE_TYPE_NOT_ASSIGNABLE)) {
3938 hasProblems = true; 3989 hasProblems = true;
3939 } 3990 }
3940 } 3991 }
3941 if (_checkForArgumentTypeNotAssignableWithExpectedTypes( 3992 if (_checkForArgumentTypeNotAssignableWithExpectedTypes(
3942 key, keyType, StaticWarningCode.MAP_KEY_TYPE_NOT_ASSIGNABLE)) { 3993 key, keyType, StaticWarningCode.MAP_KEY_TYPE_NOT_ASSIGNABLE)) {
3943 hasProblems = true; 3994 hasProblems = true;
3944 } 3995 }
3945 if (_checkForArgumentTypeNotAssignableWithExpectedTypes( 3996 if (_checkForArgumentTypeNotAssignableWithExpectedTypes(
(...skipping 16 matching lines...) Expand all
3962 } 4013 }
3963 String className = _enclosingClass.name; 4014 String className = _enclosingClass.name;
3964 if (className == null) { 4015 if (className == null) {
3965 return false; 4016 return false;
3966 } 4017 }
3967 bool problemReported = false; 4018 bool problemReported = false;
3968 // check accessors 4019 // check accessors
3969 for (PropertyAccessorElement accessor in _enclosingClass.accessors) { 4020 for (PropertyAccessorElement accessor in _enclosingClass.accessors) {
3970 if (className == accessor.name) { 4021 if (className == accessor.name) {
3971 _errorReporter.reportErrorForOffset( 4022 _errorReporter.reportErrorForOffset(
3972 CompileTimeErrorCode.MEMBER_WITH_CLASS_NAME, accessor.nameOffset, 4023 CompileTimeErrorCode.MEMBER_WITH_CLASS_NAME,
4024 accessor.nameOffset,
3973 className.length); 4025 className.length);
3974 problemReported = true; 4026 problemReported = true;
3975 } 4027 }
3976 } 4028 }
3977 // don't check methods, they would be constructors 4029 // don't check methods, they would be constructors
3978 // done 4030 // done
3979 return problemReported; 4031 return problemReported;
3980 } 4032 }
3981 4033
3982 /** 4034 /**
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
4048 getterType = _getGetterType(counterpartAccessor); 4100 getterType = _getGetterType(counterpartAccessor);
4049 } 4101 }
4050 // If either types are not assignable to each other, report an error 4102 // 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). 4103 // (if the getter is null, it is dynamic which is assignable to everything).
4052 if (setterType != null && 4104 if (setterType != null &&
4053 getterType != null && 4105 getterType != null &&
4054 !getterType.isAssignableTo(setterType)) { 4106 !getterType.isAssignableTo(setterType)) {
4055 if (enclosingClassForCounterpart == null) { 4107 if (enclosingClassForCounterpart == null) {
4056 _errorReporter.reportTypeErrorForNode( 4108 _errorReporter.reportTypeErrorForNode(
4057 StaticWarningCode.MISMATCHED_GETTER_AND_SETTER_TYPES, 4109 StaticWarningCode.MISMATCHED_GETTER_AND_SETTER_TYPES,
4058 accessorDeclaration, [accessorTextName, setterType, getterType]); 4110 accessorDeclaration,
4111 [accessorTextName, setterType, getterType]);
4059 return true; 4112 return true;
4060 } else { 4113 } else {
4061 _errorReporter.reportTypeErrorForNode( 4114 _errorReporter.reportTypeErrorForNode(
4062 StaticWarningCode.MISMATCHED_GETTER_AND_SETTER_TYPES_FROM_SUPERTYPE, 4115 StaticWarningCode.MISMATCHED_GETTER_AND_SETTER_TYPES_FROM_SUPERTYPE,
4063 accessorDeclaration, [ 4116 accessorDeclaration, [
4064 accessorTextName, 4117 accessorTextName,
4065 setterType, 4118 setterType,
4066 getterType, 4119 getterType,
4067 enclosingClassForCounterpart.displayName 4120 enclosingClassForCounterpart.displayName
4068 ]); 4121 ]);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
4114 } 4167 }
4115 } 4168 }
4116 int nameCount = constantNames.length; 4169 int nameCount = constantNames.length;
4117 if (nameCount == 0) { 4170 if (nameCount == 0) {
4118 return false; 4171 return false;
4119 } 4172 }
4120 for (int i = 0; i < nameCount; i++) { 4173 for (int i = 0; i < nameCount; i++) {
4121 int offset = statement.offset; 4174 int offset = statement.offset;
4122 int end = statement.rightParenthesis.end; 4175 int end = statement.rightParenthesis.end;
4123 _errorReporter.reportErrorForOffset( 4176 _errorReporter.reportErrorForOffset(
4124 CompileTimeErrorCode.MISSING_ENUM_CONSTANT_IN_SWITCH, offset, 4177 CompileTimeErrorCode.MISSING_ENUM_CONSTANT_IN_SWITCH,
4125 end - offset, [constantNames[i]]); 4178 offset,
4179 end - offset,
4180 [constantNames[i]]);
4126 } 4181 }
4127 return true; 4182 return true;
4128 } 4183 }
4129 4184
4130 /** 4185 /**
4131 * Verify that the given function [body] does not contain return statements 4186 * Verify that the given function [body] does not contain return statements
4132 * that both have and do not have return values. 4187 * that both have and do not have return values.
4133 * 4188 *
4134 * See [StaticWarningCode.MIXED_RETURN_TYPES]. 4189 * See [StaticWarningCode.MIXED_RETURN_TYPES].
4135 */ 4190 */
(...skipping 22 matching lines...) Expand all
4158 * constructor. The [mixinName] is the node to report problem on. The 4213 * constructor. The [mixinName] is the node to report problem on. The
4159 * [mixinElement] is the mixing to evaluate. 4214 * [mixinElement] is the mixing to evaluate.
4160 * 4215 *
4161 * See [CompileTimeErrorCode.MIXIN_DECLARES_CONSTRUCTOR]. 4216 * See [CompileTimeErrorCode.MIXIN_DECLARES_CONSTRUCTOR].
4162 */ 4217 */
4163 bool _checkForMixinDeclaresConstructor( 4218 bool _checkForMixinDeclaresConstructor(
4164 TypeName mixinName, ClassElement mixinElement) { 4219 TypeName mixinName, ClassElement mixinElement) {
4165 for (ConstructorElement constructor in mixinElement.constructors) { 4220 for (ConstructorElement constructor in mixinElement.constructors) {
4166 if (!constructor.isSynthetic && !constructor.isFactory) { 4221 if (!constructor.isSynthetic && !constructor.isFactory) {
4167 _errorReporter.reportErrorForNode( 4222 _errorReporter.reportErrorForNode(
4168 CompileTimeErrorCode.MIXIN_DECLARES_CONSTRUCTOR, mixinName, 4223 CompileTimeErrorCode.MIXIN_DECLARES_CONSTRUCTOR,
4224 mixinName,
4169 [mixinElement.name]); 4225 [mixinElement.name]);
4170 return true; 4226 return true;
4171 } 4227 }
4172 } 4228 }
4173 return false; 4229 return false;
4174 } 4230 }
4175 4231
4176 /** 4232 /**
4177 * Report the error [CompileTimeErrorCode.MIXIN_HAS_NO_CONSTRUCTORS] if 4233 * Report the error [CompileTimeErrorCode.MIXIN_HAS_NO_CONSTRUCTORS] if
4178 * appropriate. 4234 * appropriate.
(...skipping 13 matching lines...) Expand all
4192 * 4248 *
4193 * See [CompileTimeErrorCode.MIXIN_INHERITS_FROM_NOT_OBJECT]. 4249 * See [CompileTimeErrorCode.MIXIN_INHERITS_FROM_NOT_OBJECT].
4194 */ 4250 */
4195 bool _checkForMixinInheritsNotFromObject( 4251 bool _checkForMixinInheritsNotFromObject(
4196 TypeName mixinName, ClassElement mixinElement) { 4252 TypeName mixinName, ClassElement mixinElement) {
4197 InterfaceType mixinSupertype = mixinElement.supertype; 4253 InterfaceType mixinSupertype = mixinElement.supertype;
4198 if (mixinSupertype != null) { 4254 if (mixinSupertype != null) {
4199 if (!mixinSupertype.isObject || 4255 if (!mixinSupertype.isObject ||
4200 !mixinElement.isMixinApplication && mixinElement.mixins.length != 0) { 4256 !mixinElement.isMixinApplication && mixinElement.mixins.length != 0) {
4201 _errorReporter.reportErrorForNode( 4257 _errorReporter.reportErrorForNode(
4202 CompileTimeErrorCode.MIXIN_INHERITS_FROM_NOT_OBJECT, mixinName, 4258 CompileTimeErrorCode.MIXIN_INHERITS_FROM_NOT_OBJECT,
4259 mixinName,
4203 [mixinElement.name]); 4260 [mixinElement.name]);
4204 return true; 4261 return true;
4205 } 4262 }
4206 } 4263 }
4207 return false; 4264 return false;
4208 } 4265 }
4209 4266
4210 /** 4267 /**
4211 * Verify that the given mixin does not reference 'super'. The [mixinName] is 4268 * 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 4269 * the node to report problem on. The [mixinElement] is the mixing to
4213 * evaluate. 4270 * evaluate.
4214 * 4271 *
4215 * See [CompileTimeErrorCode.MIXIN_REFERENCES_SUPER]. 4272 * See [CompileTimeErrorCode.MIXIN_REFERENCES_SUPER].
4216 */ 4273 */
4217 bool _checkForMixinReferencesSuper( 4274 bool _checkForMixinReferencesSuper(
4218 TypeName mixinName, ClassElement mixinElement) { 4275 TypeName mixinName, ClassElement mixinElement) {
4219 if (!enableSuperMixins && mixinElement.hasReferenceToSuper) { 4276 if (!enableSuperMixins && mixinElement.hasReferenceToSuper) {
4220 _errorReporter.reportErrorForNode( 4277 _errorReporter.reportErrorForNode(
4221 CompileTimeErrorCode.MIXIN_REFERENCES_SUPER, mixinName, 4278 CompileTimeErrorCode.MIXIN_REFERENCES_SUPER,
4279 mixinName,
4222 [mixinElement.name]); 4280 [mixinElement.name]);
4223 } 4281 }
4224 return false; 4282 return false;
4225 } 4283 }
4226 4284
4227 /** 4285 /**
4228 * Verify that the given [constructor] has at most one 'super' initializer. 4286 * Verify that the given [constructor] has at most one 'super' initializer.
4229 * 4287 *
4230 * See [CompileTimeErrorCode.MULTIPLE_SUPER_INITIALIZERS]. 4288 * See [CompileTimeErrorCode.MULTIPLE_SUPER_INITIALIZERS].
4231 */ 4289 */
(...skipping 29 matching lines...) Expand all
4261 * Verify that the given instance creation [expression] invokes an existing 4319 * Verify that the given instance creation [expression] invokes an existing
4262 * constructor. The [constructorName] is the constructor name. The [typeName] 4320 * constructor. The [constructorName] is the constructor name. The [typeName]
4263 * is the name of the type defining the constructor. 4321 * is the name of the type defining the constructor.
4264 * 4322 *
4265 * This method assumes that the instance creation was tested to be 'new' 4323 * This method assumes that the instance creation was tested to be 'new'
4266 * before being called. 4324 * before being called.
4267 * 4325 *
4268 * See [StaticWarningCode.NEW_WITH_UNDEFINED_CONSTRUCTOR]. 4326 * See [StaticWarningCode.NEW_WITH_UNDEFINED_CONSTRUCTOR].
4269 */ 4327 */
4270 bool _checkForNewWithUndefinedConstructor( 4328 bool _checkForNewWithUndefinedConstructor(
4271 InstanceCreationExpression expression, ConstructorName constructorName, 4329 InstanceCreationExpression expression,
4330 ConstructorName constructorName,
4272 TypeName typeName) { 4331 TypeName typeName) {
4273 // OK if resolved 4332 // OK if resolved
4274 if (expression.staticElement != null) { 4333 if (expression.staticElement != null) {
4275 return false; 4334 return false;
4276 } 4335 }
4277 DartType type = typeName.type; 4336 DartType type = typeName.type;
4278 if (type is InterfaceType) { 4337 if (type is InterfaceType) {
4279 ClassElement element = type.element; 4338 ClassElement element = type.element;
4280 if (element != null && element.isEnum) { 4339 if (element != null && element.isEnum) {
4281 // We have already reported the error. 4340 // We have already reported the error.
4282 return false; 4341 return false;
4283 } 4342 }
4284 } 4343 }
4285 // prepare class name 4344 // prepare class name
4286 Identifier className = typeName.name; 4345 Identifier className = typeName.name;
4287 // report as named or default constructor absence 4346 // report as named or default constructor absence
4288 SimpleIdentifier name = constructorName.name; 4347 SimpleIdentifier name = constructorName.name;
4289 if (name != null) { 4348 if (name != null) {
4290 _errorReporter.reportErrorForNode( 4349 _errorReporter.reportErrorForNode(
4291 StaticWarningCode.NEW_WITH_UNDEFINED_CONSTRUCTOR, name, [ 4350 StaticWarningCode.NEW_WITH_UNDEFINED_CONSTRUCTOR,
4292 className, 4351 name,
4293 name 4352 [className, name]);
4294 ]);
4295 } else { 4353 } else {
4296 _errorReporter.reportErrorForNode( 4354 _errorReporter.reportErrorForNode(
4297 StaticWarningCode.NEW_WITH_UNDEFINED_CONSTRUCTOR_DEFAULT, 4355 StaticWarningCode.NEW_WITH_UNDEFINED_CONSTRUCTOR_DEFAULT,
4298 constructorName, [className]); 4356 constructorName,
4357 [className]);
4299 } 4358 }
4300 return true; 4359 return true;
4301 } 4360 }
4302 4361
4303 /** 4362 /**
4304 * Check that if the given class [declaration] implicitly calls default 4363 * Check that if the given class [declaration] implicitly calls default
4305 * constructor of its superclass, there should be such default constructor - 4364 * constructor of its superclass, there should be such default constructor -
4306 * implicit or explicit. 4365 * implicit or explicit.
4307 * 4366 *
4308 * See [CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT]. 4367 * See [CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT].
(...skipping 15 matching lines...) Expand all
4324 if (superType == null) { 4383 if (superType == null) {
4325 return false; 4384 return false;
4326 } 4385 }
4327 ClassElement superElement = superType.element; 4386 ClassElement superElement = superType.element;
4328 // try to find default generative super constructor 4387 // try to find default generative super constructor
4329 ConstructorElement superUnnamedConstructor = 4388 ConstructorElement superUnnamedConstructor =
4330 superElement.unnamedConstructor; 4389 superElement.unnamedConstructor;
4331 if (superUnnamedConstructor != null) { 4390 if (superUnnamedConstructor != null) {
4332 if (superUnnamedConstructor.isFactory) { 4391 if (superUnnamedConstructor.isFactory) {
4333 _errorReporter.reportErrorForNode( 4392 _errorReporter.reportErrorForNode(
4334 CompileTimeErrorCode.NON_GENERATIVE_CONSTRUCTOR, declaration.name, 4393 CompileTimeErrorCode.NON_GENERATIVE_CONSTRUCTOR,
4394 declaration.name,
4335 [superUnnamedConstructor]); 4395 [superUnnamedConstructor]);
4336 return true; 4396 return true;
4337 } 4397 }
4338 if (superUnnamedConstructor.isDefaultConstructor && 4398 if (superUnnamedConstructor.isDefaultConstructor &&
4339 _enclosingClass 4399 _enclosingClass
4340 .isSuperConstructorAccessible(superUnnamedConstructor)) { 4400 .isSuperConstructorAccessible(superUnnamedConstructor)) {
4341 return true; 4401 return true;
4342 } 4402 }
4343 } 4403 }
4344 // report problem 4404 // report problem
4345 _errorReporter.reportErrorForNode( 4405 _errorReporter.reportErrorForNode(
4346 CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT, 4406 CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT,
4347 declaration.name, [superType.displayName]); 4407 declaration.name,
4408 [superType.displayName]);
4348 return true; 4409 return true;
4349 } 4410 }
4350 4411
4351 /** 4412 /**
4352 * Check that the given class declaration overrides all members required by 4413 * Check that the given class declaration overrides all members required by
4353 * its superclasses and interfaces. The [classNameNode] is the 4414 * its superclasses and interfaces. The [classNameNode] is the
4354 * [SimpleIdentifier] to be used if there is a violation, this is either the 4415 * [SimpleIdentifier] to be used if there is a violation, this is either the
4355 * named from the [ClassDeclaration] or from the [ClassTypeAlias]. 4416 * named from the [ClassDeclaration] or from the [ClassTypeAlias].
4356 * 4417 *
4357 * See [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE], 4418 * See [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE],
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
4479 } else { 4540 } else {
4480 newStrMember = "$prefix'${missingOverridesArray[i].displayName}'"; 4541 newStrMember = "$prefix'${missingOverridesArray[i].displayName}'";
4481 } 4542 }
4482 stringMembersArrayListSet.add(newStrMember); 4543 stringMembersArrayListSet.add(newStrMember);
4483 } 4544 }
4484 List<String> stringMembersArray = new List.from(stringMembersArrayListSet); 4545 List<String> stringMembersArray = new List.from(stringMembersArrayListSet);
4485 AnalysisErrorWithProperties analysisError; 4546 AnalysisErrorWithProperties analysisError;
4486 if (stringMembersArray.length == 1) { 4547 if (stringMembersArray.length == 1) {
4487 analysisError = _errorReporter.newErrorWithProperties( 4548 analysisError = _errorReporter.newErrorWithProperties(
4488 StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE, 4549 StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE,
4489 classNameNode, [stringMembersArray[0]]); 4550 classNameNode,
4551 [stringMembersArray[0]]);
4490 } else if (stringMembersArray.length == 2) { 4552 } else if (stringMembersArray.length == 2) {
4491 analysisError = _errorReporter.newErrorWithProperties( 4553 analysisError = _errorReporter.newErrorWithProperties(
4492 StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_TWO, 4554 StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_TWO,
4493 classNameNode, [stringMembersArray[0], stringMembersArray[1]]); 4555 classNameNode,
4556 [stringMembersArray[0], stringMembersArray[1]]);
4494 } else if (stringMembersArray.length == 3) { 4557 } else if (stringMembersArray.length == 3) {
4495 analysisError = _errorReporter.newErrorWithProperties( 4558 analysisError = _errorReporter.newErrorWithProperties(
4496 StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_THREE, 4559 StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_THREE,
4497 classNameNode, [ 4560 classNameNode, [
4498 stringMembersArray[0], 4561 stringMembersArray[0],
4499 stringMembersArray[1], 4562 stringMembersArray[1],
4500 stringMembersArray[2] 4563 stringMembersArray[2]
4501 ]); 4564 ]);
4502 } else if (stringMembersArray.length == 4) { 4565 } else if (stringMembersArray.length == 4) {
4503 analysisError = _errorReporter.newErrorWithProperties( 4566 analysisError = _errorReporter.newErrorWithProperties(
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
4610 if (!identical(statement.beginToken, literal.beginToken)) { 4673 if (!identical(statement.beginToken, literal.beginToken)) {
4611 return false; 4674 return false;
4612 } 4675 }
4613 // report problem 4676 // report problem
4614 _errorReporter.reportErrorForNode( 4677 _errorReporter.reportErrorForNode(
4615 CompileTimeErrorCode.NON_CONST_MAP_AS_EXPRESSION_STATEMENT, literal); 4678 CompileTimeErrorCode.NON_CONST_MAP_AS_EXPRESSION_STATEMENT, literal);
4616 return true; 4679 return true;
4617 } 4680 }
4618 4681
4619 /** 4682 /**
4683 * If the given assert [statement] specifies a message, verify that its type
4684 * is assignable to `String`.
4685 *
4686 * See [StaticTypeWarningCode.ASSERT_MESSAGE_NON_STRING].
4687 */
4688 bool _checkForNonStringMessage(AssertStatement statement) {
4689 Expression expression = statement.message;
4690 if (expression != null) {
4691 DartType type = getStaticType(expression);
4692 if (!type.isAssignableTo(_stringType)) {
4693 _errorReporter.reportErrorForNode(
4694 StaticTypeWarningCode.ASSERT_MESSAGE_NON_STRING, expression);
4695 }
4696 }
4697 }
4698
4699 /**
4620 * Verify that the given method [declaration] of operator `[]=`, has `void` 4700 * Verify that the given method [declaration] of operator `[]=`, has `void`
4621 * return type. 4701 * return type.
4622 * 4702 *
4623 * See [StaticWarningCode.NON_VOID_RETURN_FOR_OPERATOR]. 4703 * See [StaticWarningCode.NON_VOID_RETURN_FOR_OPERATOR].
4624 */ 4704 */
4625 bool _checkForNonVoidReturnTypeForOperator(MethodDeclaration declaration) { 4705 bool _checkForNonVoidReturnTypeForOperator(MethodDeclaration declaration) {
4626 // check that []= operator 4706 // check that []= operator
4627 SimpleIdentifier name = declaration.name; 4707 SimpleIdentifier name = declaration.name;
4628 if (name.name != "[]=") { 4708 if (name.name != "[]=") {
4629 return false; 4709 return false;
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
4819 RedirectingConstructorInvocation invocation = initializer; 4899 RedirectingConstructorInvocation invocation = initializer;
4820 ConstructorElement redirectingElement = invocation.staticElement; 4900 ConstructorElement redirectingElement = invocation.staticElement;
4821 if (redirectingElement == null) { 4901 if (redirectingElement == null) {
4822 String enclosingTypeName = _enclosingClass.displayName; 4902 String enclosingTypeName = _enclosingClass.displayName;
4823 String constructorStrName = enclosingTypeName; 4903 String constructorStrName = enclosingTypeName;
4824 if (invocation.constructorName != null) { 4904 if (invocation.constructorName != null) {
4825 constructorStrName += ".${invocation.constructorName.name}"; 4905 constructorStrName += ".${invocation.constructorName.name}";
4826 } 4906 }
4827 _errorReporter.reportErrorForNode( 4907 _errorReporter.reportErrorForNode(
4828 CompileTimeErrorCode.REDIRECT_GENERATIVE_TO_MISSING_CONSTRUCTOR, 4908 CompileTimeErrorCode.REDIRECT_GENERATIVE_TO_MISSING_CONSTRUCTOR,
4829 invocation, [constructorStrName, enclosingTypeName]); 4909 invocation,
4910 [constructorStrName, enclosingTypeName]);
4830 } else { 4911 } else {
4831 if (redirectingElement.isFactory) { 4912 if (redirectingElement.isFactory) {
4832 _errorReporter.reportErrorForNode( 4913 _errorReporter.reportErrorForNode(
4833 CompileTimeErrorCode.REDIRECT_GENERATIVE_TO_NON_GENERATIVE_CON STRUCTOR, 4914 CompileTimeErrorCode.REDIRECT_GENERATIVE_TO_NON_GENERATIVE_CON STRUCTOR,
4834 initializer); 4915 initializer);
4835 } 4916 }
4836 } 4917 }
4837 } 4918 }
4838 numRedirections++; 4919 numRedirections++;
4839 } 4920 }
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
4967 staticReturnType, 5048 staticReturnType,
4968 expectedReturnType, 5049 expectedReturnType,
4969 _enclosingFunction.displayName 5050 _enclosingFunction.displayName
4970 ]); 5051 ]);
4971 return true; 5052 return true;
4972 } 5053 }
4973 if (staticReturnType.isAssignableTo(expectedReturnType)) { 5054 if (staticReturnType.isAssignableTo(expectedReturnType)) {
4974 return false; 5055 return false;
4975 } 5056 }
4976 _errorReporter.reportTypeErrorForNode( 5057 _errorReporter.reportTypeErrorForNode(
4977 StaticTypeWarningCode.RETURN_OF_INVALID_TYPE, returnExpression, [ 5058 StaticTypeWarningCode.RETURN_OF_INVALID_TYPE,
4978 staticReturnType, 5059 returnExpression,
4979 expectedReturnType, 5060 [staticReturnType, expectedReturnType, _enclosingFunction.displayName]);
4980 _enclosingFunction.displayName
4981 ]);
4982 return true; 5061 return true;
4983 // TODO(brianwilkerson) Define a hint corresponding to the warning and 5062 // TODO(brianwilkerson) Define a hint corresponding to the warning and
4984 // report it if appropriate. 5063 // report it if appropriate.
4985 // Type propagatedReturnType = returnExpression.getPropagatedType(); 5064 // Type propagatedReturnType = returnExpression.getPropagatedType();
4986 // boolean isPropagatedAssignable = propagatedReturnType.isAssignableTo(e xpectedReturnType); 5065 // boolean isPropagatedAssignable = propagatedReturnType.isAssignableTo(e xpectedReturnType);
4987 // if (isStaticAssignable || isPropagatedAssignable) { 5066 // if (isStaticAssignable || isPropagatedAssignable) {
4988 // return false; 5067 // return false;
4989 // } 5068 // }
4990 // errorReporter.reportTypeErrorForNode( 5069 // errorReporter.reportTypeErrorForNode(
4991 // StaticTypeWarningCode.RETURN_OF_INVALID_TYPE, 5070 // StaticTypeWarningCode.RETURN_OF_INVALID_TYPE,
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
5046 SwitchCase switchCase = switchMember as SwitchCase; 5125 SwitchCase switchCase = switchMember as SwitchCase;
5047 // prepare 'case' type 5126 // prepare 'case' type
5048 Expression caseExpression = switchCase.expression; 5127 Expression caseExpression = switchCase.expression;
5049 DartType caseType = getStaticType(caseExpression); 5128 DartType caseType = getStaticType(caseExpression);
5050 // check types 5129 // check types
5051 if (expressionType.isAssignableTo(caseType)) { 5130 if (expressionType.isAssignableTo(caseType)) {
5052 return false; 5131 return false;
5053 } 5132 }
5054 // report problem 5133 // report problem
5055 _errorReporter.reportErrorForNode( 5134 _errorReporter.reportErrorForNode(
5056 StaticWarningCode.SWITCH_EXPRESSION_NOT_ASSIGNABLE, expression, [ 5135 StaticWarningCode.SWITCH_EXPRESSION_NOT_ASSIGNABLE,
5057 expressionType, 5136 expression,
5058 caseType 5137 [expressionType, caseType]);
5059 ]);
5060 return true; 5138 return true;
5061 } 5139 }
5062 return false; 5140 return false;
5063 } 5141 }
5064 5142
5065 /** 5143 /**
5066 * Verify that the given function type [alias] does not reference itself 5144 * Verify that the given function type [alias] does not reference itself
5067 * directly. 5145 * directly.
5068 * 5146 *
5069 * See [CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REFERENCE_ITSELF]. 5147 * See [CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REFERENCE_ITSELF].
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
5176 DartType bound = element.bound; 5254 DartType bound = element.bound;
5177 if (bound == null) { 5255 if (bound == null) {
5178 return false; 5256 return false;
5179 } 5257 }
5180 // OK, type parameter is not supertype of its bound 5258 // OK, type parameter is not supertype of its bound
5181 if (!bound.isMoreSpecificThan(element.type)) { 5259 if (!bound.isMoreSpecificThan(element.type)) {
5182 return false; 5260 return false;
5183 } 5261 }
5184 // report problem 5262 // report problem
5185 _errorReporter.reportErrorForNode( 5263 _errorReporter.reportErrorForNode(
5186 StaticTypeWarningCode.TYPE_PARAMETER_SUPERTYPE_OF_ITS_BOUND, parameter, 5264 StaticTypeWarningCode.TYPE_PARAMETER_SUPERTYPE_OF_ITS_BOUND,
5265 parameter,
5187 [element.displayName]); 5266 [element.displayName]);
5188 return true; 5267 return true;
5189 } 5268 }
5190 5269
5191 /** 5270 /**
5192 * Check that if the given generative [constructor] has neither an explicit 5271 * Check that if the given generative [constructor] has neither an explicit
5193 * super constructor invocation nor a redirecting constructor invocation, that 5272 * super constructor invocation nor a redirecting constructor invocation, that
5194 * the superclass has a default generative constructor. 5273 * the superclass has a default generative constructor.
5195 * 5274 *
5196 * See [CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALIZER_DEFAULT], 5275 * See [CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALIZER_DEFAULT],
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
5232 if (superType == null) { 5311 if (superType == null) {
5233 return false; 5312 return false;
5234 } 5313 }
5235 ClassElement superElement = superType.element; 5314 ClassElement superElement = superType.element;
5236 ConstructorElement superUnnamedConstructor = 5315 ConstructorElement superUnnamedConstructor =
5237 superElement.unnamedConstructor; 5316 superElement.unnamedConstructor;
5238 if (superUnnamedConstructor != null) { 5317 if (superUnnamedConstructor != null) {
5239 if (superUnnamedConstructor.isFactory) { 5318 if (superUnnamedConstructor.isFactory) {
5240 _errorReporter.reportErrorForNode( 5319 _errorReporter.reportErrorForNode(
5241 CompileTimeErrorCode.NON_GENERATIVE_CONSTRUCTOR, 5320 CompileTimeErrorCode.NON_GENERATIVE_CONSTRUCTOR,
5242 constructor.returnType, [superUnnamedConstructor]); 5321 constructor.returnType,
5322 [superUnnamedConstructor]);
5243 return true; 5323 return true;
5244 } 5324 }
5245 if (!superUnnamedConstructor.isDefaultConstructor || 5325 if (!superUnnamedConstructor.isDefaultConstructor ||
5246 !_enclosingClass 5326 !_enclosingClass
5247 .isSuperConstructorAccessible(superUnnamedConstructor)) { 5327 .isSuperConstructorAccessible(superUnnamedConstructor)) {
5248 int offset; 5328 int offset;
5249 int length; 5329 int length;
5250 { 5330 {
5251 Identifier returnType = constructor.returnType; 5331 Identifier returnType = constructor.returnType;
5252 SimpleIdentifier name = constructor.name; 5332 SimpleIdentifier name = constructor.name;
5253 offset = returnType.offset; 5333 offset = returnType.offset;
5254 length = (name != null ? name.end : returnType.end) - offset; 5334 length = (name != null ? name.end : returnType.end) - offset;
5255 } 5335 }
5256 _errorReporter.reportErrorForOffset( 5336 _errorReporter.reportErrorForOffset(
5257 CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_EXPLICIT, offset, 5337 CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_EXPLICIT,
5258 length, [superType.displayName]); 5338 offset,
5339 length,
5340 [superType.displayName]);
5259 } 5341 }
5260 return false; 5342 return false;
5261 } 5343 }
5262 _errorReporter.reportErrorForNode( 5344 _errorReporter.reportErrorForNode(
5263 CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALIZER_DEFAULT, 5345 CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALIZER_DEFAULT,
5264 constructor.returnType, [superElement.name]); 5346 constructor.returnType,
5347 [superElement.name]);
5265 return true; 5348 return true;
5266 } 5349 }
5267 5350
5268 /** 5351 /**
5269 * Check that if the given [name] is a reference to a static member it is 5352 * 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. 5353 * defined in the enclosing class rather than in a superclass.
5271 * 5354 *
5272 * See [StaticTypeWarningCode.UNQUALIFIED_REFERENCE_TO_NON_LOCAL_STATIC_MEMBER ]. 5355 * See [StaticTypeWarningCode.UNQUALIFIED_REFERENCE_TO_NON_LOCAL_STATIC_MEMBER ].
5273 */ 5356 */
5274 bool _checkForUnqualifiedReferenceToNonLocalStaticMember( 5357 bool _checkForUnqualifiedReferenceToNonLocalStaticMember(
5275 SimpleIdentifier name) { 5358 SimpleIdentifier name) {
5276 Element element = name.staticElement; 5359 Element element = name.staticElement;
5277 if (element == null || element is TypeParameterElement) { 5360 if (element == null || element is TypeParameterElement) {
5278 return false; 5361 return false;
5279 } 5362 }
5280 Element enclosingElement = element.enclosingElement; 5363 Element enclosingElement = element.enclosingElement;
5281 if (enclosingElement is! ClassElement) { 5364 if (enclosingElement is! ClassElement) {
5282 return false; 5365 return false;
5283 } 5366 }
5284 if ((element is MethodElement && !element.isStatic) || 5367 if ((element is MethodElement && !element.isStatic) ||
5285 (element is PropertyAccessorElement && !element.isStatic)) { 5368 (element is PropertyAccessorElement && !element.isStatic)) {
5286 return false; 5369 return false;
5287 } 5370 }
5288 if (identical(enclosingElement, _enclosingClass)) { 5371 if (identical(enclosingElement, _enclosingClass)) {
5289 return false; 5372 return false;
5290 } 5373 }
5291 _errorReporter.reportErrorForNode( 5374 _errorReporter.reportErrorForNode(
5292 StaticTypeWarningCode.UNQUALIFIED_REFERENCE_TO_NON_LOCAL_STATIC_MEMBER, 5375 StaticTypeWarningCode.UNQUALIFIED_REFERENCE_TO_NON_LOCAL_STATIC_MEMBER,
5293 name, [name.name]); 5376 name,
5377 [name.name]);
5294 return true; 5378 return true;
5295 } 5379 }
5296 5380
5297 void _checkForValidField(FieldFormalParameter parameter) { 5381 void _checkForValidField(FieldFormalParameter parameter) {
5298 ParameterElement element = parameter.element; 5382 ParameterElement element = parameter.element;
5299 if (element is FieldFormalParameterElement) { 5383 if (element is FieldFormalParameterElement) {
5300 FieldElement fieldElement = element.field; 5384 FieldElement fieldElement = element.field;
5301 if (fieldElement == null || fieldElement.isSynthetic) { 5385 if (fieldElement == null || fieldElement.isSynthetic) {
5302 _errorReporter.reportErrorForNode( 5386 _errorReporter.reportErrorForNode(
5303 CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_NON_EXISTENT_FIELD, 5387 CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_NON_EXISTENT_FIELD,
5304 parameter, [parameter.identifier.name]); 5388 parameter,
5389 [parameter.identifier.name]);
5305 } else { 5390 } else {
5306 ParameterElement parameterElement = parameter.element; 5391 ParameterElement parameterElement = parameter.element;
5307 if (parameterElement is FieldFormalParameterElementImpl) { 5392 if (parameterElement is FieldFormalParameterElementImpl) {
5308 FieldFormalParameterElementImpl fieldFormal = parameterElement; 5393 FieldFormalParameterElementImpl fieldFormal = parameterElement;
5309 DartType declaredType = fieldFormal.type; 5394 DartType declaredType = fieldFormal.type;
5310 DartType fieldType = fieldElement.type; 5395 DartType fieldType = fieldElement.type;
5311 if (fieldElement.isSynthetic) { 5396 if (fieldElement.isSynthetic) {
5312 _errorReporter.reportErrorForNode( 5397 _errorReporter.reportErrorForNode(
5313 CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_NON_EXISTENT_FIELD, 5398 CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_NON_EXISTENT_FIELD,
5314 parameter, [parameter.identifier.name]); 5399 parameter,
5400 [parameter.identifier.name]);
5315 } else if (fieldElement.isStatic) { 5401 } else if (fieldElement.isStatic) {
5316 _errorReporter.reportErrorForNode( 5402 _errorReporter.reportErrorForNode(
5317 CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_STATIC_FIELD, 5403 CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_STATIC_FIELD,
5318 parameter, [parameter.identifier.name]); 5404 parameter,
5405 [parameter.identifier.name]);
5319 } else if (declaredType != null && 5406 } else if (declaredType != null &&
5320 fieldType != null && 5407 fieldType != null &&
5321 !declaredType.isAssignableTo(fieldType)) { 5408 !declaredType.isAssignableTo(fieldType)) {
5322 _errorReporter.reportTypeErrorForNode( 5409 _errorReporter.reportTypeErrorForNode(
5323 StaticWarningCode.FIELD_INITIALIZING_FORMAL_NOT_ASSIGNABLE, 5410 StaticWarningCode.FIELD_INITIALIZING_FORMAL_NOT_ASSIGNABLE,
5324 parameter, [declaredType, fieldType]); 5411 parameter,
5412 [declaredType, fieldType]);
5325 } 5413 }
5326 } else { 5414 } else {
5327 if (fieldElement.isSynthetic) { 5415 if (fieldElement.isSynthetic) {
5328 _errorReporter.reportErrorForNode( 5416 _errorReporter.reportErrorForNode(
5329 CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_NON_EXISTENT_FIELD, 5417 CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_NON_EXISTENT_FIELD,
5330 parameter, [parameter.identifier.name]); 5418 parameter,
5419 [parameter.identifier.name]);
5331 } else if (fieldElement.isStatic) { 5420 } else if (fieldElement.isStatic) {
5332 _errorReporter.reportErrorForNode( 5421 _errorReporter.reportErrorForNode(
5333 CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_STATIC_FIELD, 5422 CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_STATIC_FIELD,
5334 parameter, [parameter.identifier.name]); 5423 parameter,
5424 [parameter.identifier.name]);
5335 } 5425 }
5336 } 5426 }
5337 } 5427 }
5338 } 5428 }
5339 // else { 5429 // else {
5340 // // TODO(jwren) Report error, constructor initializer variable is a top level element 5430 // // TODO(jwren) Report error, constructor initializer variable is a top level element
5341 // // (Either here or in ErrorVerifier.checkForAllFinalInitializedErrorCo des) 5431 // // (Either here or in ErrorVerifier.checkForAllFinalInitializedErrorCo des)
5342 // } 5432 // }
5343 } 5433 }
5344 5434
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
5400 "<<" == name || 5490 "<<" == name ||
5401 ">>" == name || 5491 ">>" == name ||
5402 "[]" == name) { 5492 "[]" == name) {
5403 expected = 1; 5493 expected = 1;
5404 } else if ("~" == name) { 5494 } else if ("~" == name) {
5405 expected = 0; 5495 expected = 0;
5406 } 5496 }
5407 if (expected != -1 && numParameters != expected) { 5497 if (expected != -1 && numParameters != expected) {
5408 _errorReporter.reportErrorForNode( 5498 _errorReporter.reportErrorForNode(
5409 CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_OPERATOR, 5499 CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_OPERATOR,
5410 nameNode, [name, expected, numParameters]); 5500 nameNode,
5501 [name, expected, numParameters]);
5411 return true; 5502 return true;
5412 } 5503 }
5413 // check for operator "-" 5504 // check for operator "-"
5414 if ("-" == name && numParameters > 1) { 5505 if ("-" == name && numParameters > 1) {
5415 _errorReporter.reportErrorForNode( 5506 _errorReporter.reportErrorForNode(
5416 CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_OPERATOR_MINUS, 5507 CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_OPERATOR_MINUS,
5417 nameNode, [numParameters]); 5508 nameNode,
5509 [numParameters]);
5418 return true; 5510 return true;
5419 } 5511 }
5420 // OK 5512 // OK
5421 return false; 5513 return false;
5422 } 5514 }
5423 5515
5424 /** 5516 /**
5425 * Verify that the given setter [parameterList] has only one required 5517 * Verify that the given setter [parameterList] has only one required
5426 * parameter. The [setterName] is the name of the setter to report problems 5518 * parameter. The [setterName] is the name of the setter to report problems
5427 * on. 5519 * on.
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
5469 impliedReturnType = staticYieldedType; 5561 impliedReturnType = staticYieldedType;
5470 } else if (_enclosingFunction.isAsynchronous) { 5562 } else if (_enclosingFunction.isAsynchronous) {
5471 impliedReturnType = 5563 impliedReturnType =
5472 _typeProvider.streamType.substitute4(<DartType>[staticYieldedType]); 5564 _typeProvider.streamType.substitute4(<DartType>[staticYieldedType]);
5473 } else { 5565 } else {
5474 impliedReturnType = 5566 impliedReturnType =
5475 _typeProvider.iterableType.substitute4(<DartType>[staticYieldedType]); 5567 _typeProvider.iterableType.substitute4(<DartType>[staticYieldedType]);
5476 } 5568 }
5477 if (!impliedReturnType.isAssignableTo(declaredReturnType)) { 5569 if (!impliedReturnType.isAssignableTo(declaredReturnType)) {
5478 _errorReporter.reportTypeErrorForNode( 5570 _errorReporter.reportTypeErrorForNode(
5479 StaticTypeWarningCode.YIELD_OF_INVALID_TYPE, yieldExpression, [ 5571 StaticTypeWarningCode.YIELD_OF_INVALID_TYPE,
5480 impliedReturnType, 5572 yieldExpression,
5481 declaredReturnType 5573 [impliedReturnType, declaredReturnType]);
5482 ]);
5483 return true; 5574 return true;
5484 } 5575 }
5485 if (isYieldEach) { 5576 if (isYieldEach) {
5486 // Since the declared return type might have been "dynamic", we need to 5577 // Since the declared return type might have been "dynamic", we need to
5487 // also check that the implied return type is assignable to generic 5578 // also check that the implied return type is assignable to generic
5488 // Stream/Iterable. 5579 // Stream/Iterable.
5489 DartType requiredReturnType; 5580 DartType requiredReturnType;
5490 if (_enclosingFunction.isAsynchronous) { 5581 if (_enclosingFunction.isAsynchronous) {
5491 requiredReturnType = _typeProvider.streamDynamicType; 5582 requiredReturnType = _typeProvider.streamDynamicType;
5492 } else { 5583 } else {
5493 requiredReturnType = _typeProvider.iterableDynamicType; 5584 requiredReturnType = _typeProvider.iterableDynamicType;
5494 } 5585 }
5495 if (!impliedReturnType.isAssignableTo(requiredReturnType)) { 5586 if (!impliedReturnType.isAssignableTo(requiredReturnType)) {
5496 _errorReporter.reportTypeErrorForNode( 5587 _errorReporter.reportTypeErrorForNode(
5497 StaticTypeWarningCode.YIELD_OF_INVALID_TYPE, yieldExpression, [ 5588 StaticTypeWarningCode.YIELD_OF_INVALID_TYPE,
5498 impliedReturnType, 5589 yieldExpression,
5499 requiredReturnType 5590 [impliedReturnType, requiredReturnType]);
5500 ]);
5501 return true; 5591 return true;
5502 } 5592 }
5503 } 5593 }
5504 return false; 5594 return false;
5505 } 5595 }
5506 5596
5507 /** 5597 /**
5508 * Verify that if the given class [declaration] implements the class Function 5598 * Verify that if the given class [declaration] implements the class Function
5509 * that it has a concrete implementation of the call method. 5599 * that it has a concrete implementation of the call method.
5510 * 5600 *
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
5555 ImplementsClause implementsClause = declaration.implementsClause; 5645 ImplementsClause implementsClause = declaration.implementsClause;
5556 if (implementsClause == null) { 5646 if (implementsClause == null) {
5557 return false; 5647 return false;
5558 } 5648 }
5559 // check interfaces 5649 // check interfaces
5560 bool hasProblem = false; 5650 bool hasProblem = false;
5561 for (TypeName interfaceNode in implementsClause.interfaces) { 5651 for (TypeName interfaceNode in implementsClause.interfaces) {
5562 if (interfaceNode.type == superType) { 5652 if (interfaceNode.type == superType) {
5563 hasProblem = true; 5653 hasProblem = true;
5564 _errorReporter.reportErrorForNode( 5654 _errorReporter.reportErrorForNode(
5565 CompileTimeErrorCode.IMPLEMENTS_SUPER_CLASS, interfaceNode, 5655 CompileTimeErrorCode.IMPLEMENTS_SUPER_CLASS,
5656 interfaceNode,
5566 [superType.displayName]); 5657 [superType.displayName]);
5567 } 5658 }
5568 } 5659 }
5569 // done 5660 // done
5570 return hasProblem; 5661 return hasProblem;
5571 } 5662 }
5572 5663
5573 DartType _computeReturnTypeForMethod(Expression returnExpression) { 5664 DartType _computeReturnTypeForMethod(Expression returnExpression) {
5574 // This method should never be called for generators, since generators are 5665 // This method should never be called for generators, since generators are
5575 // never allowed to contain return statements with expressions. 5666 // never allowed to contain return statements with expressions.
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
5876 // "A, B, C, D, A" 5967 // "A, B, C, D, A"
5877 String separator = ", "; 5968 String separator = ", ";
5878 StringBuffer buffer = new StringBuffer(); 5969 StringBuffer buffer = new StringBuffer();
5879 for (int i = 0; i < size; i++) { 5970 for (int i = 0; i < size; i++) {
5880 buffer.write(path[i].displayName); 5971 buffer.write(path[i].displayName);
5881 buffer.write(separator); 5972 buffer.write(separator);
5882 } 5973 }
5883 buffer.write(element.displayName); 5974 buffer.write(element.displayName);
5884 _errorReporter.reportErrorForOffset( 5975 _errorReporter.reportErrorForOffset(
5885 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE, 5976 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE,
5886 _enclosingClass.nameOffset, enclosingClassName.length, [ 5977 _enclosingClass.nameOffset,
5887 enclosingClassName, 5978 enclosingClassName.length,
5888 buffer.toString() 5979 [enclosingClassName, buffer.toString()]);
5889 ]);
5890 return true; 5980 return true;
5891 } else { 5981 } else {
5892 // RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_EXTENDS or 5982 // RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_EXTENDS or
5893 // RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_IMPLEMENTS or 5983 // RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_IMPLEMENTS or
5894 // RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_WITH 5984 // RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_WITH
5895 _errorReporter.reportErrorForOffset(_getBaseCaseErrorCode(element), 5985 _errorReporter.reportErrorForOffset(
5896 _enclosingClass.nameOffset, enclosingClassName.length, 5986 _getBaseCaseErrorCode(element),
5987 _enclosingClass.nameOffset,
5988 enclosingClassName.length,
5897 [enclosingClassName]); 5989 [enclosingClassName]);
5898 return true; 5990 return true;
5899 } 5991 }
5900 } 5992 }
5901 if (path.indexOf(element) > 0) { 5993 if (path.indexOf(element) > 0) {
5902 return false; 5994 return false;
5903 } 5995 }
5904 path.add(element); 5996 path.add(element);
5905 // n-case 5997 // n-case
5906 InterfaceType supertype = element.supertype; 5998 InterfaceType supertype = element.supertype;
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
5992 toCheck.add(type.element); 6084 toCheck.add(type.element);
5993 // type arguments 6085 // type arguments
5994 if (type is InterfaceType) { 6086 if (type is InterfaceType) {
5995 InterfaceType interfaceType = type; 6087 InterfaceType interfaceType = type;
5996 for (DartType typeArgument in interfaceType.typeArguments) { 6088 for (DartType typeArgument in interfaceType.typeArguments) {
5997 _addTypeToCheck(typeArgument); 6089 _addTypeToCheck(typeArgument);
5998 } 6090 }
5999 } 6091 }
6000 } 6092 }
6001 } 6093 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698