OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library engine.resolver.error_verifier; | 5 library engine.resolver.error_verifier; |
6 | 6 |
7 import 'dart:collection'; | 7 import 'dart:collection'; |
8 import "dart:math" as math; | 8 import "dart:math" as math; |
9 | 9 |
10 import 'package:analyzer/src/generated/static_type_analyzer.dart'; | 10 import 'package:analyzer/src/generated/static_type_analyzer.dart'; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 */ | 259 */ |
255 List<InterfaceType> _DISALLOWED_TYPES_TO_EXTEND_OR_IMPLEMENT; | 260 List<InterfaceType> _DISALLOWED_TYPES_TO_EXTEND_OR_IMPLEMENT; |
256 | 261 |
257 /** | 262 /** |
258 * If `true`, mixins are allowed to inherit from types other than Object, and | 263 * If `true`, mixins are allowed to inherit from types other than Object, and |
259 * are allowed to reference `super`. | 264 * are allowed to reference `super`. |
260 */ | 265 */ |
261 final bool enableSuperMixins; | 266 final bool enableSuperMixins; |
262 | 267 |
263 /** | 268 /** |
| 269 * If `true`, asserts are allowed to take a second argument representing the |
| 270 * assertion failure message (see DEP 37). |
| 271 */ |
| 272 final bool enableAssertMessage; |
| 273 |
| 274 /** |
264 * Initialize a newly created error verifier. | 275 * Initialize a newly created error verifier. |
265 */ | 276 */ |
266 ErrorVerifier(this._errorReporter, this._currentLibrary, this._typeProvider, | 277 ErrorVerifier( |
267 this._inheritanceManager, this.enableSuperMixins) { | 278 this._errorReporter, |
| 279 this._currentLibrary, |
| 280 this._typeProvider, |
| 281 this._inheritanceManager, |
| 282 this.enableSuperMixins, |
| 283 this.enableAssertMessage) { |
268 this._isInSystemLibrary = _currentLibrary.source.isInSystemLibrary; | 284 this._isInSystemLibrary = _currentLibrary.source.isInSystemLibrary; |
269 this._hasExtUri = _currentLibrary.hasExtUri; | 285 this._hasExtUri = _currentLibrary.hasExtUri; |
270 _isEnclosingConstructorConst = false; | 286 _isEnclosingConstructorConst = false; |
271 _isInCatchClause = false; | 287 _isInCatchClause = false; |
272 _isInStaticVariableDeclaration = false; | 288 _isInStaticVariableDeclaration = false; |
273 _isInInstanceVariableDeclaration = false; | 289 _isInInstanceVariableDeclaration = false; |
274 _isInInstanceVariableInitializer = false; | 290 _isInInstanceVariableInitializer = false; |
275 _isInConstructorInitializer = false; | 291 _isInConstructorInitializer = false; |
276 _isInStaticMethod = false; | 292 _isInStaticMethod = false; |
277 _boolType = _typeProvider.boolType; | 293 _boolType = _typeProvider.boolType; |
278 _intType = _typeProvider.intType; | 294 _intType = _typeProvider.intType; |
| 295 _stringType = _typeProvider.stringType; |
279 _DISALLOWED_TYPES_TO_EXTEND_OR_IMPLEMENT = _typeProvider.nonSubtypableTypes; | 296 _DISALLOWED_TYPES_TO_EXTEND_OR_IMPLEMENT = _typeProvider.nonSubtypableTypes; |
280 } | 297 } |
281 | 298 |
282 @override | 299 @override |
283 Object visitAnnotation(Annotation node) { | 300 Object visitAnnotation(Annotation node) { |
284 _checkForInvalidAnnotationFromDeferredLibrary(node); | 301 _checkForInvalidAnnotationFromDeferredLibrary(node); |
285 return super.visitAnnotation(node); | 302 return super.visitAnnotation(node); |
286 } | 303 } |
287 | 304 |
288 @override | 305 @override |
289 Object visitArgumentList(ArgumentList node) { | 306 Object visitArgumentList(ArgumentList node) { |
290 _checkForArgumentTypesNotAssignableInList(node); | 307 _checkForArgumentTypesNotAssignableInList(node); |
291 return super.visitArgumentList(node); | 308 return super.visitArgumentList(node); |
292 } | 309 } |
293 | 310 |
294 @override | 311 @override |
295 Object visitAsExpression(AsExpression node) { | 312 Object visitAsExpression(AsExpression node) { |
296 _checkForTypeAnnotationDeferredClass(node.type); | 313 _checkForTypeAnnotationDeferredClass(node.type); |
297 return super.visitAsExpression(node); | 314 return super.visitAsExpression(node); |
298 } | 315 } |
299 | 316 |
300 @override | 317 @override |
301 Object visitAssertStatement(AssertStatement node) { | 318 Object visitAssertStatement(AssertStatement node) { |
302 _checkForNonBoolExpression(node); | 319 _checkForNonBoolExpression(node); |
| 320 _checkForNonStringMessage(node); |
303 return super.visitAssertStatement(node); | 321 return super.visitAssertStatement(node); |
304 } | 322 } |
305 | 323 |
306 @override | 324 @override |
307 Object visitAssignmentExpression(AssignmentExpression node) { | 325 Object visitAssignmentExpression(AssignmentExpression node) { |
308 sc.TokenType operatorType = node.operator.type; | 326 sc.TokenType operatorType = node.operator.type; |
309 Expression lhs = node.leftHandSide; | 327 Expression lhs = node.leftHandSide; |
310 Expression rhs = node.rightHandSide; | 328 Expression rhs = node.rightHandSide; |
311 if (operatorType == sc.TokenType.EQ || | 329 if (operatorType == sc.TokenType.EQ || |
312 operatorType == sc.TokenType.QUESTION_QUESTION_EQ) { | 330 operatorType == sc.TokenType.QUESTION_QUESTION_EQ) { |
(...skipping 805 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1118 * See [StaticTypeWarningCode.EXPECTED_TWO_MAP_TYPE_ARGUMENTS]. | 1136 * See [StaticTypeWarningCode.EXPECTED_TWO_MAP_TYPE_ARGUMENTS]. |
1119 */ | 1137 */ |
1120 bool _checkExpectedTwoMapTypeArguments(TypeArgumentList typeArguments) { | 1138 bool _checkExpectedTwoMapTypeArguments(TypeArgumentList typeArguments) { |
1121 // check number of type arguments | 1139 // check number of type arguments |
1122 int num = typeArguments.arguments.length; | 1140 int num = typeArguments.arguments.length; |
1123 if (num == 2) { | 1141 if (num == 2) { |
1124 return false; | 1142 return false; |
1125 } | 1143 } |
1126 // report problem | 1144 // report problem |
1127 _errorReporter.reportErrorForNode( | 1145 _errorReporter.reportErrorForNode( |
1128 StaticTypeWarningCode.EXPECTED_TWO_MAP_TYPE_ARGUMENTS, typeArguments, | 1146 StaticTypeWarningCode.EXPECTED_TWO_MAP_TYPE_ARGUMENTS, |
| 1147 typeArguments, |
1129 [num]); | 1148 [num]); |
1130 return true; | 1149 return true; |
1131 } | 1150 } |
1132 | 1151 |
1133 /** | 1152 /** |
1134 * Verify that the given [constructor] declaration does not violate any of the | 1153 * Verify that the given [constructor] declaration does not violate any of the |
1135 * error codes relating to the initialization of fields in the enclosing | 1154 * error codes relating to the initialization of fields in the enclosing |
1136 * class. | 1155 * class. |
1137 * | 1156 * |
1138 * See [_initialFieldElementsMap], | 1157 * See [_initialFieldElementsMap], |
(...skipping 25 matching lines...) Expand all Loading... |
1164 if (parameter is FieldFormalParameter) { | 1183 if (parameter is FieldFormalParameter) { |
1165 FieldElement fieldElement = | 1184 FieldElement fieldElement = |
1166 (parameter.element as FieldFormalParameterElementImpl).field; | 1185 (parameter.element as FieldFormalParameterElementImpl).field; |
1167 INIT_STATE state = fieldElementsMap[fieldElement]; | 1186 INIT_STATE state = fieldElementsMap[fieldElement]; |
1168 if (state == INIT_STATE.NOT_INIT) { | 1187 if (state == INIT_STATE.NOT_INIT) { |
1169 fieldElementsMap[fieldElement] = INIT_STATE.INIT_IN_FIELD_FORMAL; | 1188 fieldElementsMap[fieldElement] = INIT_STATE.INIT_IN_FIELD_FORMAL; |
1170 } else if (state == INIT_STATE.INIT_IN_DECLARATION) { | 1189 } else if (state == INIT_STATE.INIT_IN_DECLARATION) { |
1171 if (fieldElement.isFinal || fieldElement.isConst) { | 1190 if (fieldElement.isFinal || fieldElement.isConst) { |
1172 _errorReporter.reportErrorForNode( | 1191 _errorReporter.reportErrorForNode( |
1173 StaticWarningCode.FINAL_INITIALIZED_IN_DECLARATION_AND_CONSTRUCT
OR, | 1192 StaticWarningCode.FINAL_INITIALIZED_IN_DECLARATION_AND_CONSTRUCT
OR, |
1174 formalParameter.identifier, [fieldElement.displayName]); | 1193 formalParameter.identifier, |
| 1194 [fieldElement.displayName]); |
1175 foundError = true; | 1195 foundError = true; |
1176 } | 1196 } |
1177 } else if (state == INIT_STATE.INIT_IN_FIELD_FORMAL) { | 1197 } else if (state == INIT_STATE.INIT_IN_FIELD_FORMAL) { |
1178 if (fieldElement.isFinal || fieldElement.isConst) { | 1198 if (fieldElement.isFinal || fieldElement.isConst) { |
1179 _errorReporter.reportErrorForNode( | 1199 _errorReporter.reportErrorForNode( |
1180 CompileTimeErrorCode.FINAL_INITIALIZED_MULTIPLE_TIMES, | 1200 CompileTimeErrorCode.FINAL_INITIALIZED_MULTIPLE_TIMES, |
1181 formalParameter.identifier, [fieldElement.displayName]); | 1201 formalParameter.identifier, |
| 1202 [fieldElement.displayName]); |
1182 foundError = true; | 1203 foundError = true; |
1183 } | 1204 } |
1184 } | 1205 } |
1185 } | 1206 } |
1186 } | 1207 } |
1187 // Visit all of the initializers | 1208 // Visit all of the initializers |
1188 NodeList<ConstructorInitializer> initializers = constructor.initializers; | 1209 NodeList<ConstructorInitializer> initializers = constructor.initializers; |
1189 for (ConstructorInitializer constructorInitializer in initializers) { | 1210 for (ConstructorInitializer constructorInitializer in initializers) { |
1190 if (constructorInitializer is RedirectingConstructorInvocation) { | 1211 if (constructorInitializer is RedirectingConstructorInvocation) { |
1191 return false; | 1212 return false; |
(...skipping 16 matching lines...) Expand all Loading... |
1208 foundError = true; | 1229 foundError = true; |
1209 } | 1230 } |
1210 } else if (state == INIT_STATE.INIT_IN_FIELD_FORMAL) { | 1231 } else if (state == INIT_STATE.INIT_IN_FIELD_FORMAL) { |
1211 _errorReporter.reportErrorForNode( | 1232 _errorReporter.reportErrorForNode( |
1212 CompileTimeErrorCode.FIELD_INITIALIZED_IN_PARAMETER_AND_INITIALI
ZER, | 1233 CompileTimeErrorCode.FIELD_INITIALIZED_IN_PARAMETER_AND_INITIALI
ZER, |
1213 fieldName); | 1234 fieldName); |
1214 foundError = true; | 1235 foundError = true; |
1215 } else if (state == INIT_STATE.INIT_IN_INITIALIZERS) { | 1236 } else if (state == INIT_STATE.INIT_IN_INITIALIZERS) { |
1216 _errorReporter.reportErrorForNode( | 1237 _errorReporter.reportErrorForNode( |
1217 CompileTimeErrorCode.FIELD_INITIALIZED_BY_MULTIPLE_INITIALIZERS, | 1238 CompileTimeErrorCode.FIELD_INITIALIZED_BY_MULTIPLE_INITIALIZERS, |
1218 fieldName, [fieldElement.displayName]); | 1239 fieldName, |
| 1240 [fieldElement.displayName]); |
1219 foundError = true; | 1241 foundError = true; |
1220 } | 1242 } |
1221 } | 1243 } |
1222 } | 1244 } |
1223 } | 1245 } |
1224 // Prepare a list of not initialized fields. | 1246 // Prepare a list of not initialized fields. |
1225 List<FieldElement> notInitFinalFields = <FieldElement>[]; | 1247 List<FieldElement> notInitFinalFields = <FieldElement>[]; |
1226 fieldElementsMap.forEach((FieldElement fieldElement, INIT_STATE state) { | 1248 fieldElementsMap.forEach((FieldElement fieldElement, INIT_STATE state) { |
1227 if (state == INIT_STATE.NOT_INIT) { | 1249 if (state == INIT_STATE.NOT_INIT) { |
1228 if (fieldElement.isFinal) { | 1250 if (fieldElement.isFinal) { |
1229 notInitFinalFields.add(fieldElement); | 1251 notInitFinalFields.add(fieldElement); |
1230 } | 1252 } |
1231 } | 1253 } |
1232 }); | 1254 }); |
1233 // Visit all of the states in the map to ensure that none were never | 1255 // Visit all of the states in the map to ensure that none were never |
1234 // initialized. | 1256 // initialized. |
1235 fieldElementsMap.forEach((FieldElement fieldElement, INIT_STATE state) { | 1257 fieldElementsMap.forEach((FieldElement fieldElement, INIT_STATE state) { |
1236 if (state == INIT_STATE.NOT_INIT) { | 1258 if (state == INIT_STATE.NOT_INIT) { |
1237 if (fieldElement.isConst) { | 1259 if (fieldElement.isConst) { |
1238 _errorReporter.reportErrorForNode( | 1260 _errorReporter.reportErrorForNode( |
1239 CompileTimeErrorCode.CONST_NOT_INITIALIZED, | 1261 CompileTimeErrorCode.CONST_NOT_INITIALIZED, |
1240 constructor.returnType, [fieldElement.name]); | 1262 constructor.returnType, |
| 1263 [fieldElement.name]); |
1241 foundError = true; | 1264 foundError = true; |
1242 } | 1265 } |
1243 } | 1266 } |
1244 }); | 1267 }); |
1245 if (notInitFinalFields.isNotEmpty) { | 1268 if (notInitFinalFields.isNotEmpty) { |
1246 foundError = true; | 1269 foundError = true; |
1247 AnalysisErrorWithProperties analysisError; | 1270 AnalysisErrorWithProperties analysisError; |
1248 if (notInitFinalFields.length == 1) { | 1271 if (notInitFinalFields.length == 1) { |
1249 analysisError = _errorReporter.newErrorWithProperties( | 1272 analysisError = _errorReporter.newErrorWithProperties( |
1250 StaticWarningCode.FINAL_NOT_INITIALIZED_CONSTRUCTOR_1, | 1273 StaticWarningCode.FINAL_NOT_INITIALIZED_CONSTRUCTOR_1, |
1251 constructor.returnType, [notInitFinalFields[0].name]); | 1274 constructor.returnType, |
| 1275 [notInitFinalFields[0].name]); |
1252 } else if (notInitFinalFields.length == 2) { | 1276 } else if (notInitFinalFields.length == 2) { |
1253 analysisError = _errorReporter.newErrorWithProperties( | 1277 analysisError = _errorReporter.newErrorWithProperties( |
1254 StaticWarningCode.FINAL_NOT_INITIALIZED_CONSTRUCTOR_2, | 1278 StaticWarningCode.FINAL_NOT_INITIALIZED_CONSTRUCTOR_2, |
1255 constructor.returnType, [ | 1279 constructor.returnType, |
1256 notInitFinalFields[0].name, | 1280 [notInitFinalFields[0].name, notInitFinalFields[1].name]); |
1257 notInitFinalFields[1].name | |
1258 ]); | |
1259 } else { | 1281 } else { |
1260 analysisError = _errorReporter.newErrorWithProperties( | 1282 analysisError = _errorReporter.newErrorWithProperties( |
1261 StaticWarningCode.FINAL_NOT_INITIALIZED_CONSTRUCTOR_3_PLUS, | 1283 StaticWarningCode.FINAL_NOT_INITIALIZED_CONSTRUCTOR_3_PLUS, |
1262 constructor.returnType, [ | 1284 constructor.returnType, [ |
1263 notInitFinalFields[0].name, | 1285 notInitFinalFields[0].name, |
1264 notInitFinalFields[1].name, | 1286 notInitFinalFields[1].name, |
1265 notInitFinalFields.length - 2 | 1287 notInitFinalFields.length - 2 |
1266 ]); | 1288 ]); |
1267 } | 1289 } |
1268 analysisError.setProperty( | 1290 analysisError.setProperty( |
(...skipping 16 matching lines...) Expand all Loading... |
1285 * [StaticWarningCode.INVALID_GETTER_OVERRIDE_RETURN_TYPE], | 1307 * [StaticWarningCode.INVALID_GETTER_OVERRIDE_RETURN_TYPE], |
1286 * [StaticWarningCode.INVALID_METHOD_OVERRIDE_RETURN_TYPE], | 1308 * [StaticWarningCode.INVALID_METHOD_OVERRIDE_RETURN_TYPE], |
1287 * [StaticWarningCode.INVALID_METHOD_OVERRIDE_NORMAL_PARAM_TYPE], | 1309 * [StaticWarningCode.INVALID_METHOD_OVERRIDE_NORMAL_PARAM_TYPE], |
1288 * [StaticWarningCode.INVALID_SETTER_OVERRIDE_NORMAL_PARAM_TYPE], | 1310 * [StaticWarningCode.INVALID_SETTER_OVERRIDE_NORMAL_PARAM_TYPE], |
1289 * [StaticWarningCode.INVALID_METHOD_OVERRIDE_OPTIONAL_PARAM_TYPE], | 1311 * [StaticWarningCode.INVALID_METHOD_OVERRIDE_OPTIONAL_PARAM_TYPE], |
1290 * [StaticWarningCode.INVALID_METHOD_OVERRIDE_NAMED_PARAM_TYPE], and | 1312 * [StaticWarningCode.INVALID_METHOD_OVERRIDE_NAMED_PARAM_TYPE], and |
1291 * [StaticWarningCode.INVALID_OVERRIDE_DIFFERENT_DEFAULT_VALUES]. | 1313 * [StaticWarningCode.INVALID_OVERRIDE_DIFFERENT_DEFAULT_VALUES]. |
1292 */ | 1314 */ |
1293 bool _checkForAllInvalidOverrideErrorCodes( | 1315 bool _checkForAllInvalidOverrideErrorCodes( |
1294 ExecutableElement executableElement, | 1316 ExecutableElement executableElement, |
1295 ExecutableElement overriddenExecutable, List<ParameterElement> parameters, | 1317 ExecutableElement overriddenExecutable, |
1296 List<AstNode> parameterLocations, SimpleIdentifier errorNameTarget) { | 1318 List<ParameterElement> parameters, |
| 1319 List<AstNode> parameterLocations, |
| 1320 SimpleIdentifier errorNameTarget) { |
1297 bool isGetter = false; | 1321 bool isGetter = false; |
1298 bool isSetter = false; | 1322 bool isSetter = false; |
1299 if (executableElement is PropertyAccessorElement) { | 1323 if (executableElement is PropertyAccessorElement) { |
1300 PropertyAccessorElement accessorElement = executableElement; | 1324 PropertyAccessorElement accessorElement = executableElement; |
1301 isGetter = accessorElement.isGetter; | 1325 isGetter = accessorElement.isGetter; |
1302 isSetter = accessorElement.isSetter; | 1326 isSetter = accessorElement.isSetter; |
1303 } | 1327 } |
1304 String executableElementName = executableElement.name; | 1328 String executableElementName = executableElement.name; |
1305 FunctionType overridingFT = executableElement.type; | 1329 FunctionType overridingFT = executableElement.type; |
1306 FunctionType overriddenFT = overriddenExecutable.type; | 1330 FunctionType overriddenFT = overriddenExecutable.type; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1348 StaticWarningCode.INVALID_OVERRIDE_NAMED, errorNameTarget, [ | 1372 StaticWarningCode.INVALID_OVERRIDE_NAMED, errorNameTarget, [ |
1349 overriddenParamName, | 1373 overriddenParamName, |
1350 overriddenExecutable.enclosingElement.displayName | 1374 overriddenExecutable.enclosingElement.displayName |
1351 ]); | 1375 ]); |
1352 return true; | 1376 return true; |
1353 } | 1377 } |
1354 } | 1378 } |
1355 // SWC.INVALID_METHOD_OVERRIDE_RETURN_TYPE | 1379 // SWC.INVALID_METHOD_OVERRIDE_RETURN_TYPE |
1356 if (overriddenFTReturnType != VoidTypeImpl.instance && | 1380 if (overriddenFTReturnType != VoidTypeImpl.instance && |
1357 !overridingFTReturnType.isAssignableTo(overriddenFTReturnType)) { | 1381 !overridingFTReturnType.isAssignableTo(overriddenFTReturnType)) { |
1358 _errorReporter.reportTypeErrorForNode(!isGetter | 1382 _errorReporter.reportTypeErrorForNode( |
| 1383 !isGetter |
1359 ? StaticWarningCode.INVALID_METHOD_OVERRIDE_RETURN_TYPE | 1384 ? StaticWarningCode.INVALID_METHOD_OVERRIDE_RETURN_TYPE |
1360 : StaticWarningCode.INVALID_GETTER_OVERRIDE_RETURN_TYPE, | 1385 : StaticWarningCode.INVALID_GETTER_OVERRIDE_RETURN_TYPE, |
1361 errorNameTarget, [ | 1386 errorNameTarget, |
| 1387 [ |
1362 overridingFTReturnType, | 1388 overridingFTReturnType, |
1363 overriddenFTReturnType, | 1389 overriddenFTReturnType, |
1364 overriddenExecutable.enclosingElement.displayName | 1390 overriddenExecutable.enclosingElement.displayName |
1365 ]); | 1391 ]); |
1366 return true; | 1392 return true; |
1367 } | 1393 } |
1368 // SWC.INVALID_METHOD_OVERRIDE_NORMAL_PARAM_TYPE | 1394 // SWC.INVALID_METHOD_OVERRIDE_NORMAL_PARAM_TYPE |
1369 if (parameterLocations == null) { | 1395 if (parameterLocations == null) { |
1370 return false; | 1396 return false; |
1371 } | 1397 } |
1372 int parameterIndex = 0; | 1398 int parameterIndex = 0; |
1373 for (int i = 0; i < overridingNormalPT.length; i++) { | 1399 for (int i = 0; i < overridingNormalPT.length; i++) { |
1374 if (!overridingNormalPT[i].isAssignableTo(overriddenNormalPT[i])) { | 1400 if (!overridingNormalPT[i].isAssignableTo(overriddenNormalPT[i])) { |
1375 _errorReporter.reportTypeErrorForNode(!isSetter | 1401 _errorReporter.reportTypeErrorForNode( |
| 1402 !isSetter |
1376 ? StaticWarningCode.INVALID_METHOD_OVERRIDE_NORMAL_PARAM_TYPE | 1403 ? StaticWarningCode.INVALID_METHOD_OVERRIDE_NORMAL_PARAM_TYPE |
1377 : StaticWarningCode.INVALID_SETTER_OVERRIDE_NORMAL_PARAM_TYPE, | 1404 : StaticWarningCode.INVALID_SETTER_OVERRIDE_NORMAL_PARAM_TYPE, |
1378 parameterLocations[parameterIndex], [ | 1405 parameterLocations[parameterIndex], |
| 1406 [ |
1379 overridingNormalPT[i], | 1407 overridingNormalPT[i], |
1380 overriddenNormalPT[i], | 1408 overriddenNormalPT[i], |
1381 overriddenExecutable.enclosingElement.displayName | 1409 overriddenExecutable.enclosingElement.displayName |
1382 ]); | 1410 ]); |
1383 return true; | 1411 return true; |
1384 } | 1412 } |
1385 parameterIndex++; | 1413 parameterIndex++; |
1386 } | 1414 } |
1387 // SWC.INVALID_METHOD_OVERRIDE_OPTIONAL_PARAM_TYPE | 1415 // SWC.INVALID_METHOD_OVERRIDE_OPTIONAL_PARAM_TYPE |
1388 for (int i = 0; i < overriddenPositionalPT.length; i++) { | 1416 for (int i = 0; i < overriddenPositionalPT.length; i++) { |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1548 /** | 1576 /** |
1549 * Check the given [executableElement] against override-error codes. This | 1577 * Check the given [executableElement] against override-error codes. This |
1550 * method computes the given executableElement is overriding and calls | 1578 * method computes the given executableElement is overriding and calls |
1551 * [_checkForAllInvalidOverrideErrorCodes] when the [InheritanceManager] | 1579 * [_checkForAllInvalidOverrideErrorCodes] when the [InheritanceManager] |
1552 * returns a [MultiplyInheritedExecutableElement], this method loops through | 1580 * returns a [MultiplyInheritedExecutableElement], this method loops through |
1553 * the list in the [MultiplyInheritedExecutableElement]. The [parameters] are | 1581 * the list in the [MultiplyInheritedExecutableElement]. The [parameters] are |
1554 * the parameters of the executable element. The [errorNameTarget] is the node | 1582 * the parameters of the executable element. The [errorNameTarget] is the node |
1555 * to report problems on. | 1583 * to report problems on. |
1556 */ | 1584 */ |
1557 bool _checkForAllInvalidOverrideErrorCodesForExecutable( | 1585 bool _checkForAllInvalidOverrideErrorCodesForExecutable( |
1558 ExecutableElement executableElement, List<ParameterElement> parameters, | 1586 ExecutableElement executableElement, |
1559 List<AstNode> parameterLocations, SimpleIdentifier errorNameTarget) { | 1587 List<ParameterElement> parameters, |
| 1588 List<AstNode> parameterLocations, |
| 1589 SimpleIdentifier errorNameTarget) { |
1560 // | 1590 // |
1561 // Compute the overridden executable from the InheritanceManager | 1591 // Compute the overridden executable from the InheritanceManager |
1562 // | 1592 // |
1563 List<ExecutableElement> overriddenExecutables = _inheritanceManager | 1593 List<ExecutableElement> overriddenExecutables = _inheritanceManager |
1564 .lookupOverrides(_enclosingClass, executableElement.name); | 1594 .lookupOverrides(_enclosingClass, executableElement.name); |
1565 if (_checkForInstanceMethodNameCollidesWithSuperclassStatic( | 1595 if (_checkForInstanceMethodNameCollidesWithSuperclassStatic( |
1566 executableElement, errorNameTarget)) { | 1596 executableElement, errorNameTarget)) { |
1567 return true; | 1597 return true; |
1568 } | 1598 } |
1569 for (ExecutableElement overriddenElement in overriddenExecutables) { | 1599 for (ExecutableElement overriddenElement in overriddenExecutables) { |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1714 // | 1744 // |
1715 // Prepare the constructor name | 1745 // Prepare the constructor name |
1716 // | 1746 // |
1717 String constructorStrName = constructorTypeName.name.name; | 1747 String constructorStrName = constructorTypeName.name.name; |
1718 if (redirectedConstructor.name != null) { | 1748 if (redirectedConstructor.name != null) { |
1719 constructorStrName += ".${redirectedConstructor.name.name}"; | 1749 constructorStrName += ".${redirectedConstructor.name.name}"; |
1720 } | 1750 } |
1721 ErrorCode errorCode = (declaration.constKeyword != null | 1751 ErrorCode errorCode = (declaration.constKeyword != null |
1722 ? CompileTimeErrorCode.REDIRECT_TO_MISSING_CONSTRUCTOR | 1752 ? CompileTimeErrorCode.REDIRECT_TO_MISSING_CONSTRUCTOR |
1723 : StaticWarningCode.REDIRECT_TO_MISSING_CONSTRUCTOR); | 1753 : StaticWarningCode.REDIRECT_TO_MISSING_CONSTRUCTOR); |
1724 _errorReporter.reportErrorForNode(errorCode, redirectedConstructor, [ | 1754 _errorReporter.reportErrorForNode(errorCode, redirectedConstructor, |
1725 constructorStrName, | 1755 [constructorStrName, redirectedType.displayName]); |
1726 redirectedType.displayName | |
1727 ]); | |
1728 return true; | 1756 return true; |
1729 } | 1757 } |
1730 return false; | 1758 return false; |
1731 } | 1759 } |
1732 FunctionType redirectedType = redirectedElement.type; | 1760 FunctionType redirectedType = redirectedElement.type; |
1733 DartType redirectedReturnType = redirectedType.returnType; | 1761 DartType redirectedReturnType = redirectedType.returnType; |
1734 // | 1762 // |
1735 // Report specific problem when return type is incompatible | 1763 // Report specific problem when return type is incompatible |
1736 // | 1764 // |
1737 FunctionType constructorType = declaration.element.type; | 1765 FunctionType constructorType = declaration.element.type; |
1738 DartType constructorReturnType = constructorType.returnType; | 1766 DartType constructorReturnType = constructorType.returnType; |
1739 if (!redirectedReturnType.isAssignableTo(constructorReturnType)) { | 1767 if (!redirectedReturnType.isAssignableTo(constructorReturnType)) { |
1740 _errorReporter.reportErrorForNode( | 1768 _errorReporter.reportErrorForNode( |
1741 StaticWarningCode.REDIRECT_TO_INVALID_RETURN_TYPE, | 1769 StaticWarningCode.REDIRECT_TO_INVALID_RETURN_TYPE, |
1742 redirectedConstructor, [redirectedReturnType, constructorReturnType]); | 1770 redirectedConstructor, |
| 1771 [redirectedReturnType, constructorReturnType]); |
1743 return true; | 1772 return true; |
1744 } | 1773 } |
1745 // | 1774 // |
1746 // Check parameters | 1775 // Check parameters |
1747 // | 1776 // |
1748 if (!redirectedType.isSubtypeOf(constructorType)) { | 1777 if (!redirectedType.isSubtypeOf(constructorType)) { |
1749 _errorReporter.reportErrorForNode( | 1778 _errorReporter.reportErrorForNode( |
1750 StaticWarningCode.REDIRECT_TO_INVALID_FUNCTION_TYPE, | 1779 StaticWarningCode.REDIRECT_TO_INVALID_FUNCTION_TYPE, |
1751 redirectedConstructor, [redirectedType, constructorType]); | 1780 redirectedConstructor, |
| 1781 [redirectedType, constructorType]); |
1752 return true; | 1782 return true; |
1753 } | 1783 } |
1754 return false; | 1784 return false; |
1755 } | 1785 } |
1756 | 1786 |
1757 /** | 1787 /** |
1758 * Check that the return [statement] of the form <i>return e;</i> is not in a | 1788 * Check that the return [statement] of the form <i>return e;</i> is not in a |
1759 * generative constructor. | 1789 * generative constructor. |
1760 * | 1790 * |
1761 * Check that return statements without expressions are not in a generative | 1791 * Check that return statements without expressions are not in a generative |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1823 return false; | 1853 return false; |
1824 } | 1854 } |
1825 // check exported names | 1855 // check exported names |
1826 Namespace namespace = | 1856 Namespace namespace = |
1827 new NamespaceBuilder().createExportNamespaceForDirective(exportElement); | 1857 new NamespaceBuilder().createExportNamespaceForDirective(exportElement); |
1828 Map<String, Element> definedNames = namespace.definedNames; | 1858 Map<String, Element> definedNames = namespace.definedNames; |
1829 for (String name in definedNames.keys) { | 1859 for (String name in definedNames.keys) { |
1830 Element element = definedNames[name]; | 1860 Element element = definedNames[name]; |
1831 Element prevElement = _exportedElements[name]; | 1861 Element prevElement = _exportedElements[name]; |
1832 if (element != null && prevElement != null && prevElement != element) { | 1862 if (element != null && prevElement != null && prevElement != element) { |
1833 _errorReporter.reportErrorForNode(CompileTimeErrorCode.AMBIGUOUS_EXPORT, | 1863 _errorReporter.reportErrorForNode( |
1834 directive, [ | 1864 CompileTimeErrorCode.AMBIGUOUS_EXPORT, directive, [ |
1835 name, | 1865 name, |
1836 prevElement.library.definingCompilationUnit.displayName, | 1866 prevElement.library.definingCompilationUnit.displayName, |
1837 element.library.definingCompilationUnit.displayName | 1867 element.library.definingCompilationUnit.displayName |
1838 ]); | 1868 ]); |
1839 return true; | 1869 return true; |
1840 } else { | 1870 } else { |
1841 _exportedElements[name] = element; | 1871 _exportedElements[name] = element; |
1842 } | 1872 } |
1843 } | 1873 } |
1844 return false; | 1874 return false; |
1845 } | 1875 } |
1846 | 1876 |
1847 /** | 1877 /** |
1848 * Verify that the given [expression] can be assigned to its corresponding | 1878 * Verify that the given [expression] can be assigned to its corresponding |
1849 * parameters. The [expectedStaticType] is the expected static type of the | 1879 * parameters. The [expectedStaticType] is the expected static type of the |
1850 * parameter. The [actualStaticType] is the actual static type of the | 1880 * parameter. The [actualStaticType] is the actual static type of the |
1851 * argument. | 1881 * argument. |
1852 * | 1882 * |
1853 * This method corresponds to | 1883 * This method corresponds to |
1854 * [BestPracticesVerifier.checkForArgumentTypeNotAssignable]. | 1884 * [BestPracticesVerifier.checkForArgumentTypeNotAssignable]. |
1855 * | 1885 * |
1856 * See [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE], | 1886 * See [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE], |
1857 * [CompileTimeErrorCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE], | 1887 * [CompileTimeErrorCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE], |
1858 * [StaticWarningCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE], | 1888 * [StaticWarningCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE], |
1859 * [CompileTimeErrorCode.MAP_KEY_TYPE_NOT_ASSIGNABLE], | 1889 * [CompileTimeErrorCode.MAP_KEY_TYPE_NOT_ASSIGNABLE], |
1860 * [CompileTimeErrorCode.MAP_VALUE_TYPE_NOT_ASSIGNABLE], | 1890 * [CompileTimeErrorCode.MAP_VALUE_TYPE_NOT_ASSIGNABLE], |
1861 * [StaticWarningCode.MAP_KEY_TYPE_NOT_ASSIGNABLE], and | 1891 * [StaticWarningCode.MAP_KEY_TYPE_NOT_ASSIGNABLE], and |
1862 * [StaticWarningCode.MAP_VALUE_TYPE_NOT_ASSIGNABLE]. | 1892 * [StaticWarningCode.MAP_VALUE_TYPE_NOT_ASSIGNABLE]. |
1863 */ | 1893 */ |
1864 bool _checkForArgumentTypeNotAssignable(Expression expression, | 1894 bool _checkForArgumentTypeNotAssignable( |
1865 DartType expectedStaticType, DartType actualStaticType, | 1895 Expression expression, |
| 1896 DartType expectedStaticType, |
| 1897 DartType actualStaticType, |
1866 ErrorCode errorCode) { | 1898 ErrorCode errorCode) { |
1867 // | 1899 // |
1868 // Warning case: test static type information | 1900 // Warning case: test static type information |
1869 // | 1901 // |
1870 if (actualStaticType != null && expectedStaticType != null) { | 1902 if (actualStaticType != null && expectedStaticType != null) { |
1871 if (!actualStaticType.isAssignableTo(expectedStaticType)) { | 1903 if (!actualStaticType.isAssignableTo(expectedStaticType)) { |
1872 _errorReporter.reportTypeErrorForNode( | 1904 _errorReporter.reportTypeErrorForNode( |
1873 errorCode, expression, [actualStaticType, expectedStaticType]); | 1905 errorCode, expression, [actualStaticType, expectedStaticType]); |
1874 return true; | 1906 return true; |
1875 } | 1907 } |
(...skipping 30 matching lines...) Expand all Loading... |
1906 * | 1938 * |
1907 * See [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE], | 1939 * See [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE], |
1908 * [CompileTimeErrorCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE], | 1940 * [CompileTimeErrorCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE], |
1909 * [StaticWarningCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE], | 1941 * [StaticWarningCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE], |
1910 * [CompileTimeErrorCode.MAP_KEY_TYPE_NOT_ASSIGNABLE], | 1942 * [CompileTimeErrorCode.MAP_KEY_TYPE_NOT_ASSIGNABLE], |
1911 * [CompileTimeErrorCode.MAP_VALUE_TYPE_NOT_ASSIGNABLE], | 1943 * [CompileTimeErrorCode.MAP_VALUE_TYPE_NOT_ASSIGNABLE], |
1912 * [StaticWarningCode.MAP_KEY_TYPE_NOT_ASSIGNABLE], and | 1944 * [StaticWarningCode.MAP_KEY_TYPE_NOT_ASSIGNABLE], and |
1913 * [StaticWarningCode.MAP_VALUE_TYPE_NOT_ASSIGNABLE]. | 1945 * [StaticWarningCode.MAP_VALUE_TYPE_NOT_ASSIGNABLE]. |
1914 */ | 1946 */ |
1915 bool _checkForArgumentTypeNotAssignableWithExpectedTypes( | 1947 bool _checkForArgumentTypeNotAssignableWithExpectedTypes( |
1916 Expression expression, DartType expectedStaticType, | 1948 Expression expression, |
1917 ErrorCode errorCode) => _checkForArgumentTypeNotAssignable( | 1949 DartType expectedStaticType, |
| 1950 ErrorCode errorCode) => |
| 1951 _checkForArgumentTypeNotAssignable( |
1918 expression, expectedStaticType, getStaticType(expression), errorCode); | 1952 expression, expectedStaticType, getStaticType(expression), errorCode); |
1919 | 1953 |
1920 /** | 1954 /** |
1921 * Verify that the arguments in the given [argumentList] can be assigned to | 1955 * Verify that the arguments in the given [argumentList] can be assigned to |
1922 * their corresponding parameters. | 1956 * their corresponding parameters. |
1923 * | 1957 * |
1924 * This method corresponds to | 1958 * This method corresponds to |
1925 * [BestPracticesVerifier.checkForArgumentTypesNotAssignableInList]. | 1959 * [BestPracticesVerifier.checkForArgumentTypesNotAssignableInList]. |
1926 * | 1960 * |
1927 * See [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]. | 1961 * See [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]. |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1992 if (element.isConst) { | 2026 if (element.isConst) { |
1993 _errorReporter.reportErrorForNode( | 2027 _errorReporter.reportErrorForNode( |
1994 StaticWarningCode.ASSIGNMENT_TO_CONST, expression); | 2028 StaticWarningCode.ASSIGNMENT_TO_CONST, expression); |
1995 return true; | 2029 return true; |
1996 } | 2030 } |
1997 if (element.isFinal) { | 2031 if (element.isFinal) { |
1998 if (element is FieldElementImpl && | 2032 if (element is FieldElementImpl && |
1999 element.setter == null && | 2033 element.setter == null && |
2000 element.isSynthetic) { | 2034 element.isSynthetic) { |
2001 _errorReporter.reportErrorForNode( | 2035 _errorReporter.reportErrorForNode( |
2002 StaticWarningCode.ASSIGNMENT_TO_FINAL_NO_SETTER, highlightedNode, | 2036 StaticWarningCode.ASSIGNMENT_TO_FINAL_NO_SETTER, |
| 2037 highlightedNode, |
2003 [element.name, element.enclosingElement.displayName]); | 2038 [element.name, element.enclosingElement.displayName]); |
2004 return true; | 2039 return true; |
2005 } | 2040 } |
2006 _errorReporter.reportErrorForNode(StaticWarningCode.ASSIGNMENT_TO_FINAL, | 2041 _errorReporter.reportErrorForNode(StaticWarningCode.ASSIGNMENT_TO_FINAL, |
2007 highlightedNode, [element.name]); | 2042 highlightedNode, [element.name]); |
2008 return true; | 2043 return true; |
2009 } | 2044 } |
2010 return false; | 2045 return false; |
2011 } | 2046 } |
2012 if (element is FunctionElement) { | 2047 if (element is FunctionElement) { |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2127 memberName, _currentLibrary); | 2162 memberName, _currentLibrary); |
2128 } else if (method.isSetter) { | 2163 } else if (method.isSetter) { |
2129 overriddenMember = _enclosingClass.lookUpInheritedConcreteSetter( | 2164 overriddenMember = _enclosingClass.lookUpInheritedConcreteSetter( |
2130 memberName, _currentLibrary); | 2165 memberName, _currentLibrary); |
2131 } else { | 2166 } else { |
2132 overriddenMember = _enclosingClass.lookUpInheritedConcreteMethod( | 2167 overriddenMember = _enclosingClass.lookUpInheritedConcreteMethod( |
2133 memberName, _currentLibrary); | 2168 memberName, _currentLibrary); |
2134 } | 2169 } |
2135 if (overriddenMember == null) { | 2170 if (overriddenMember == null) { |
2136 _errorReporter.reportErrorForNode( | 2171 _errorReporter.reportErrorForNode( |
2137 StaticWarningCode.CONCRETE_CLASS_WITH_ABSTRACT_MEMBER, nameNode, [ | 2172 StaticWarningCode.CONCRETE_CLASS_WITH_ABSTRACT_MEMBER, |
2138 memberName, | 2173 nameNode, |
2139 _enclosingClass.displayName | 2174 [memberName, _enclosingClass.displayName]); |
2140 ]); | |
2141 return true; | 2175 return true; |
2142 } | 2176 } |
2143 } | 2177 } |
2144 return false; | 2178 return false; |
2145 } | 2179 } |
2146 | 2180 |
2147 /** | 2181 /** |
2148 * Verify all possible conflicts of the given [constructor]'s name with other | 2182 * Verify all possible conflicts of the given [constructor]'s name with other |
2149 * constructors and members of the same class. The [constructorElement] is the | 2183 * constructors and members of the same class. The [constructorElement] is the |
2150 * constructor's element. | 2184 * constructor's element. |
(...skipping 14 matching lines...) Expand all Loading... |
2165 for (ConstructorElement otherConstructor in constructors) { | 2199 for (ConstructorElement otherConstructor in constructors) { |
2166 if (identical(otherConstructor, constructorElement)) { | 2200 if (identical(otherConstructor, constructorElement)) { |
2167 continue; | 2201 continue; |
2168 } | 2202 } |
2169 if (name == otherConstructor.name) { | 2203 if (name == otherConstructor.name) { |
2170 if (name == null || name.length == 0) { | 2204 if (name == null || name.length == 0) { |
2171 _errorReporter.reportErrorForNode( | 2205 _errorReporter.reportErrorForNode( |
2172 CompileTimeErrorCode.DUPLICATE_CONSTRUCTOR_DEFAULT, constructor); | 2206 CompileTimeErrorCode.DUPLICATE_CONSTRUCTOR_DEFAULT, constructor); |
2173 } else { | 2207 } else { |
2174 _errorReporter.reportErrorForNode( | 2208 _errorReporter.reportErrorForNode( |
2175 CompileTimeErrorCode.DUPLICATE_CONSTRUCTOR_NAME, constructor, | 2209 CompileTimeErrorCode.DUPLICATE_CONSTRUCTOR_NAME, |
| 2210 constructor, |
2176 [name]); | 2211 [name]); |
2177 } | 2212 } |
2178 return true; | 2213 return true; |
2179 } | 2214 } |
2180 } | 2215 } |
2181 // conflict with class member | 2216 // conflict with class member |
2182 if (constructorName != null && | 2217 if (constructorName != null && |
2183 constructorElement != null && | 2218 constructorElement != null && |
2184 !constructorName.isSynthetic) { | 2219 !constructorName.isSynthetic) { |
2185 // fields | 2220 // fields |
2186 FieldElement field = classElement.getField(name); | 2221 FieldElement field = classElement.getField(name); |
2187 if (field != null) { | 2222 if (field != null) { |
2188 _errorReporter.reportErrorForNode( | 2223 _errorReporter.reportErrorForNode( |
2189 CompileTimeErrorCode.CONFLICTING_CONSTRUCTOR_NAME_AND_FIELD, | 2224 CompileTimeErrorCode.CONFLICTING_CONSTRUCTOR_NAME_AND_FIELD, |
2190 constructor, [name]); | 2225 constructor, |
| 2226 [name]); |
2191 return true; | 2227 return true; |
2192 } | 2228 } |
2193 // methods | 2229 // methods |
2194 MethodElement method = classElement.getMethod(name); | 2230 MethodElement method = classElement.getMethod(name); |
2195 if (method != null) { | 2231 if (method != null) { |
2196 _errorReporter.reportErrorForNode( | 2232 _errorReporter.reportErrorForNode( |
2197 CompileTimeErrorCode.CONFLICTING_CONSTRUCTOR_NAME_AND_METHOD, | 2233 CompileTimeErrorCode.CONFLICTING_CONSTRUCTOR_NAME_AND_METHOD, |
2198 constructor, [name]); | 2234 constructor, |
| 2235 [name]); |
2199 return true; | 2236 return true; |
2200 } | 2237 } |
2201 } | 2238 } |
2202 return false; | 2239 return false; |
2203 } | 2240 } |
2204 | 2241 |
2205 /** | 2242 /** |
2206 * Verify that the [_enclosingClass] does not have a method and getter pair | 2243 * Verify that the [_enclosingClass] does not have a method and getter pair |
2207 * with the same name on, via inheritance. | 2244 * with the same name on, via inheritance. |
2208 * | 2245 * |
(...skipping 10 matching lines...) Expand all Loading... |
2219 String name = method.name; | 2256 String name = method.name; |
2220 // find inherited property accessor (and can be only getter) | 2257 // find inherited property accessor (and can be only getter) |
2221 ExecutableElement inherited = | 2258 ExecutableElement inherited = |
2222 _inheritanceManager.lookupInheritance(_enclosingClass, name); | 2259 _inheritanceManager.lookupInheritance(_enclosingClass, name); |
2223 if (inherited is! PropertyAccessorElement) { | 2260 if (inherited is! PropertyAccessorElement) { |
2224 continue; | 2261 continue; |
2225 } | 2262 } |
2226 // report problem | 2263 // report problem |
2227 hasProblem = true; | 2264 hasProblem = true; |
2228 _errorReporter.reportErrorForOffset( | 2265 _errorReporter.reportErrorForOffset( |
2229 CompileTimeErrorCode.CONFLICTING_GETTER_AND_METHOD, method.nameOffset, | 2266 CompileTimeErrorCode.CONFLICTING_GETTER_AND_METHOD, |
| 2267 method.nameOffset, |
2230 name.length, [ | 2268 name.length, [ |
2231 _enclosingClass.displayName, | 2269 _enclosingClass.displayName, |
2232 inherited.enclosingElement.displayName, | 2270 inherited.enclosingElement.displayName, |
2233 name | 2271 name |
2234 ]); | 2272 ]); |
2235 } | 2273 } |
2236 // getter declared in the enclosing class vs. inherited method | 2274 // getter declared in the enclosing class vs. inherited method |
2237 for (PropertyAccessorElement accessor in _enclosingClass.accessors) { | 2275 for (PropertyAccessorElement accessor in _enclosingClass.accessors) { |
2238 if (!accessor.isGetter) { | 2276 if (!accessor.isGetter) { |
2239 continue; | 2277 continue; |
2240 } | 2278 } |
2241 String name = accessor.name; | 2279 String name = accessor.name; |
2242 // find inherited method | 2280 // find inherited method |
2243 ExecutableElement inherited = | 2281 ExecutableElement inherited = |
2244 _inheritanceManager.lookupInheritance(_enclosingClass, name); | 2282 _inheritanceManager.lookupInheritance(_enclosingClass, name); |
2245 if (inherited is! MethodElement) { | 2283 if (inherited is! MethodElement) { |
2246 continue; | 2284 continue; |
2247 } | 2285 } |
2248 // report problem | 2286 // report problem |
2249 hasProblem = true; | 2287 hasProblem = true; |
2250 _errorReporter.reportErrorForOffset( | 2288 _errorReporter.reportErrorForOffset( |
2251 CompileTimeErrorCode.CONFLICTING_METHOD_AND_GETTER, | 2289 CompileTimeErrorCode.CONFLICTING_METHOD_AND_GETTER, |
2252 accessor.nameOffset, name.length, [ | 2290 accessor.nameOffset, |
| 2291 name.length, [ |
2253 _enclosingClass.displayName, | 2292 _enclosingClass.displayName, |
2254 inherited.enclosingElement.displayName, | 2293 inherited.enclosingElement.displayName, |
2255 name | 2294 name |
2256 ]); | 2295 ]); |
2257 } | 2296 } |
2258 // done | 2297 // done |
2259 return hasProblem; | 2298 return hasProblem; |
2260 } | 2299 } |
2261 | 2300 |
2262 /** | 2301 /** |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2308 } | 2347 } |
2309 // prepare "super" type to report its name | 2348 // prepare "super" type to report its name |
2310 ClassElement superElementClass = | 2349 ClassElement superElementClass = |
2311 superElement.enclosingElement as ClassElement; | 2350 superElement.enclosingElement as ClassElement; |
2312 InterfaceType superElementType = superElementClass.type; | 2351 InterfaceType superElementType = superElementClass.type; |
2313 // report problem | 2352 // report problem |
2314 hasProblem = true; | 2353 hasProblem = true; |
2315 if (getter) { | 2354 if (getter) { |
2316 _errorReporter.reportErrorForElement( | 2355 _errorReporter.reportErrorForElement( |
2317 StaticWarningCode.CONFLICTING_INSTANCE_GETTER_AND_SUPERCLASS_MEMBER, | 2356 StaticWarningCode.CONFLICTING_INSTANCE_GETTER_AND_SUPERCLASS_MEMBER, |
2318 accessor, [superElementType.displayName]); | 2357 accessor, |
| 2358 [superElementType.displayName]); |
2319 } else { | 2359 } else { |
2320 _errorReporter.reportErrorForElement( | 2360 _errorReporter.reportErrorForElement( |
2321 StaticWarningCode.CONFLICTING_INSTANCE_SETTER_AND_SUPERCLASS_MEMBER, | 2361 StaticWarningCode.CONFLICTING_INSTANCE_SETTER_AND_SUPERCLASS_MEMBER, |
2322 accessor, [superElementType.displayName]); | 2362 accessor, |
| 2363 [superElementType.displayName]); |
2323 } | 2364 } |
2324 } | 2365 } |
2325 // done | 2366 // done |
2326 return hasProblem; | 2367 return hasProblem; |
2327 } | 2368 } |
2328 | 2369 |
2329 /** | 2370 /** |
2330 * Verify that the enclosing class does not have a setter with the same name | 2371 * Verify that the enclosing class does not have a setter with the same name |
2331 * as the given instance method declaration. | 2372 * as the given instance method declaration. |
2332 * | 2373 * |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2394 addThisMemberToTheMap = false; | 2435 addThisMemberToTheMap = false; |
2395 } | 2436 } |
2396 } else if (isSetter) { | 2437 } else if (isSetter) { |
2397 String methodName = name.name; | 2438 String methodName = name.name; |
2398 ClassMember conflictingMethod = memberHashMap[methodName]; | 2439 ClassMember conflictingMethod = memberHashMap[methodName]; |
2399 if (conflictingMethod != null && | 2440 if (conflictingMethod != null && |
2400 conflictingMethod is MethodDeclaration && | 2441 conflictingMethod is MethodDeclaration && |
2401 !conflictingMethod.isGetter) { | 2442 !conflictingMethod.isGetter) { |
2402 // report problem | 2443 // report problem |
2403 _errorReporter.reportErrorForNode( | 2444 _errorReporter.reportErrorForNode( |
2404 StaticWarningCode.CONFLICTING_INSTANCE_METHOD_SETTER2, name, [ | 2445 StaticWarningCode.CONFLICTING_INSTANCE_METHOD_SETTER2, |
2405 _enclosingClass.displayName, | 2446 name, |
2406 name.name | 2447 [_enclosingClass.displayName, name.name]); |
2407 ]); | |
2408 foundError = true; | 2448 foundError = true; |
2409 addThisMemberToTheMap = false; | 2449 addThisMemberToTheMap = false; |
2410 } | 2450 } |
2411 } | 2451 } |
2412 // Finally, add this member into the HashMap. | 2452 // Finally, add this member into the HashMap. |
2413 if (addThisMemberToTheMap) { | 2453 if (addThisMemberToTheMap) { |
2414 if (method.isSetter) { | 2454 if (method.isSetter) { |
2415 memberHashMap["${name.name}="] = method; | 2455 memberHashMap["${name.name}="] = method; |
2416 } else { | 2456 } else { |
2417 memberHashMap[name.name] = method; | 2457 memberHashMap[name.name] = method; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2453 // OK, also static | 2493 // OK, also static |
2454 if (setter.isStatic) { | 2494 if (setter.isStatic) { |
2455 return false; | 2495 return false; |
2456 } | 2496 } |
2457 // prepare "setter" type to report its name | 2497 // prepare "setter" type to report its name |
2458 ClassElement setterClass = setter.enclosingElement as ClassElement; | 2498 ClassElement setterClass = setter.enclosingElement as ClassElement; |
2459 InterfaceType setterType = setterClass.type; | 2499 InterfaceType setterType = setterClass.type; |
2460 // report problem | 2500 // report problem |
2461 _errorReporter.reportErrorForNode( | 2501 _errorReporter.reportErrorForNode( |
2462 StaticWarningCode.CONFLICTING_STATIC_GETTER_AND_INSTANCE_SETTER, | 2502 StaticWarningCode.CONFLICTING_STATIC_GETTER_AND_INSTANCE_SETTER, |
2463 nameNode, [setterType.displayName]); | 2503 nameNode, |
| 2504 [setterType.displayName]); |
2464 return true; | 2505 return true; |
2465 } | 2506 } |
2466 | 2507 |
2467 /** | 2508 /** |
2468 * Verify that the enclosing class does not have an instance member with the | 2509 * Verify that the enclosing class does not have an instance member with the |
2469 * same name as the given static [method] declaration. | 2510 * same name as the given static [method] declaration. |
2470 * | 2511 * |
2471 * See [StaticWarningCode.CONFLICTING_STATIC_SETTER_AND_INSTANCE_MEMBER]. | 2512 * See [StaticWarningCode.CONFLICTING_STATIC_SETTER_AND_INSTANCE_MEMBER]. |
2472 */ | 2513 */ |
2473 bool _checkForConflictingStaticSetterAndInstanceMember( | 2514 bool _checkForConflictingStaticSetterAndInstanceMember( |
(...skipping 27 matching lines...) Expand all Loading... |
2501 // OK, also static | 2542 // OK, also static |
2502 if (member.isStatic) { | 2543 if (member.isStatic) { |
2503 return false; | 2544 return false; |
2504 } | 2545 } |
2505 // prepare "member" type to report its name | 2546 // prepare "member" type to report its name |
2506 ClassElement memberClass = member.enclosingElement as ClassElement; | 2547 ClassElement memberClass = member.enclosingElement as ClassElement; |
2507 InterfaceType memberType = memberClass.type; | 2548 InterfaceType memberType = memberClass.type; |
2508 // report problem | 2549 // report problem |
2509 _errorReporter.reportErrorForNode( | 2550 _errorReporter.reportErrorForNode( |
2510 StaticWarningCode.CONFLICTING_STATIC_SETTER_AND_INSTANCE_MEMBER, | 2551 StaticWarningCode.CONFLICTING_STATIC_SETTER_AND_INSTANCE_MEMBER, |
2511 nameNode, [memberType.displayName]); | 2552 nameNode, |
| 2553 [memberType.displayName]); |
2512 return true; | 2554 return true; |
2513 } | 2555 } |
2514 | 2556 |
2515 /** | 2557 /** |
2516 * Verify all conflicts between type variable and enclosing class. | 2558 * Verify all conflicts between type variable and enclosing class. |
2517 * TODO(scheglov) | 2559 * TODO(scheglov) |
2518 * | 2560 * |
2519 * See [CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_CLASS], and | 2561 * See [CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_CLASS], and |
2520 * [CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_MEMBER]. | 2562 * [CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_MEMBER]. |
2521 */ | 2563 */ |
2522 bool _checkForConflictingTypeVariableErrorCodes( | 2564 bool _checkForConflictingTypeVariableErrorCodes( |
2523 ClassDeclaration declaration) { | 2565 ClassDeclaration declaration) { |
2524 bool problemReported = false; | 2566 bool problemReported = false; |
2525 for (TypeParameterElement typeParameter in _enclosingClass.typeParameters) { | 2567 for (TypeParameterElement typeParameter in _enclosingClass.typeParameters) { |
2526 String name = typeParameter.name; | 2568 String name = typeParameter.name; |
2527 // name is same as the name of the enclosing class | 2569 // name is same as the name of the enclosing class |
2528 if (_enclosingClass.name == name) { | 2570 if (_enclosingClass.name == name) { |
2529 _errorReporter.reportErrorForOffset( | 2571 _errorReporter.reportErrorForOffset( |
2530 CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_CLASS, | 2572 CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_CLASS, |
2531 typeParameter.nameOffset, name.length, [name]); | 2573 typeParameter.nameOffset, |
| 2574 name.length, |
| 2575 [name]); |
2532 problemReported = true; | 2576 problemReported = true; |
2533 } | 2577 } |
2534 // check members | 2578 // check members |
2535 if (_enclosingClass.getMethod(name) != null || | 2579 if (_enclosingClass.getMethod(name) != null || |
2536 _enclosingClass.getGetter(name) != null || | 2580 _enclosingClass.getGetter(name) != null || |
2537 _enclosingClass.getSetter(name) != null) { | 2581 _enclosingClass.getSetter(name) != null) { |
2538 _errorReporter.reportErrorForOffset( | 2582 _errorReporter.reportErrorForOffset( |
2539 CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_MEMBER, | 2583 CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_MEMBER, |
2540 typeParameter.nameOffset, name.length, [name]); | 2584 typeParameter.nameOffset, |
| 2585 name.length, |
| 2586 [name]); |
2541 problemReported = true; | 2587 problemReported = true; |
2542 } | 2588 } |
2543 } | 2589 } |
2544 return problemReported; | 2590 return problemReported; |
2545 } | 2591 } |
2546 | 2592 |
2547 /** | 2593 /** |
2548 * Verify that if the given [constructor] declaration is 'const' then there | 2594 * Verify that if the given [constructor] declaration is 'const' then there |
2549 * are no invocations of non-'const' super constructors. | 2595 * are no invocations of non-'const' super constructors. |
2550 * | 2596 * |
(...skipping 18 matching lines...) Expand all Loading... |
2569 // try to find and check super constructor invocation | 2615 // try to find and check super constructor invocation |
2570 for (ConstructorInitializer initializer in constructor.initializers) { | 2616 for (ConstructorInitializer initializer in constructor.initializers) { |
2571 if (initializer is SuperConstructorInvocation) { | 2617 if (initializer is SuperConstructorInvocation) { |
2572 SuperConstructorInvocation superInvocation = initializer; | 2618 SuperConstructorInvocation superInvocation = initializer; |
2573 ConstructorElement element = superInvocation.staticElement; | 2619 ConstructorElement element = superInvocation.staticElement; |
2574 if (element == null || element.isConst) { | 2620 if (element == null || element.isConst) { |
2575 return false; | 2621 return false; |
2576 } | 2622 } |
2577 _errorReporter.reportErrorForNode( | 2623 _errorReporter.reportErrorForNode( |
2578 CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_NON_CONST_SUPER, | 2624 CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_NON_CONST_SUPER, |
2579 superInvocation, [element.enclosingElement.displayName]); | 2625 superInvocation, |
| 2626 [element.enclosingElement.displayName]); |
2580 return true; | 2627 return true; |
2581 } | 2628 } |
2582 } | 2629 } |
2583 // no explicit super constructor invocation, check default constructor | 2630 // no explicit super constructor invocation, check default constructor |
2584 InterfaceType supertype = _enclosingClass.supertype; | 2631 InterfaceType supertype = _enclosingClass.supertype; |
2585 if (supertype == null) { | 2632 if (supertype == null) { |
2586 return false; | 2633 return false; |
2587 } | 2634 } |
2588 if (supertype.isObject) { | 2635 if (supertype.isObject) { |
2589 return false; | 2636 return false; |
2590 } | 2637 } |
2591 ConstructorElement unnamedConstructor = | 2638 ConstructorElement unnamedConstructor = |
2592 supertype.element.unnamedConstructor; | 2639 supertype.element.unnamedConstructor; |
2593 if (unnamedConstructor == null) { | 2640 if (unnamedConstructor == null) { |
2594 return false; | 2641 return false; |
2595 } | 2642 } |
2596 if (unnamedConstructor.isConst) { | 2643 if (unnamedConstructor.isConst) { |
2597 return false; | 2644 return false; |
2598 } | 2645 } |
2599 // default constructor is not 'const', report problem | 2646 // default constructor is not 'const', report problem |
2600 _errorReporter.reportErrorForNode( | 2647 _errorReporter.reportErrorForNode( |
2601 CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_NON_CONST_SUPER, | 2648 CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_NON_CONST_SUPER, |
2602 constructor.returnType, [supertype.displayName]); | 2649 constructor.returnType, |
| 2650 [supertype.displayName]); |
2603 return true; | 2651 return true; |
2604 } | 2652 } |
2605 | 2653 |
2606 /** | 2654 /** |
2607 * Verify that if the given [constructor] declaration is 'const' then there | 2655 * Verify that if the given [constructor] declaration is 'const' then there |
2608 * are no non-final instance variable. The [constructorElement] is the | 2656 * are no non-final instance variable. The [constructorElement] is the |
2609 * constructor element. | 2657 * constructor element. |
2610 * | 2658 * |
2611 * See [CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_NON_FINAL_FIELD]. | 2659 * See [CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_NON_FINAL_FIELD]. |
2612 */ | 2660 */ |
(...skipping 20 matching lines...) Expand all Loading... |
2633 * creating a deferred type. The [constructorName] is the constructor name, | 2681 * creating a deferred type. The [constructorName] is the constructor name, |
2634 * always non-`null`. The [typeName] is the name of the type defining the | 2682 * always non-`null`. The [typeName] is the name of the type defining the |
2635 * constructor, always non-`null`. | 2683 * constructor, always non-`null`. |
2636 * | 2684 * |
2637 * See [CompileTimeErrorCode.CONST_DEFERRED_CLASS]. | 2685 * See [CompileTimeErrorCode.CONST_DEFERRED_CLASS]. |
2638 */ | 2686 */ |
2639 bool _checkForConstDeferredClass(InstanceCreationExpression expression, | 2687 bool _checkForConstDeferredClass(InstanceCreationExpression expression, |
2640 ConstructorName constructorName, TypeName typeName) { | 2688 ConstructorName constructorName, TypeName typeName) { |
2641 if (typeName.isDeferred) { | 2689 if (typeName.isDeferred) { |
2642 _errorReporter.reportErrorForNode( | 2690 _errorReporter.reportErrorForNode( |
2643 CompileTimeErrorCode.CONST_DEFERRED_CLASS, constructorName, | 2691 CompileTimeErrorCode.CONST_DEFERRED_CLASS, |
| 2692 constructorName, |
2644 [typeName.name.name]); | 2693 [typeName.name.name]); |
2645 return true; | 2694 return true; |
2646 } | 2695 } |
2647 return false; | 2696 return false; |
2648 } | 2697 } |
2649 | 2698 |
2650 /** | 2699 /** |
2651 * Verify that the given throw [expression] is not enclosed in a 'const' | 2700 * Verify that the given throw [expression] is not enclosed in a 'const' |
2652 * constructor declaration. | 2701 * constructor declaration. |
2653 * | 2702 * |
(...skipping 26 matching lines...) Expand all Loading... |
2680 * Verify that the given instance creation [expression] is not being invoked | 2729 * Verify that the given instance creation [expression] is not being invoked |
2681 * on an abstract class. The [typeName] is the [TypeName] of the | 2730 * on an abstract class. The [typeName] is the [TypeName] of the |
2682 * [ConstructorName] from the [InstanceCreationExpression], this is the AST | 2731 * [ConstructorName] from the [InstanceCreationExpression], this is the AST |
2683 * node that the error is attached to. The [type] is the type being | 2732 * node that the error is attached to. The [type] is the type being |
2684 * constructed with this [InstanceCreationExpression]. | 2733 * constructed with this [InstanceCreationExpression]. |
2685 * | 2734 * |
2686 * See [StaticWarningCode.CONST_WITH_ABSTRACT_CLASS], and | 2735 * See [StaticWarningCode.CONST_WITH_ABSTRACT_CLASS], and |
2687 * [StaticWarningCode.NEW_WITH_ABSTRACT_CLASS]. | 2736 * [StaticWarningCode.NEW_WITH_ABSTRACT_CLASS]. |
2688 */ | 2737 */ |
2689 bool _checkForConstOrNewWithAbstractClass( | 2738 bool _checkForConstOrNewWithAbstractClass( |
2690 InstanceCreationExpression expression, TypeName typeName, | 2739 InstanceCreationExpression expression, |
| 2740 TypeName typeName, |
2691 InterfaceType type) { | 2741 InterfaceType type) { |
2692 if (type.element.isAbstract) { | 2742 if (type.element.isAbstract) { |
2693 ConstructorElement element = expression.staticElement; | 2743 ConstructorElement element = expression.staticElement; |
2694 if (element != null && !element.isFactory) { | 2744 if (element != null && !element.isFactory) { |
2695 if ((expression.keyword as sc.KeywordToken).keyword == | 2745 if ((expression.keyword as sc.KeywordToken).keyword == |
2696 sc.Keyword.CONST) { | 2746 sc.Keyword.CONST) { |
2697 _errorReporter.reportErrorForNode( | 2747 _errorReporter.reportErrorForNode( |
2698 StaticWarningCode.CONST_WITH_ABSTRACT_CLASS, typeName); | 2748 StaticWarningCode.CONST_WITH_ABSTRACT_CLASS, typeName); |
2699 } else { | 2749 } else { |
2700 _errorReporter.reportErrorForNode( | 2750 _errorReporter.reportErrorForNode( |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2784 * constructor name, always non-`null`. The [typeName] is the name of the type | 2834 * constructor name, always non-`null`. The [typeName] is the name of the type |
2785 * defining the constructor, always non-`null`. | 2835 * defining the constructor, always non-`null`. |
2786 * | 2836 * |
2787 * This method assumes that the instance creation was tested to be 'const' | 2837 * This method assumes that the instance creation was tested to be 'const' |
2788 * before being called. | 2838 * before being called. |
2789 * | 2839 * |
2790 * See [CompileTimeErrorCode.CONST_WITH_UNDEFINED_CONSTRUCTOR], and | 2840 * See [CompileTimeErrorCode.CONST_WITH_UNDEFINED_CONSTRUCTOR], and |
2791 * [CompileTimeErrorCode.CONST_WITH_UNDEFINED_CONSTRUCTOR_DEFAULT]. | 2841 * [CompileTimeErrorCode.CONST_WITH_UNDEFINED_CONSTRUCTOR_DEFAULT]. |
2792 */ | 2842 */ |
2793 bool _checkForConstWithUndefinedConstructor( | 2843 bool _checkForConstWithUndefinedConstructor( |
2794 InstanceCreationExpression expression, ConstructorName constructorName, | 2844 InstanceCreationExpression expression, |
| 2845 ConstructorName constructorName, |
2795 TypeName typeName) { | 2846 TypeName typeName) { |
2796 // OK if resolved | 2847 // OK if resolved |
2797 if (expression.staticElement != null) { | 2848 if (expression.staticElement != null) { |
2798 return false; | 2849 return false; |
2799 } | 2850 } |
2800 DartType type = typeName.type; | 2851 DartType type = typeName.type; |
2801 if (type is InterfaceType) { | 2852 if (type is InterfaceType) { |
2802 ClassElement element = type.element; | 2853 ClassElement element = type.element; |
2803 if (element != null && element.isEnum) { | 2854 if (element != null && element.isEnum) { |
2804 // We have already reported the error. | 2855 // We have already reported the error. |
2805 return false; | 2856 return false; |
2806 } | 2857 } |
2807 } | 2858 } |
2808 Identifier className = typeName.name; | 2859 Identifier className = typeName.name; |
2809 // report as named or default constructor absence | 2860 // report as named or default constructor absence |
2810 SimpleIdentifier name = constructorName.name; | 2861 SimpleIdentifier name = constructorName.name; |
2811 if (name != null) { | 2862 if (name != null) { |
2812 _errorReporter.reportErrorForNode( | 2863 _errorReporter.reportErrorForNode( |
2813 CompileTimeErrorCode.CONST_WITH_UNDEFINED_CONSTRUCTOR, name, [ | 2864 CompileTimeErrorCode.CONST_WITH_UNDEFINED_CONSTRUCTOR, |
2814 className, | 2865 name, |
2815 name | 2866 [className, name]); |
2816 ]); | |
2817 } else { | 2867 } else { |
2818 _errorReporter.reportErrorForNode( | 2868 _errorReporter.reportErrorForNode( |
2819 CompileTimeErrorCode.CONST_WITH_UNDEFINED_CONSTRUCTOR_DEFAULT, | 2869 CompileTimeErrorCode.CONST_WITH_UNDEFINED_CONSTRUCTOR_DEFAULT, |
2820 constructorName, [className]); | 2870 constructorName, |
| 2871 [className]); |
2821 } | 2872 } |
2822 return true; | 2873 return true; |
2823 } | 2874 } |
2824 | 2875 |
2825 /** | 2876 /** |
2826 * Verify that there are no default parameters in the given function type | 2877 * Verify that there are no default parameters in the given function type |
2827 * [alias]. | 2878 * [alias]. |
2828 * | 2879 * |
2829 * See [CompileTimeErrorCode.DEFAULT_VALUE_IN_FUNCTION_TYPE_ALIAS]. | 2880 * See [CompileTimeErrorCode.DEFAULT_VALUE_IN_FUNCTION_TYPE_ALIAS]. |
2830 */ | 2881 */ |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2961 String displayName; | 3012 String displayName; |
2962 Element enclosingElement = inheritedMember.enclosingElement; | 3013 Element enclosingElement = inheritedMember.enclosingElement; |
2963 if (enclosingElement.source == _enclosingClass.source) { | 3014 if (enclosingElement.source == _enclosingClass.source) { |
2964 displayName = enclosingElement.displayName; | 3015 displayName = enclosingElement.displayName; |
2965 } else { | 3016 } else { |
2966 displayName = enclosingElement.getExtendedDisplayName(null); | 3017 displayName = enclosingElement.getExtendedDisplayName(null); |
2967 } | 3018 } |
2968 // report problem | 3019 // report problem |
2969 _errorReporter.reportErrorForOffset( | 3020 _errorReporter.reportErrorForOffset( |
2970 CompileTimeErrorCode.DUPLICATE_DEFINITION_INHERITANCE, | 3021 CompileTimeErrorCode.DUPLICATE_DEFINITION_INHERITANCE, |
2971 staticMember.nameOffset, name.length, [name, displayName]); | 3022 staticMember.nameOffset, |
| 3023 name.length, |
| 3024 [name, displayName]); |
2972 return true; | 3025 return true; |
2973 } | 3026 } |
2974 | 3027 |
2975 /** | 3028 /** |
2976 * Verify that if the given list [literal] has type arguments then there is | 3029 * Verify that if the given list [literal] has type arguments then there is |
2977 * exactly one. The [typeArguments] are the type arguments. | 3030 * exactly one. The [typeArguments] are the type arguments. |
2978 * | 3031 * |
2979 * See [StaticTypeWarningCode.EXPECTED_ONE_LIST_TYPE_ARGUMENTS]. | 3032 * See [StaticTypeWarningCode.EXPECTED_ONE_LIST_TYPE_ARGUMENTS]. |
2980 */ | 3033 */ |
2981 bool _checkForExpectedOneListTypeArgument( | 3034 bool _checkForExpectedOneListTypeArgument( |
2982 ListLiteral literal, TypeArgumentList typeArguments) { | 3035 ListLiteral literal, TypeArgumentList typeArguments) { |
2983 // check number of type arguments | 3036 // check number of type arguments |
2984 int num = typeArguments.arguments.length; | 3037 int num = typeArguments.arguments.length; |
2985 if (num == 1) { | 3038 if (num == 1) { |
2986 return false; | 3039 return false; |
2987 } | 3040 } |
2988 // report problem | 3041 // report problem |
2989 _errorReporter.reportErrorForNode( | 3042 _errorReporter.reportErrorForNode( |
2990 StaticTypeWarningCode.EXPECTED_ONE_LIST_TYPE_ARGUMENTS, typeArguments, | 3043 StaticTypeWarningCode.EXPECTED_ONE_LIST_TYPE_ARGUMENTS, |
| 3044 typeArguments, |
2991 [num]); | 3045 [num]); |
2992 return true; | 3046 return true; |
2993 } | 3047 } |
2994 | 3048 |
2995 /** | 3049 /** |
2996 * Verify that the given export [directive] has a unique name among other | 3050 * Verify that the given export [directive] has a unique name among other |
2997 * exported libraries. The [exportElement] is the [ExportElement] retrieved | 3051 * exported libraries. The [exportElement] is the [ExportElement] retrieved |
2998 * from the node, if the element in the node was `null`, then this method is | 3052 * 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 | 3053 * not called. The [exportedLibrary] is the library element containing the |
3000 * exported element. | 3054 * exported element. |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3046 String uri = exportElement.uri; | 3100 String uri = exportElement.uri; |
3047 SdkLibrary sdkLibrary = sdk.getSdkLibrary(uri); | 3101 SdkLibrary sdkLibrary = sdk.getSdkLibrary(uri); |
3048 if (sdkLibrary == null) { | 3102 if (sdkLibrary == null) { |
3049 return false; | 3103 return false; |
3050 } | 3104 } |
3051 if (!sdkLibrary.isInternal) { | 3105 if (!sdkLibrary.isInternal) { |
3052 return false; | 3106 return false; |
3053 } | 3107 } |
3054 // report problem | 3108 // report problem |
3055 _errorReporter.reportErrorForNode( | 3109 _errorReporter.reportErrorForNode( |
3056 CompileTimeErrorCode.EXPORT_INTERNAL_LIBRARY, directive, | 3110 CompileTimeErrorCode.EXPORT_INTERNAL_LIBRARY, |
| 3111 directive, |
3057 [directive.uri]); | 3112 [directive.uri]); |
3058 return true; | 3113 return true; |
3059 } | 3114 } |
3060 | 3115 |
3061 /** | 3116 /** |
3062 * Verify that the given extends [clause] does not extend a deferred class. | 3117 * Verify that the given extends [clause] does not extend a deferred class. |
3063 * | 3118 * |
3064 * See [CompileTimeErrorCode.EXTENDS_DEFERRED_CLASS]. | 3119 * See [CompileTimeErrorCode.EXTENDS_DEFERRED_CLASS]. |
3065 */ | 3120 */ |
3066 bool _checkForExtendsDeferredClass(ExtendsClause clause) { | 3121 bool _checkForExtendsDeferredClass(ExtendsClause clause) { |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3215 } | 3270 } |
3216 if (staticType.isAssignableTo(fieldType)) { | 3271 if (staticType.isAssignableTo(fieldType)) { |
3217 return false; | 3272 return false; |
3218 } | 3273 } |
3219 // report problem | 3274 // report problem |
3220 if (_isEnclosingConstructorConst) { | 3275 if (_isEnclosingConstructorConst) { |
3221 // TODO(paulberry): this error should be based on the actual type of the | 3276 // TODO(paulberry): this error should be based on the actual type of the |
3222 // constant, not the static type. See dartbug.com/21119. | 3277 // constant, not the static type. See dartbug.com/21119. |
3223 _errorReporter.reportTypeErrorForNode( | 3278 _errorReporter.reportTypeErrorForNode( |
3224 CheckedModeCompileTimeErrorCode.CONST_FIELD_INITIALIZER_NOT_ASSIGNABLE
, | 3279 CheckedModeCompileTimeErrorCode.CONST_FIELD_INITIALIZER_NOT_ASSIGNABLE
, |
3225 expression, [staticType, fieldType]); | 3280 expression, |
| 3281 [staticType, fieldType]); |
3226 } | 3282 } |
3227 _errorReporter.reportTypeErrorForNode( | 3283 _errorReporter.reportTypeErrorForNode( |
3228 StaticWarningCode.FIELD_INITIALIZER_NOT_ASSIGNABLE, expression, [ | 3284 StaticWarningCode.FIELD_INITIALIZER_NOT_ASSIGNABLE, |
3229 staticType, | 3285 expression, |
3230 fieldType | 3286 [staticType, fieldType]); |
3231 ]); | |
3232 return true; | 3287 return true; |
3233 // TODO(brianwilkerson) Define a hint corresponding to these errors and | 3288 // TODO(brianwilkerson) Define a hint corresponding to these errors and |
3234 // report it if appropriate. | 3289 // report it if appropriate. |
3235 // // test the propagated type of the expression | 3290 // // test the propagated type of the expression |
3236 // Type propagatedType = expression.getPropagatedType(); | 3291 // Type propagatedType = expression.getPropagatedType(); |
3237 // if (propagatedType != null && propagatedType.isAssignableTo(fieldType)
) { | 3292 // if (propagatedType != null && propagatedType.isAssignableTo(fieldType)
) { |
3238 // return false; | 3293 // return false; |
3239 // } | 3294 // } |
3240 // // report problem | 3295 // // report problem |
3241 // if (isEnclosingConstructorConst) { | 3296 // if (isEnclosingConstructorConst) { |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3301 if (_isInNativeClass) { | 3356 if (_isInNativeClass) { |
3302 return false; | 3357 return false; |
3303 } | 3358 } |
3304 bool foundError = false; | 3359 bool foundError = false; |
3305 if (!list.isSynthetic) { | 3360 if (!list.isSynthetic) { |
3306 NodeList<VariableDeclaration> variables = list.variables; | 3361 NodeList<VariableDeclaration> variables = list.variables; |
3307 for (VariableDeclaration variable in variables) { | 3362 for (VariableDeclaration variable in variables) { |
3308 if (variable.initializer == null) { | 3363 if (variable.initializer == null) { |
3309 if (list.isConst) { | 3364 if (list.isConst) { |
3310 _errorReporter.reportErrorForNode( | 3365 _errorReporter.reportErrorForNode( |
3311 CompileTimeErrorCode.CONST_NOT_INITIALIZED, variable.name, | 3366 CompileTimeErrorCode.CONST_NOT_INITIALIZED, |
| 3367 variable.name, |
3312 [variable.name.name]); | 3368 [variable.name.name]); |
3313 } else if (list.isFinal) { | 3369 } else if (list.isFinal) { |
3314 _errorReporter.reportErrorForNode( | 3370 _errorReporter.reportErrorForNode( |
3315 StaticWarningCode.FINAL_NOT_INITIALIZED, variable.name, | 3371 StaticWarningCode.FINAL_NOT_INITIALIZED, |
| 3372 variable.name, |
3316 [variable.name.name]); | 3373 [variable.name.name]); |
3317 } | 3374 } |
3318 foundError = true; | 3375 foundError = true; |
3319 } | 3376 } |
3320 } | 3377 } |
3321 } | 3378 } |
3322 return foundError; | 3379 return foundError; |
3323 } | 3380 } |
3324 | 3381 |
3325 /** | 3382 /** |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3553 String uri = importElement.uri; | 3610 String uri = importElement.uri; |
3554 SdkLibrary sdkLibrary = sdk.getSdkLibrary(uri); | 3611 SdkLibrary sdkLibrary = sdk.getSdkLibrary(uri); |
3555 if (sdkLibrary == null) { | 3612 if (sdkLibrary == null) { |
3556 return false; | 3613 return false; |
3557 } | 3614 } |
3558 if (!sdkLibrary.isInternal) { | 3615 if (!sdkLibrary.isInternal) { |
3559 return false; | 3616 return false; |
3560 } | 3617 } |
3561 // report problem | 3618 // report problem |
3562 _errorReporter.reportErrorForNode( | 3619 _errorReporter.reportErrorForNode( |
3563 CompileTimeErrorCode.IMPORT_INTERNAL_LIBRARY, directive, | 3620 CompileTimeErrorCode.IMPORT_INTERNAL_LIBRARY, |
| 3621 directive, |
3564 [directive.uri]); | 3622 [directive.uri]); |
3565 return true; | 3623 return true; |
3566 } | 3624 } |
3567 | 3625 |
3568 /** | 3626 /** |
3569 * For each class declaration, this method is called which verifies that all | 3627 * For each class declaration, this method is called which verifies that all |
3570 * inherited members are inherited consistently. | 3628 * inherited members are inherited consistently. |
3571 * | 3629 * |
3572 * See [StaticTypeWarningCode.INCONSISTENT_METHOD_INHERITANCE]. | 3630 * See [StaticTypeWarningCode.INCONSISTENT_METHOD_INHERITANCE]. |
3573 */ | 3631 */ |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3612 // OK, top-level element | 3670 // OK, top-level element |
3613 if (executableElement.enclosingElement is! ClassElement) { | 3671 if (executableElement.enclosingElement is! ClassElement) { |
3614 return false; | 3672 return false; |
3615 } | 3673 } |
3616 // OK, instance member | 3674 // OK, instance member |
3617 if (!executableElement.isStatic) { | 3675 if (!executableElement.isStatic) { |
3618 return false; | 3676 return false; |
3619 } | 3677 } |
3620 // report problem | 3678 // report problem |
3621 _errorReporter.reportErrorForNode( | 3679 _errorReporter.reportErrorForNode( |
3622 StaticTypeWarningCode.INSTANCE_ACCESS_TO_STATIC_MEMBER, name, | 3680 StaticTypeWarningCode.INSTANCE_ACCESS_TO_STATIC_MEMBER, |
| 3681 name, |
3623 [name.name]); | 3682 [name.name]); |
3624 return true; | 3683 return true; |
3625 } | 3684 } |
3626 | 3685 |
3627 /** | 3686 /** |
3628 * Check whether the given [executableElement] collides with the name of a | 3687 * Check whether the given [executableElement] collides with the name of a |
3629 * static method in one of its superclasses, and reports the appropriate | 3688 * static method in one of its superclasses, and reports the appropriate |
3630 * warning if it does. The [errorNameTarget] is the node to report problems | 3689 * warning if it does. The [errorNameTarget] is the node to report problems |
3631 * on. | 3690 * on. |
3632 * | 3691 * |
(...skipping 20 matching lines...) Expand all Loading... |
3653 if (fieldElt != null) { | 3712 if (fieldElt != null) { |
3654 // Ignore if private in a different library - cannot collide. | 3713 // Ignore if private in a different library - cannot collide. |
3655 if (executableElementPrivate && | 3714 if (executableElementPrivate && |
3656 _currentLibrary != superclassLibrary) { | 3715 _currentLibrary != superclassLibrary) { |
3657 continue; | 3716 continue; |
3658 } | 3717 } |
3659 // instance vs. static | 3718 // instance vs. static |
3660 if (fieldElt.isStatic) { | 3719 if (fieldElt.isStatic) { |
3661 _errorReporter.reportErrorForNode( | 3720 _errorReporter.reportErrorForNode( |
3662 StaticWarningCode.INSTANCE_METHOD_NAME_COLLIDES_WITH_SUPERCLASS_
STATIC, | 3721 StaticWarningCode.INSTANCE_METHOD_NAME_COLLIDES_WITH_SUPERCLASS_
STATIC, |
3663 errorNameTarget, [ | 3722 errorNameTarget, |
3664 executableElementName, | 3723 [executableElementName, fieldElt.enclosingElement.displayName]); |
3665 fieldElt.enclosingElement.displayName | |
3666 ]); | |
3667 return true; | 3724 return true; |
3668 } | 3725 } |
3669 } | 3726 } |
3670 // Check methods. | 3727 // Check methods. |
3671 List<MethodElement> methodElements = superclassElement.methods; | 3728 List<MethodElement> methodElements = superclassElement.methods; |
3672 for (MethodElement methodElement in methodElements) { | 3729 for (MethodElement methodElement in methodElements) { |
3673 // We need the same name. | 3730 // We need the same name. |
3674 if (methodElement.name != executableElementName) { | 3731 if (methodElement.name != executableElementName) { |
3675 continue; | 3732 continue; |
3676 } | 3733 } |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3744 if (lhs == null || rhs == null) { | 3801 if (lhs == null || rhs == null) { |
3745 return false; | 3802 return false; |
3746 } | 3803 } |
3747 VariableElement leftVariableElement = getVariableElement(lhs); | 3804 VariableElement leftVariableElement = getVariableElement(lhs); |
3748 DartType leftType = (leftVariableElement == null) | 3805 DartType leftType = (leftVariableElement == null) |
3749 ? getStaticType(lhs) | 3806 ? getStaticType(lhs) |
3750 : leftVariableElement.type; | 3807 : leftVariableElement.type; |
3751 DartType staticRightType = getStaticType(rhs); | 3808 DartType staticRightType = getStaticType(rhs); |
3752 if (!staticRightType.isAssignableTo(leftType)) { | 3809 if (!staticRightType.isAssignableTo(leftType)) { |
3753 _errorReporter.reportTypeErrorForNode( | 3810 _errorReporter.reportTypeErrorForNode( |
3754 StaticTypeWarningCode.INVALID_ASSIGNMENT, rhs, [ | 3811 StaticTypeWarningCode.INVALID_ASSIGNMENT, |
3755 staticRightType, | 3812 rhs, |
3756 leftType | 3813 [staticRightType, leftType]); |
3757 ]); | |
3758 return true; | 3814 return true; |
3759 } | 3815 } |
3760 return false; | 3816 return false; |
3761 } | 3817 } |
3762 | 3818 |
3763 /** | 3819 /** |
3764 * Given an [assignment] using a compound assignment operator, this verifies | 3820 * Given an [assignment] using a compound assignment operator, this verifies |
3765 * that the given assignment is valid. The [lhs] is the left hand side | 3821 * that the given assignment is valid. The [lhs] is the left hand side |
3766 * expression. The [rhs] is the right hand side expression. | 3822 * expression. The [rhs] is the right hand side expression. |
3767 * | 3823 * |
(...skipping 30 matching lines...) Expand all Loading... |
3798 * [ConstructorFieldInitializer]. The [staticElement] is the static element | 3854 * [ConstructorFieldInitializer]. The [staticElement] is the static element |
3799 * from the name in the [ConstructorFieldInitializer]. | 3855 * from the name in the [ConstructorFieldInitializer]. |
3800 */ | 3856 */ |
3801 void _checkForInvalidField(ConstructorFieldInitializer initializer, | 3857 void _checkForInvalidField(ConstructorFieldInitializer initializer, |
3802 SimpleIdentifier fieldName, Element staticElement) { | 3858 SimpleIdentifier fieldName, Element staticElement) { |
3803 if (staticElement is FieldElement) { | 3859 if (staticElement is FieldElement) { |
3804 FieldElement fieldElement = staticElement; | 3860 FieldElement fieldElement = staticElement; |
3805 if (fieldElement.isSynthetic) { | 3861 if (fieldElement.isSynthetic) { |
3806 _errorReporter.reportErrorForNode( | 3862 _errorReporter.reportErrorForNode( |
3807 CompileTimeErrorCode.INITIALIZER_FOR_NON_EXISTENT_FIELD, | 3863 CompileTimeErrorCode.INITIALIZER_FOR_NON_EXISTENT_FIELD, |
3808 initializer, [fieldName]); | 3864 initializer, |
| 3865 [fieldName]); |
3809 } else if (fieldElement.isStatic) { | 3866 } else if (fieldElement.isStatic) { |
3810 _errorReporter.reportErrorForNode( | 3867 _errorReporter.reportErrorForNode( |
3811 CompileTimeErrorCode.INITIALIZER_FOR_STATIC_FIELD, initializer, | 3868 CompileTimeErrorCode.INITIALIZER_FOR_STATIC_FIELD, |
| 3869 initializer, |
3812 [fieldName]); | 3870 [fieldName]); |
3813 } | 3871 } |
3814 } else { | 3872 } else { |
3815 _errorReporter.reportErrorForNode( | 3873 _errorReporter.reportErrorForNode( |
3816 CompileTimeErrorCode.INITIALIZER_FOR_NON_EXISTENT_FIELD, initializer, | 3874 CompileTimeErrorCode.INITIALIZER_FOR_NON_EXISTENT_FIELD, |
| 3875 initializer, |
3817 [fieldName]); | 3876 [fieldName]); |
3818 return; | 3877 return; |
3819 } | 3878 } |
3820 } | 3879 } |
3821 | 3880 |
3822 /** | 3881 /** |
3823 * Check to see whether the given function [body] has a modifier associated | 3882 * Check to see whether the given function [body] has a modifier associated |
3824 * with it, and report it as an error if it does. | 3883 * with it, and report it as an error if it does. |
3825 */ | 3884 */ |
3826 bool _checkForInvalidModifierOnBody( | 3885 bool _checkForInvalidModifierOnBody( |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3878 if (typeNames.length < 1) { | 3937 if (typeNames.length < 1) { |
3879 return false; | 3938 return false; |
3880 } | 3939 } |
3881 DartType listElementType = typeNames[0].type; | 3940 DartType listElementType = typeNames[0].type; |
3882 // Check every list element. | 3941 // Check every list element. |
3883 bool hasProblems = false; | 3942 bool hasProblems = false; |
3884 for (Expression element in literal.elements) { | 3943 for (Expression element in literal.elements) { |
3885 if (literal.constKeyword != null) { | 3944 if (literal.constKeyword != null) { |
3886 // TODO(paulberry): this error should be based on the actual type of the | 3945 // TODO(paulberry): this error should be based on the actual type of the |
3887 // list element, not the static type. See dartbug.com/21119. | 3946 // list element, not the static type. See dartbug.com/21119. |
3888 if (_checkForArgumentTypeNotAssignableWithExpectedTypes(element, | 3947 if (_checkForArgumentTypeNotAssignableWithExpectedTypes( |
| 3948 element, |
3889 listElementType, | 3949 listElementType, |
3890 CheckedModeCompileTimeErrorCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE)) { | 3950 CheckedModeCompileTimeErrorCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE)) { |
3891 hasProblems = true; | 3951 hasProblems = true; |
3892 } | 3952 } |
3893 } | 3953 } |
3894 if (_checkForArgumentTypeNotAssignableWithExpectedTypes(element, | 3954 if (_checkForArgumentTypeNotAssignableWithExpectedTypes( |
| 3955 element, |
3895 listElementType, | 3956 listElementType, |
3896 StaticWarningCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE)) { | 3957 StaticWarningCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE)) { |
3897 hasProblems = true; | 3958 hasProblems = true; |
3898 } | 3959 } |
3899 } | 3960 } |
3900 return hasProblems; | 3961 return hasProblems; |
3901 } | 3962 } |
3902 | 3963 |
3903 /** | 3964 /** |
3904 * Verify that the key/value of entries of the given map [literal] are | 3965 * Verify that the key/value of entries of the given map [literal] are |
(...skipping 20 matching lines...) Expand all Loading... |
3925 for (MapLiteralEntry entry in entries) { | 3986 for (MapLiteralEntry entry in entries) { |
3926 Expression key = entry.key; | 3987 Expression key = entry.key; |
3927 Expression value = entry.value; | 3988 Expression value = entry.value; |
3928 if (literal.constKeyword != null) { | 3989 if (literal.constKeyword != null) { |
3929 // TODO(paulberry): this error should be based on the actual type of the | 3990 // TODO(paulberry): this error should be based on the actual type of the |
3930 // list element, not the static type. See dartbug.com/21119. | 3991 // list element, not the static type. See dartbug.com/21119. |
3931 if (_checkForArgumentTypeNotAssignableWithExpectedTypes(key, keyType, | 3992 if (_checkForArgumentTypeNotAssignableWithExpectedTypes(key, keyType, |
3932 CheckedModeCompileTimeErrorCode.MAP_KEY_TYPE_NOT_ASSIGNABLE)) { | 3993 CheckedModeCompileTimeErrorCode.MAP_KEY_TYPE_NOT_ASSIGNABLE)) { |
3933 hasProblems = true; | 3994 hasProblems = true; |
3934 } | 3995 } |
3935 if (_checkForArgumentTypeNotAssignableWithExpectedTypes(value, | 3996 if (_checkForArgumentTypeNotAssignableWithExpectedTypes( |
| 3997 value, |
3936 valueType, | 3998 valueType, |
3937 CheckedModeCompileTimeErrorCode.MAP_VALUE_TYPE_NOT_ASSIGNABLE)) { | 3999 CheckedModeCompileTimeErrorCode.MAP_VALUE_TYPE_NOT_ASSIGNABLE)) { |
3938 hasProblems = true; | 4000 hasProblems = true; |
3939 } | 4001 } |
3940 } | 4002 } |
3941 if (_checkForArgumentTypeNotAssignableWithExpectedTypes( | 4003 if (_checkForArgumentTypeNotAssignableWithExpectedTypes( |
3942 key, keyType, StaticWarningCode.MAP_KEY_TYPE_NOT_ASSIGNABLE)) { | 4004 key, keyType, StaticWarningCode.MAP_KEY_TYPE_NOT_ASSIGNABLE)) { |
3943 hasProblems = true; | 4005 hasProblems = true; |
3944 } | 4006 } |
3945 if (_checkForArgumentTypeNotAssignableWithExpectedTypes( | 4007 if (_checkForArgumentTypeNotAssignableWithExpectedTypes( |
(...skipping 16 matching lines...) Expand all Loading... |
3962 } | 4024 } |
3963 String className = _enclosingClass.name; | 4025 String className = _enclosingClass.name; |
3964 if (className == null) { | 4026 if (className == null) { |
3965 return false; | 4027 return false; |
3966 } | 4028 } |
3967 bool problemReported = false; | 4029 bool problemReported = false; |
3968 // check accessors | 4030 // check accessors |
3969 for (PropertyAccessorElement accessor in _enclosingClass.accessors) { | 4031 for (PropertyAccessorElement accessor in _enclosingClass.accessors) { |
3970 if (className == accessor.name) { | 4032 if (className == accessor.name) { |
3971 _errorReporter.reportErrorForOffset( | 4033 _errorReporter.reportErrorForOffset( |
3972 CompileTimeErrorCode.MEMBER_WITH_CLASS_NAME, accessor.nameOffset, | 4034 CompileTimeErrorCode.MEMBER_WITH_CLASS_NAME, |
| 4035 accessor.nameOffset, |
3973 className.length); | 4036 className.length); |
3974 problemReported = true; | 4037 problemReported = true; |
3975 } | 4038 } |
3976 } | 4039 } |
3977 // don't check methods, they would be constructors | 4040 // don't check methods, they would be constructors |
3978 // done | 4041 // done |
3979 return problemReported; | 4042 return problemReported; |
3980 } | 4043 } |
3981 | 4044 |
3982 /** | 4045 /** |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4048 getterType = _getGetterType(counterpartAccessor); | 4111 getterType = _getGetterType(counterpartAccessor); |
4049 } | 4112 } |
4050 // If either types are not assignable to each other, report an error | 4113 // 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). | 4114 // (if the getter is null, it is dynamic which is assignable to everything). |
4052 if (setterType != null && | 4115 if (setterType != null && |
4053 getterType != null && | 4116 getterType != null && |
4054 !getterType.isAssignableTo(setterType)) { | 4117 !getterType.isAssignableTo(setterType)) { |
4055 if (enclosingClassForCounterpart == null) { | 4118 if (enclosingClassForCounterpart == null) { |
4056 _errorReporter.reportTypeErrorForNode( | 4119 _errorReporter.reportTypeErrorForNode( |
4057 StaticWarningCode.MISMATCHED_GETTER_AND_SETTER_TYPES, | 4120 StaticWarningCode.MISMATCHED_GETTER_AND_SETTER_TYPES, |
4058 accessorDeclaration, [accessorTextName, setterType, getterType]); | 4121 accessorDeclaration, |
| 4122 [accessorTextName, setterType, getterType]); |
4059 return true; | 4123 return true; |
4060 } else { | 4124 } else { |
4061 _errorReporter.reportTypeErrorForNode( | 4125 _errorReporter.reportTypeErrorForNode( |
4062 StaticWarningCode.MISMATCHED_GETTER_AND_SETTER_TYPES_FROM_SUPERTYPE, | 4126 StaticWarningCode.MISMATCHED_GETTER_AND_SETTER_TYPES_FROM_SUPERTYPE, |
4063 accessorDeclaration, [ | 4127 accessorDeclaration, [ |
4064 accessorTextName, | 4128 accessorTextName, |
4065 setterType, | 4129 setterType, |
4066 getterType, | 4130 getterType, |
4067 enclosingClassForCounterpart.displayName | 4131 enclosingClassForCounterpart.displayName |
4068 ]); | 4132 ]); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4114 } | 4178 } |
4115 } | 4179 } |
4116 int nameCount = constantNames.length; | 4180 int nameCount = constantNames.length; |
4117 if (nameCount == 0) { | 4181 if (nameCount == 0) { |
4118 return false; | 4182 return false; |
4119 } | 4183 } |
4120 for (int i = 0; i < nameCount; i++) { | 4184 for (int i = 0; i < nameCount; i++) { |
4121 int offset = statement.offset; | 4185 int offset = statement.offset; |
4122 int end = statement.rightParenthesis.end; | 4186 int end = statement.rightParenthesis.end; |
4123 _errorReporter.reportErrorForOffset( | 4187 _errorReporter.reportErrorForOffset( |
4124 CompileTimeErrorCode.MISSING_ENUM_CONSTANT_IN_SWITCH, offset, | 4188 CompileTimeErrorCode.MISSING_ENUM_CONSTANT_IN_SWITCH, |
4125 end - offset, [constantNames[i]]); | 4189 offset, |
| 4190 end - offset, |
| 4191 [constantNames[i]]); |
4126 } | 4192 } |
4127 return true; | 4193 return true; |
4128 } | 4194 } |
4129 | 4195 |
4130 /** | 4196 /** |
4131 * Verify that the given function [body] does not contain return statements | 4197 * Verify that the given function [body] does not contain return statements |
4132 * that both have and do not have return values. | 4198 * that both have and do not have return values. |
4133 * | 4199 * |
4134 * See [StaticWarningCode.MIXED_RETURN_TYPES]. | 4200 * See [StaticWarningCode.MIXED_RETURN_TYPES]. |
4135 */ | 4201 */ |
(...skipping 22 matching lines...) Expand all Loading... |
4158 * constructor. The [mixinName] is the node to report problem on. The | 4224 * constructor. The [mixinName] is the node to report problem on. The |
4159 * [mixinElement] is the mixing to evaluate. | 4225 * [mixinElement] is the mixing to evaluate. |
4160 * | 4226 * |
4161 * See [CompileTimeErrorCode.MIXIN_DECLARES_CONSTRUCTOR]. | 4227 * See [CompileTimeErrorCode.MIXIN_DECLARES_CONSTRUCTOR]. |
4162 */ | 4228 */ |
4163 bool _checkForMixinDeclaresConstructor( | 4229 bool _checkForMixinDeclaresConstructor( |
4164 TypeName mixinName, ClassElement mixinElement) { | 4230 TypeName mixinName, ClassElement mixinElement) { |
4165 for (ConstructorElement constructor in mixinElement.constructors) { | 4231 for (ConstructorElement constructor in mixinElement.constructors) { |
4166 if (!constructor.isSynthetic && !constructor.isFactory) { | 4232 if (!constructor.isSynthetic && !constructor.isFactory) { |
4167 _errorReporter.reportErrorForNode( | 4233 _errorReporter.reportErrorForNode( |
4168 CompileTimeErrorCode.MIXIN_DECLARES_CONSTRUCTOR, mixinName, | 4234 CompileTimeErrorCode.MIXIN_DECLARES_CONSTRUCTOR, |
| 4235 mixinName, |
4169 [mixinElement.name]); | 4236 [mixinElement.name]); |
4170 return true; | 4237 return true; |
4171 } | 4238 } |
4172 } | 4239 } |
4173 return false; | 4240 return false; |
4174 } | 4241 } |
4175 | 4242 |
4176 /** | 4243 /** |
4177 * Report the error [CompileTimeErrorCode.MIXIN_HAS_NO_CONSTRUCTORS] if | 4244 * Report the error [CompileTimeErrorCode.MIXIN_HAS_NO_CONSTRUCTORS] if |
4178 * appropriate. | 4245 * appropriate. |
(...skipping 13 matching lines...) Expand all Loading... |
4192 * | 4259 * |
4193 * See [CompileTimeErrorCode.MIXIN_INHERITS_FROM_NOT_OBJECT]. | 4260 * See [CompileTimeErrorCode.MIXIN_INHERITS_FROM_NOT_OBJECT]. |
4194 */ | 4261 */ |
4195 bool _checkForMixinInheritsNotFromObject( | 4262 bool _checkForMixinInheritsNotFromObject( |
4196 TypeName mixinName, ClassElement mixinElement) { | 4263 TypeName mixinName, ClassElement mixinElement) { |
4197 InterfaceType mixinSupertype = mixinElement.supertype; | 4264 InterfaceType mixinSupertype = mixinElement.supertype; |
4198 if (mixinSupertype != null) { | 4265 if (mixinSupertype != null) { |
4199 if (!mixinSupertype.isObject || | 4266 if (!mixinSupertype.isObject || |
4200 !mixinElement.isMixinApplication && mixinElement.mixins.length != 0) { | 4267 !mixinElement.isMixinApplication && mixinElement.mixins.length != 0) { |
4201 _errorReporter.reportErrorForNode( | 4268 _errorReporter.reportErrorForNode( |
4202 CompileTimeErrorCode.MIXIN_INHERITS_FROM_NOT_OBJECT, mixinName, | 4269 CompileTimeErrorCode.MIXIN_INHERITS_FROM_NOT_OBJECT, |
| 4270 mixinName, |
4203 [mixinElement.name]); | 4271 [mixinElement.name]); |
4204 return true; | 4272 return true; |
4205 } | 4273 } |
4206 } | 4274 } |
4207 return false; | 4275 return false; |
4208 } | 4276 } |
4209 | 4277 |
4210 /** | 4278 /** |
4211 * Verify that the given mixin does not reference 'super'. The [mixinName] is | 4279 * 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 | 4280 * the node to report problem on. The [mixinElement] is the mixing to |
4213 * evaluate. | 4281 * evaluate. |
4214 * | 4282 * |
4215 * See [CompileTimeErrorCode.MIXIN_REFERENCES_SUPER]. | 4283 * See [CompileTimeErrorCode.MIXIN_REFERENCES_SUPER]. |
4216 */ | 4284 */ |
4217 bool _checkForMixinReferencesSuper( | 4285 bool _checkForMixinReferencesSuper( |
4218 TypeName mixinName, ClassElement mixinElement) { | 4286 TypeName mixinName, ClassElement mixinElement) { |
4219 if (!enableSuperMixins && mixinElement.hasReferenceToSuper) { | 4287 if (!enableSuperMixins && mixinElement.hasReferenceToSuper) { |
4220 _errorReporter.reportErrorForNode( | 4288 _errorReporter.reportErrorForNode( |
4221 CompileTimeErrorCode.MIXIN_REFERENCES_SUPER, mixinName, | 4289 CompileTimeErrorCode.MIXIN_REFERENCES_SUPER, |
| 4290 mixinName, |
4222 [mixinElement.name]); | 4291 [mixinElement.name]); |
4223 } | 4292 } |
4224 return false; | 4293 return false; |
4225 } | 4294 } |
4226 | 4295 |
4227 /** | 4296 /** |
4228 * Verify that the given [constructor] has at most one 'super' initializer. | 4297 * Verify that the given [constructor] has at most one 'super' initializer. |
4229 * | 4298 * |
4230 * See [CompileTimeErrorCode.MULTIPLE_SUPER_INITIALIZERS]. | 4299 * See [CompileTimeErrorCode.MULTIPLE_SUPER_INITIALIZERS]. |
4231 */ | 4300 */ |
(...skipping 29 matching lines...) Expand all Loading... |
4261 * Verify that the given instance creation [expression] invokes an existing | 4330 * Verify that the given instance creation [expression] invokes an existing |
4262 * constructor. The [constructorName] is the constructor name. The [typeName] | 4331 * constructor. The [constructorName] is the constructor name. The [typeName] |
4263 * is the name of the type defining the constructor. | 4332 * is the name of the type defining the constructor. |
4264 * | 4333 * |
4265 * This method assumes that the instance creation was tested to be 'new' | 4334 * This method assumes that the instance creation was tested to be 'new' |
4266 * before being called. | 4335 * before being called. |
4267 * | 4336 * |
4268 * See [StaticWarningCode.NEW_WITH_UNDEFINED_CONSTRUCTOR]. | 4337 * See [StaticWarningCode.NEW_WITH_UNDEFINED_CONSTRUCTOR]. |
4269 */ | 4338 */ |
4270 bool _checkForNewWithUndefinedConstructor( | 4339 bool _checkForNewWithUndefinedConstructor( |
4271 InstanceCreationExpression expression, ConstructorName constructorName, | 4340 InstanceCreationExpression expression, |
| 4341 ConstructorName constructorName, |
4272 TypeName typeName) { | 4342 TypeName typeName) { |
4273 // OK if resolved | 4343 // OK if resolved |
4274 if (expression.staticElement != null) { | 4344 if (expression.staticElement != null) { |
4275 return false; | 4345 return false; |
4276 } | 4346 } |
4277 DartType type = typeName.type; | 4347 DartType type = typeName.type; |
4278 if (type is InterfaceType) { | 4348 if (type is InterfaceType) { |
4279 ClassElement element = type.element; | 4349 ClassElement element = type.element; |
4280 if (element != null && element.isEnum) { | 4350 if (element != null && element.isEnum) { |
4281 // We have already reported the error. | 4351 // We have already reported the error. |
4282 return false; | 4352 return false; |
4283 } | 4353 } |
4284 } | 4354 } |
4285 // prepare class name | 4355 // prepare class name |
4286 Identifier className = typeName.name; | 4356 Identifier className = typeName.name; |
4287 // report as named or default constructor absence | 4357 // report as named or default constructor absence |
4288 SimpleIdentifier name = constructorName.name; | 4358 SimpleIdentifier name = constructorName.name; |
4289 if (name != null) { | 4359 if (name != null) { |
4290 _errorReporter.reportErrorForNode( | 4360 _errorReporter.reportErrorForNode( |
4291 StaticWarningCode.NEW_WITH_UNDEFINED_CONSTRUCTOR, name, [ | 4361 StaticWarningCode.NEW_WITH_UNDEFINED_CONSTRUCTOR, |
4292 className, | 4362 name, |
4293 name | 4363 [className, name]); |
4294 ]); | |
4295 } else { | 4364 } else { |
4296 _errorReporter.reportErrorForNode( | 4365 _errorReporter.reportErrorForNode( |
4297 StaticWarningCode.NEW_WITH_UNDEFINED_CONSTRUCTOR_DEFAULT, | 4366 StaticWarningCode.NEW_WITH_UNDEFINED_CONSTRUCTOR_DEFAULT, |
4298 constructorName, [className]); | 4367 constructorName, |
| 4368 [className]); |
4299 } | 4369 } |
4300 return true; | 4370 return true; |
4301 } | 4371 } |
4302 | 4372 |
4303 /** | 4373 /** |
4304 * Check that if the given class [declaration] implicitly calls default | 4374 * Check that if the given class [declaration] implicitly calls default |
4305 * constructor of its superclass, there should be such default constructor - | 4375 * constructor of its superclass, there should be such default constructor - |
4306 * implicit or explicit. | 4376 * implicit or explicit. |
4307 * | 4377 * |
4308 * See [CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT]. | 4378 * See [CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT]. |
(...skipping 15 matching lines...) Expand all Loading... |
4324 if (superType == null) { | 4394 if (superType == null) { |
4325 return false; | 4395 return false; |
4326 } | 4396 } |
4327 ClassElement superElement = superType.element; | 4397 ClassElement superElement = superType.element; |
4328 // try to find default generative super constructor | 4398 // try to find default generative super constructor |
4329 ConstructorElement superUnnamedConstructor = | 4399 ConstructorElement superUnnamedConstructor = |
4330 superElement.unnamedConstructor; | 4400 superElement.unnamedConstructor; |
4331 if (superUnnamedConstructor != null) { | 4401 if (superUnnamedConstructor != null) { |
4332 if (superUnnamedConstructor.isFactory) { | 4402 if (superUnnamedConstructor.isFactory) { |
4333 _errorReporter.reportErrorForNode( | 4403 _errorReporter.reportErrorForNode( |
4334 CompileTimeErrorCode.NON_GENERATIVE_CONSTRUCTOR, declaration.name, | 4404 CompileTimeErrorCode.NON_GENERATIVE_CONSTRUCTOR, |
| 4405 declaration.name, |
4335 [superUnnamedConstructor]); | 4406 [superUnnamedConstructor]); |
4336 return true; | 4407 return true; |
4337 } | 4408 } |
4338 if (superUnnamedConstructor.isDefaultConstructor && | 4409 if (superUnnamedConstructor.isDefaultConstructor && |
4339 _enclosingClass | 4410 _enclosingClass |
4340 .isSuperConstructorAccessible(superUnnamedConstructor)) { | 4411 .isSuperConstructorAccessible(superUnnamedConstructor)) { |
4341 return true; | 4412 return true; |
4342 } | 4413 } |
4343 } | 4414 } |
4344 // report problem | 4415 // report problem |
4345 _errorReporter.reportErrorForNode( | 4416 _errorReporter.reportErrorForNode( |
4346 CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT, | 4417 CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT, |
4347 declaration.name, [superType.displayName]); | 4418 declaration.name, |
| 4419 [superType.displayName]); |
4348 return true; | 4420 return true; |
4349 } | 4421 } |
4350 | 4422 |
4351 /** | 4423 /** |
4352 * Check that the given class declaration overrides all members required by | 4424 * Check that the given class declaration overrides all members required by |
4353 * its superclasses and interfaces. The [classNameNode] is the | 4425 * its superclasses and interfaces. The [classNameNode] is the |
4354 * [SimpleIdentifier] to be used if there is a violation, this is either the | 4426 * [SimpleIdentifier] to be used if there is a violation, this is either the |
4355 * named from the [ClassDeclaration] or from the [ClassTypeAlias]. | 4427 * named from the [ClassDeclaration] or from the [ClassTypeAlias]. |
4356 * | 4428 * |
4357 * See [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE], | 4429 * See [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE], |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4479 } else { | 4551 } else { |
4480 newStrMember = "$prefix'${missingOverridesArray[i].displayName}'"; | 4552 newStrMember = "$prefix'${missingOverridesArray[i].displayName}'"; |
4481 } | 4553 } |
4482 stringMembersArrayListSet.add(newStrMember); | 4554 stringMembersArrayListSet.add(newStrMember); |
4483 } | 4555 } |
4484 List<String> stringMembersArray = new List.from(stringMembersArrayListSet); | 4556 List<String> stringMembersArray = new List.from(stringMembersArrayListSet); |
4485 AnalysisErrorWithProperties analysisError; | 4557 AnalysisErrorWithProperties analysisError; |
4486 if (stringMembersArray.length == 1) { | 4558 if (stringMembersArray.length == 1) { |
4487 analysisError = _errorReporter.newErrorWithProperties( | 4559 analysisError = _errorReporter.newErrorWithProperties( |
4488 StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE, | 4560 StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE, |
4489 classNameNode, [stringMembersArray[0]]); | 4561 classNameNode, |
| 4562 [stringMembersArray[0]]); |
4490 } else if (stringMembersArray.length == 2) { | 4563 } else if (stringMembersArray.length == 2) { |
4491 analysisError = _errorReporter.newErrorWithProperties( | 4564 analysisError = _errorReporter.newErrorWithProperties( |
4492 StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_TWO, | 4565 StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_TWO, |
4493 classNameNode, [stringMembersArray[0], stringMembersArray[1]]); | 4566 classNameNode, |
| 4567 [stringMembersArray[0], stringMembersArray[1]]); |
4494 } else if (stringMembersArray.length == 3) { | 4568 } else if (stringMembersArray.length == 3) { |
4495 analysisError = _errorReporter.newErrorWithProperties( | 4569 analysisError = _errorReporter.newErrorWithProperties( |
4496 StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_THREE, | 4570 StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_THREE, |
4497 classNameNode, [ | 4571 classNameNode, [ |
4498 stringMembersArray[0], | 4572 stringMembersArray[0], |
4499 stringMembersArray[1], | 4573 stringMembersArray[1], |
4500 stringMembersArray[2] | 4574 stringMembersArray[2] |
4501 ]); | 4575 ]); |
4502 } else if (stringMembersArray.length == 4) { | 4576 } else if (stringMembersArray.length == 4) { |
4503 analysisError = _errorReporter.newErrorWithProperties( | 4577 analysisError = _errorReporter.newErrorWithProperties( |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4610 if (!identical(statement.beginToken, literal.beginToken)) { | 4684 if (!identical(statement.beginToken, literal.beginToken)) { |
4611 return false; | 4685 return false; |
4612 } | 4686 } |
4613 // report problem | 4687 // report problem |
4614 _errorReporter.reportErrorForNode( | 4688 _errorReporter.reportErrorForNode( |
4615 CompileTimeErrorCode.NON_CONST_MAP_AS_EXPRESSION_STATEMENT, literal); | 4689 CompileTimeErrorCode.NON_CONST_MAP_AS_EXPRESSION_STATEMENT, literal); |
4616 return true; | 4690 return true; |
4617 } | 4691 } |
4618 | 4692 |
4619 /** | 4693 /** |
| 4694 * If the given assert [statement] specifies a message, verify that its type |
| 4695 * is assignable to `String`. |
| 4696 * |
| 4697 * See [StaticTypeWarningCode.ASSERT_MESSAGE_NON_STRING]. |
| 4698 */ |
| 4699 void _checkForNonStringMessage(AssertStatement statement) { |
| 4700 Expression expression = statement.message; |
| 4701 if (expression != null) { |
| 4702 if (!enableAssertMessage) { |
| 4703 _errorReporter.reportErrorForNode( |
| 4704 CompileTimeErrorCode.EXTRA_ARGUMENT_TO_ASSERT, expression); |
| 4705 return; |
| 4706 } |
| 4707 DartType type = getStaticType(expression); |
| 4708 if (!type.isAssignableTo(_stringType)) { |
| 4709 _errorReporter.reportErrorForNode( |
| 4710 StaticTypeWarningCode.ASSERT_MESSAGE_NON_STRING, expression); |
| 4711 } |
| 4712 } |
| 4713 } |
| 4714 |
| 4715 /** |
4620 * Verify that the given method [declaration] of operator `[]=`, has `void` | 4716 * Verify that the given method [declaration] of operator `[]=`, has `void` |
4621 * return type. | 4717 * return type. |
4622 * | 4718 * |
4623 * See [StaticWarningCode.NON_VOID_RETURN_FOR_OPERATOR]. | 4719 * See [StaticWarningCode.NON_VOID_RETURN_FOR_OPERATOR]. |
4624 */ | 4720 */ |
4625 bool _checkForNonVoidReturnTypeForOperator(MethodDeclaration declaration) { | 4721 bool _checkForNonVoidReturnTypeForOperator(MethodDeclaration declaration) { |
4626 // check that []= operator | 4722 // check that []= operator |
4627 SimpleIdentifier name = declaration.name; | 4723 SimpleIdentifier name = declaration.name; |
4628 if (name.name != "[]=") { | 4724 if (name.name != "[]=") { |
4629 return false; | 4725 return false; |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4819 RedirectingConstructorInvocation invocation = initializer; | 4915 RedirectingConstructorInvocation invocation = initializer; |
4820 ConstructorElement redirectingElement = invocation.staticElement; | 4916 ConstructorElement redirectingElement = invocation.staticElement; |
4821 if (redirectingElement == null) { | 4917 if (redirectingElement == null) { |
4822 String enclosingTypeName = _enclosingClass.displayName; | 4918 String enclosingTypeName = _enclosingClass.displayName; |
4823 String constructorStrName = enclosingTypeName; | 4919 String constructorStrName = enclosingTypeName; |
4824 if (invocation.constructorName != null) { | 4920 if (invocation.constructorName != null) { |
4825 constructorStrName += ".${invocation.constructorName.name}"; | 4921 constructorStrName += ".${invocation.constructorName.name}"; |
4826 } | 4922 } |
4827 _errorReporter.reportErrorForNode( | 4923 _errorReporter.reportErrorForNode( |
4828 CompileTimeErrorCode.REDIRECT_GENERATIVE_TO_MISSING_CONSTRUCTOR, | 4924 CompileTimeErrorCode.REDIRECT_GENERATIVE_TO_MISSING_CONSTRUCTOR, |
4829 invocation, [constructorStrName, enclosingTypeName]); | 4925 invocation, |
| 4926 [constructorStrName, enclosingTypeName]); |
4830 } else { | 4927 } else { |
4831 if (redirectingElement.isFactory) { | 4928 if (redirectingElement.isFactory) { |
4832 _errorReporter.reportErrorForNode( | 4929 _errorReporter.reportErrorForNode( |
4833 CompileTimeErrorCode.REDIRECT_GENERATIVE_TO_NON_GENERATIVE_CON
STRUCTOR, | 4930 CompileTimeErrorCode.REDIRECT_GENERATIVE_TO_NON_GENERATIVE_CON
STRUCTOR, |
4834 initializer); | 4931 initializer); |
4835 } | 4932 } |
4836 } | 4933 } |
4837 } | 4934 } |
4838 numRedirections++; | 4935 numRedirections++; |
4839 } | 4936 } |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4967 staticReturnType, | 5064 staticReturnType, |
4968 expectedReturnType, | 5065 expectedReturnType, |
4969 _enclosingFunction.displayName | 5066 _enclosingFunction.displayName |
4970 ]); | 5067 ]); |
4971 return true; | 5068 return true; |
4972 } | 5069 } |
4973 if (staticReturnType.isAssignableTo(expectedReturnType)) { | 5070 if (staticReturnType.isAssignableTo(expectedReturnType)) { |
4974 return false; | 5071 return false; |
4975 } | 5072 } |
4976 _errorReporter.reportTypeErrorForNode( | 5073 _errorReporter.reportTypeErrorForNode( |
4977 StaticTypeWarningCode.RETURN_OF_INVALID_TYPE, returnExpression, [ | 5074 StaticTypeWarningCode.RETURN_OF_INVALID_TYPE, |
4978 staticReturnType, | 5075 returnExpression, |
4979 expectedReturnType, | 5076 [staticReturnType, expectedReturnType, _enclosingFunction.displayName]); |
4980 _enclosingFunction.displayName | |
4981 ]); | |
4982 return true; | 5077 return true; |
4983 // TODO(brianwilkerson) Define a hint corresponding to the warning and | 5078 // TODO(brianwilkerson) Define a hint corresponding to the warning and |
4984 // report it if appropriate. | 5079 // report it if appropriate. |
4985 // Type propagatedReturnType = returnExpression.getPropagatedType(); | 5080 // Type propagatedReturnType = returnExpression.getPropagatedType(); |
4986 // boolean isPropagatedAssignable = propagatedReturnType.isAssignableTo(e
xpectedReturnType); | 5081 // boolean isPropagatedAssignable = propagatedReturnType.isAssignableTo(e
xpectedReturnType); |
4987 // if (isStaticAssignable || isPropagatedAssignable) { | 5082 // if (isStaticAssignable || isPropagatedAssignable) { |
4988 // return false; | 5083 // return false; |
4989 // } | 5084 // } |
4990 // errorReporter.reportTypeErrorForNode( | 5085 // errorReporter.reportTypeErrorForNode( |
4991 // StaticTypeWarningCode.RETURN_OF_INVALID_TYPE, | 5086 // StaticTypeWarningCode.RETURN_OF_INVALID_TYPE, |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5046 SwitchCase switchCase = switchMember as SwitchCase; | 5141 SwitchCase switchCase = switchMember as SwitchCase; |
5047 // prepare 'case' type | 5142 // prepare 'case' type |
5048 Expression caseExpression = switchCase.expression; | 5143 Expression caseExpression = switchCase.expression; |
5049 DartType caseType = getStaticType(caseExpression); | 5144 DartType caseType = getStaticType(caseExpression); |
5050 // check types | 5145 // check types |
5051 if (expressionType.isAssignableTo(caseType)) { | 5146 if (expressionType.isAssignableTo(caseType)) { |
5052 return false; | 5147 return false; |
5053 } | 5148 } |
5054 // report problem | 5149 // report problem |
5055 _errorReporter.reportErrorForNode( | 5150 _errorReporter.reportErrorForNode( |
5056 StaticWarningCode.SWITCH_EXPRESSION_NOT_ASSIGNABLE, expression, [ | 5151 StaticWarningCode.SWITCH_EXPRESSION_NOT_ASSIGNABLE, |
5057 expressionType, | 5152 expression, |
5058 caseType | 5153 [expressionType, caseType]); |
5059 ]); | |
5060 return true; | 5154 return true; |
5061 } | 5155 } |
5062 return false; | 5156 return false; |
5063 } | 5157 } |
5064 | 5158 |
5065 /** | 5159 /** |
5066 * Verify that the given function type [alias] does not reference itself | 5160 * Verify that the given function type [alias] does not reference itself |
5067 * directly. | 5161 * directly. |
5068 * | 5162 * |
5069 * See [CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REFERENCE_ITSELF]. | 5163 * See [CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REFERENCE_ITSELF]. |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5176 DartType bound = element.bound; | 5270 DartType bound = element.bound; |
5177 if (bound == null) { | 5271 if (bound == null) { |
5178 return false; | 5272 return false; |
5179 } | 5273 } |
5180 // OK, type parameter is not supertype of its bound | 5274 // OK, type parameter is not supertype of its bound |
5181 if (!bound.isMoreSpecificThan(element.type)) { | 5275 if (!bound.isMoreSpecificThan(element.type)) { |
5182 return false; | 5276 return false; |
5183 } | 5277 } |
5184 // report problem | 5278 // report problem |
5185 _errorReporter.reportErrorForNode( | 5279 _errorReporter.reportErrorForNode( |
5186 StaticTypeWarningCode.TYPE_PARAMETER_SUPERTYPE_OF_ITS_BOUND, parameter, | 5280 StaticTypeWarningCode.TYPE_PARAMETER_SUPERTYPE_OF_ITS_BOUND, |
| 5281 parameter, |
5187 [element.displayName]); | 5282 [element.displayName]); |
5188 return true; | 5283 return true; |
5189 } | 5284 } |
5190 | 5285 |
5191 /** | 5286 /** |
5192 * Check that if the given generative [constructor] has neither an explicit | 5287 * Check that if the given generative [constructor] has neither an explicit |
5193 * super constructor invocation nor a redirecting constructor invocation, that | 5288 * super constructor invocation nor a redirecting constructor invocation, that |
5194 * the superclass has a default generative constructor. | 5289 * the superclass has a default generative constructor. |
5195 * | 5290 * |
5196 * See [CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALIZER_DEFAULT], | 5291 * See [CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALIZER_DEFAULT], |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5232 if (superType == null) { | 5327 if (superType == null) { |
5233 return false; | 5328 return false; |
5234 } | 5329 } |
5235 ClassElement superElement = superType.element; | 5330 ClassElement superElement = superType.element; |
5236 ConstructorElement superUnnamedConstructor = | 5331 ConstructorElement superUnnamedConstructor = |
5237 superElement.unnamedConstructor; | 5332 superElement.unnamedConstructor; |
5238 if (superUnnamedConstructor != null) { | 5333 if (superUnnamedConstructor != null) { |
5239 if (superUnnamedConstructor.isFactory) { | 5334 if (superUnnamedConstructor.isFactory) { |
5240 _errorReporter.reportErrorForNode( | 5335 _errorReporter.reportErrorForNode( |
5241 CompileTimeErrorCode.NON_GENERATIVE_CONSTRUCTOR, | 5336 CompileTimeErrorCode.NON_GENERATIVE_CONSTRUCTOR, |
5242 constructor.returnType, [superUnnamedConstructor]); | 5337 constructor.returnType, |
| 5338 [superUnnamedConstructor]); |
5243 return true; | 5339 return true; |
5244 } | 5340 } |
5245 if (!superUnnamedConstructor.isDefaultConstructor || | 5341 if (!superUnnamedConstructor.isDefaultConstructor || |
5246 !_enclosingClass | 5342 !_enclosingClass |
5247 .isSuperConstructorAccessible(superUnnamedConstructor)) { | 5343 .isSuperConstructorAccessible(superUnnamedConstructor)) { |
5248 int offset; | 5344 int offset; |
5249 int length; | 5345 int length; |
5250 { | 5346 { |
5251 Identifier returnType = constructor.returnType; | 5347 Identifier returnType = constructor.returnType; |
5252 SimpleIdentifier name = constructor.name; | 5348 SimpleIdentifier name = constructor.name; |
5253 offset = returnType.offset; | 5349 offset = returnType.offset; |
5254 length = (name != null ? name.end : returnType.end) - offset; | 5350 length = (name != null ? name.end : returnType.end) - offset; |
5255 } | 5351 } |
5256 _errorReporter.reportErrorForOffset( | 5352 _errorReporter.reportErrorForOffset( |
5257 CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_EXPLICIT, offset, | 5353 CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_EXPLICIT, |
5258 length, [superType.displayName]); | 5354 offset, |
| 5355 length, |
| 5356 [superType.displayName]); |
5259 } | 5357 } |
5260 return false; | 5358 return false; |
5261 } | 5359 } |
5262 _errorReporter.reportErrorForNode( | 5360 _errorReporter.reportErrorForNode( |
5263 CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALIZER_DEFAULT, | 5361 CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALIZER_DEFAULT, |
5264 constructor.returnType, [superElement.name]); | 5362 constructor.returnType, |
| 5363 [superElement.name]); |
5265 return true; | 5364 return true; |
5266 } | 5365 } |
5267 | 5366 |
5268 /** | 5367 /** |
5269 * Check that if the given [name] is a reference to a static member it is | 5368 * 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. | 5369 * defined in the enclosing class rather than in a superclass. |
5271 * | 5370 * |
5272 * See [StaticTypeWarningCode.UNQUALIFIED_REFERENCE_TO_NON_LOCAL_STATIC_MEMBER
]. | 5371 * See [StaticTypeWarningCode.UNQUALIFIED_REFERENCE_TO_NON_LOCAL_STATIC_MEMBER
]. |
5273 */ | 5372 */ |
5274 bool _checkForUnqualifiedReferenceToNonLocalStaticMember( | 5373 bool _checkForUnqualifiedReferenceToNonLocalStaticMember( |
5275 SimpleIdentifier name) { | 5374 SimpleIdentifier name) { |
5276 Element element = name.staticElement; | 5375 Element element = name.staticElement; |
5277 if (element == null || element is TypeParameterElement) { | 5376 if (element == null || element is TypeParameterElement) { |
5278 return false; | 5377 return false; |
5279 } | 5378 } |
5280 Element enclosingElement = element.enclosingElement; | 5379 Element enclosingElement = element.enclosingElement; |
5281 if (enclosingElement is! ClassElement) { | 5380 if (enclosingElement is! ClassElement) { |
5282 return false; | 5381 return false; |
5283 } | 5382 } |
5284 if ((element is MethodElement && !element.isStatic) || | 5383 if ((element is MethodElement && !element.isStatic) || |
5285 (element is PropertyAccessorElement && !element.isStatic)) { | 5384 (element is PropertyAccessorElement && !element.isStatic)) { |
5286 return false; | 5385 return false; |
5287 } | 5386 } |
5288 if (identical(enclosingElement, _enclosingClass)) { | 5387 if (identical(enclosingElement, _enclosingClass)) { |
5289 return false; | 5388 return false; |
5290 } | 5389 } |
5291 _errorReporter.reportErrorForNode( | 5390 _errorReporter.reportErrorForNode( |
5292 StaticTypeWarningCode.UNQUALIFIED_REFERENCE_TO_NON_LOCAL_STATIC_MEMBER, | 5391 StaticTypeWarningCode.UNQUALIFIED_REFERENCE_TO_NON_LOCAL_STATIC_MEMBER, |
5293 name, [name.name]); | 5392 name, |
| 5393 [name.name]); |
5294 return true; | 5394 return true; |
5295 } | 5395 } |
5296 | 5396 |
5297 void _checkForValidField(FieldFormalParameter parameter) { | 5397 void _checkForValidField(FieldFormalParameter parameter) { |
5298 ParameterElement element = parameter.element; | 5398 ParameterElement element = parameter.element; |
5299 if (element is FieldFormalParameterElement) { | 5399 if (element is FieldFormalParameterElement) { |
5300 FieldElement fieldElement = element.field; | 5400 FieldElement fieldElement = element.field; |
5301 if (fieldElement == null || fieldElement.isSynthetic) { | 5401 if (fieldElement == null || fieldElement.isSynthetic) { |
5302 _errorReporter.reportErrorForNode( | 5402 _errorReporter.reportErrorForNode( |
5303 CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_NON_EXISTENT_FIELD, | 5403 CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_NON_EXISTENT_FIELD, |
5304 parameter, [parameter.identifier.name]); | 5404 parameter, |
| 5405 [parameter.identifier.name]); |
5305 } else { | 5406 } else { |
5306 ParameterElement parameterElement = parameter.element; | 5407 ParameterElement parameterElement = parameter.element; |
5307 if (parameterElement is FieldFormalParameterElementImpl) { | 5408 if (parameterElement is FieldFormalParameterElementImpl) { |
5308 FieldFormalParameterElementImpl fieldFormal = parameterElement; | 5409 FieldFormalParameterElementImpl fieldFormal = parameterElement; |
5309 DartType declaredType = fieldFormal.type; | 5410 DartType declaredType = fieldFormal.type; |
5310 DartType fieldType = fieldElement.type; | 5411 DartType fieldType = fieldElement.type; |
5311 if (fieldElement.isSynthetic) { | 5412 if (fieldElement.isSynthetic) { |
5312 _errorReporter.reportErrorForNode( | 5413 _errorReporter.reportErrorForNode( |
5313 CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_NON_EXISTENT_FIELD, | 5414 CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_NON_EXISTENT_FIELD, |
5314 parameter, [parameter.identifier.name]); | 5415 parameter, |
| 5416 [parameter.identifier.name]); |
5315 } else if (fieldElement.isStatic) { | 5417 } else if (fieldElement.isStatic) { |
5316 _errorReporter.reportErrorForNode( | 5418 _errorReporter.reportErrorForNode( |
5317 CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_STATIC_FIELD, | 5419 CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_STATIC_FIELD, |
5318 parameter, [parameter.identifier.name]); | 5420 parameter, |
| 5421 [parameter.identifier.name]); |
5319 } else if (declaredType != null && | 5422 } else if (declaredType != null && |
5320 fieldType != null && | 5423 fieldType != null && |
5321 !declaredType.isAssignableTo(fieldType)) { | 5424 !declaredType.isAssignableTo(fieldType)) { |
5322 _errorReporter.reportTypeErrorForNode( | 5425 _errorReporter.reportTypeErrorForNode( |
5323 StaticWarningCode.FIELD_INITIALIZING_FORMAL_NOT_ASSIGNABLE, | 5426 StaticWarningCode.FIELD_INITIALIZING_FORMAL_NOT_ASSIGNABLE, |
5324 parameter, [declaredType, fieldType]); | 5427 parameter, |
| 5428 [declaredType, fieldType]); |
5325 } | 5429 } |
5326 } else { | 5430 } else { |
5327 if (fieldElement.isSynthetic) { | 5431 if (fieldElement.isSynthetic) { |
5328 _errorReporter.reportErrorForNode( | 5432 _errorReporter.reportErrorForNode( |
5329 CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_NON_EXISTENT_FIELD, | 5433 CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_NON_EXISTENT_FIELD, |
5330 parameter, [parameter.identifier.name]); | 5434 parameter, |
| 5435 [parameter.identifier.name]); |
5331 } else if (fieldElement.isStatic) { | 5436 } else if (fieldElement.isStatic) { |
5332 _errorReporter.reportErrorForNode( | 5437 _errorReporter.reportErrorForNode( |
5333 CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_STATIC_FIELD, | 5438 CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_STATIC_FIELD, |
5334 parameter, [parameter.identifier.name]); | 5439 parameter, |
| 5440 [parameter.identifier.name]); |
5335 } | 5441 } |
5336 } | 5442 } |
5337 } | 5443 } |
5338 } | 5444 } |
5339 // else { | 5445 // else { |
5340 // // TODO(jwren) Report error, constructor initializer variable is a top
level element | 5446 // // TODO(jwren) Report error, constructor initializer variable is a top
level element |
5341 // // (Either here or in ErrorVerifier.checkForAllFinalInitializedErrorCo
des) | 5447 // // (Either here or in ErrorVerifier.checkForAllFinalInitializedErrorCo
des) |
5342 // } | 5448 // } |
5343 } | 5449 } |
5344 | 5450 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5400 "<<" == name || | 5506 "<<" == name || |
5401 ">>" == name || | 5507 ">>" == name || |
5402 "[]" == name) { | 5508 "[]" == name) { |
5403 expected = 1; | 5509 expected = 1; |
5404 } else if ("~" == name) { | 5510 } else if ("~" == name) { |
5405 expected = 0; | 5511 expected = 0; |
5406 } | 5512 } |
5407 if (expected != -1 && numParameters != expected) { | 5513 if (expected != -1 && numParameters != expected) { |
5408 _errorReporter.reportErrorForNode( | 5514 _errorReporter.reportErrorForNode( |
5409 CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_OPERATOR, | 5515 CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_OPERATOR, |
5410 nameNode, [name, expected, numParameters]); | 5516 nameNode, |
| 5517 [name, expected, numParameters]); |
5411 return true; | 5518 return true; |
5412 } | 5519 } |
5413 // check for operator "-" | 5520 // check for operator "-" |
5414 if ("-" == name && numParameters > 1) { | 5521 if ("-" == name && numParameters > 1) { |
5415 _errorReporter.reportErrorForNode( | 5522 _errorReporter.reportErrorForNode( |
5416 CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_OPERATOR_MINUS, | 5523 CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_OPERATOR_MINUS, |
5417 nameNode, [numParameters]); | 5524 nameNode, |
| 5525 [numParameters]); |
5418 return true; | 5526 return true; |
5419 } | 5527 } |
5420 // OK | 5528 // OK |
5421 return false; | 5529 return false; |
5422 } | 5530 } |
5423 | 5531 |
5424 /** | 5532 /** |
5425 * Verify that the given setter [parameterList] has only one required | 5533 * Verify that the given setter [parameterList] has only one required |
5426 * parameter. The [setterName] is the name of the setter to report problems | 5534 * parameter. The [setterName] is the name of the setter to report problems |
5427 * on. | 5535 * on. |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5469 impliedReturnType = staticYieldedType; | 5577 impliedReturnType = staticYieldedType; |
5470 } else if (_enclosingFunction.isAsynchronous) { | 5578 } else if (_enclosingFunction.isAsynchronous) { |
5471 impliedReturnType = | 5579 impliedReturnType = |
5472 _typeProvider.streamType.substitute4(<DartType>[staticYieldedType]); | 5580 _typeProvider.streamType.substitute4(<DartType>[staticYieldedType]); |
5473 } else { | 5581 } else { |
5474 impliedReturnType = | 5582 impliedReturnType = |
5475 _typeProvider.iterableType.substitute4(<DartType>[staticYieldedType]); | 5583 _typeProvider.iterableType.substitute4(<DartType>[staticYieldedType]); |
5476 } | 5584 } |
5477 if (!impliedReturnType.isAssignableTo(declaredReturnType)) { | 5585 if (!impliedReturnType.isAssignableTo(declaredReturnType)) { |
5478 _errorReporter.reportTypeErrorForNode( | 5586 _errorReporter.reportTypeErrorForNode( |
5479 StaticTypeWarningCode.YIELD_OF_INVALID_TYPE, yieldExpression, [ | 5587 StaticTypeWarningCode.YIELD_OF_INVALID_TYPE, |
5480 impliedReturnType, | 5588 yieldExpression, |
5481 declaredReturnType | 5589 [impliedReturnType, declaredReturnType]); |
5482 ]); | |
5483 return true; | 5590 return true; |
5484 } | 5591 } |
5485 if (isYieldEach) { | 5592 if (isYieldEach) { |
5486 // Since the declared return type might have been "dynamic", we need to | 5593 // Since the declared return type might have been "dynamic", we need to |
5487 // also check that the implied return type is assignable to generic | 5594 // also check that the implied return type is assignable to generic |
5488 // Stream/Iterable. | 5595 // Stream/Iterable. |
5489 DartType requiredReturnType; | 5596 DartType requiredReturnType; |
5490 if (_enclosingFunction.isAsynchronous) { | 5597 if (_enclosingFunction.isAsynchronous) { |
5491 requiredReturnType = _typeProvider.streamDynamicType; | 5598 requiredReturnType = _typeProvider.streamDynamicType; |
5492 } else { | 5599 } else { |
5493 requiredReturnType = _typeProvider.iterableDynamicType; | 5600 requiredReturnType = _typeProvider.iterableDynamicType; |
5494 } | 5601 } |
5495 if (!impliedReturnType.isAssignableTo(requiredReturnType)) { | 5602 if (!impliedReturnType.isAssignableTo(requiredReturnType)) { |
5496 _errorReporter.reportTypeErrorForNode( | 5603 _errorReporter.reportTypeErrorForNode( |
5497 StaticTypeWarningCode.YIELD_OF_INVALID_TYPE, yieldExpression, [ | 5604 StaticTypeWarningCode.YIELD_OF_INVALID_TYPE, |
5498 impliedReturnType, | 5605 yieldExpression, |
5499 requiredReturnType | 5606 [impliedReturnType, requiredReturnType]); |
5500 ]); | |
5501 return true; | 5607 return true; |
5502 } | 5608 } |
5503 } | 5609 } |
5504 return false; | 5610 return false; |
5505 } | 5611 } |
5506 | 5612 |
5507 /** | 5613 /** |
5508 * Verify that if the given class [declaration] implements the class Function | 5614 * Verify that if the given class [declaration] implements the class Function |
5509 * that it has a concrete implementation of the call method. | 5615 * that it has a concrete implementation of the call method. |
5510 * | 5616 * |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5555 ImplementsClause implementsClause = declaration.implementsClause; | 5661 ImplementsClause implementsClause = declaration.implementsClause; |
5556 if (implementsClause == null) { | 5662 if (implementsClause == null) { |
5557 return false; | 5663 return false; |
5558 } | 5664 } |
5559 // check interfaces | 5665 // check interfaces |
5560 bool hasProblem = false; | 5666 bool hasProblem = false; |
5561 for (TypeName interfaceNode in implementsClause.interfaces) { | 5667 for (TypeName interfaceNode in implementsClause.interfaces) { |
5562 if (interfaceNode.type == superType) { | 5668 if (interfaceNode.type == superType) { |
5563 hasProblem = true; | 5669 hasProblem = true; |
5564 _errorReporter.reportErrorForNode( | 5670 _errorReporter.reportErrorForNode( |
5565 CompileTimeErrorCode.IMPLEMENTS_SUPER_CLASS, interfaceNode, | 5671 CompileTimeErrorCode.IMPLEMENTS_SUPER_CLASS, |
| 5672 interfaceNode, |
5566 [superType.displayName]); | 5673 [superType.displayName]); |
5567 } | 5674 } |
5568 } | 5675 } |
5569 // done | 5676 // done |
5570 return hasProblem; | 5677 return hasProblem; |
5571 } | 5678 } |
5572 | 5679 |
5573 DartType _computeReturnTypeForMethod(Expression returnExpression) { | 5680 DartType _computeReturnTypeForMethod(Expression returnExpression) { |
5574 // This method should never be called for generators, since generators are | 5681 // This method should never be called for generators, since generators are |
5575 // never allowed to contain return statements with expressions. | 5682 // never allowed to contain return statements with expressions. |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5876 // "A, B, C, D, A" | 5983 // "A, B, C, D, A" |
5877 String separator = ", "; | 5984 String separator = ", "; |
5878 StringBuffer buffer = new StringBuffer(); | 5985 StringBuffer buffer = new StringBuffer(); |
5879 for (int i = 0; i < size; i++) { | 5986 for (int i = 0; i < size; i++) { |
5880 buffer.write(path[i].displayName); | 5987 buffer.write(path[i].displayName); |
5881 buffer.write(separator); | 5988 buffer.write(separator); |
5882 } | 5989 } |
5883 buffer.write(element.displayName); | 5990 buffer.write(element.displayName); |
5884 _errorReporter.reportErrorForOffset( | 5991 _errorReporter.reportErrorForOffset( |
5885 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE, | 5992 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE, |
5886 _enclosingClass.nameOffset, enclosingClassName.length, [ | 5993 _enclosingClass.nameOffset, |
5887 enclosingClassName, | 5994 enclosingClassName.length, |
5888 buffer.toString() | 5995 [enclosingClassName, buffer.toString()]); |
5889 ]); | |
5890 return true; | 5996 return true; |
5891 } else { | 5997 } else { |
5892 // RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_EXTENDS or | 5998 // RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_EXTENDS or |
5893 // RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_IMPLEMENTS or | 5999 // RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_IMPLEMENTS or |
5894 // RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_WITH | 6000 // RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_WITH |
5895 _errorReporter.reportErrorForOffset(_getBaseCaseErrorCode(element), | 6001 _errorReporter.reportErrorForOffset( |
5896 _enclosingClass.nameOffset, enclosingClassName.length, | 6002 _getBaseCaseErrorCode(element), |
| 6003 _enclosingClass.nameOffset, |
| 6004 enclosingClassName.length, |
5897 [enclosingClassName]); | 6005 [enclosingClassName]); |
5898 return true; | 6006 return true; |
5899 } | 6007 } |
5900 } | 6008 } |
5901 if (path.indexOf(element) > 0) { | 6009 if (path.indexOf(element) > 0) { |
5902 return false; | 6010 return false; |
5903 } | 6011 } |
5904 path.add(element); | 6012 path.add(element); |
5905 // n-case | 6013 // n-case |
5906 InterfaceType supertype = element.supertype; | 6014 InterfaceType supertype = element.supertype; |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5992 toCheck.add(type.element); | 6100 toCheck.add(type.element); |
5993 // type arguments | 6101 // type arguments |
5994 if (type is InterfaceType) { | 6102 if (type is InterfaceType) { |
5995 InterfaceType interfaceType = type; | 6103 InterfaceType interfaceType = type; |
5996 for (DartType typeArgument in interfaceType.typeArguments) { | 6104 for (DartType typeArgument in interfaceType.typeArguments) { |
5997 _addTypeToCheck(typeArgument); | 6105 _addTypeToCheck(typeArgument); |
5998 } | 6106 } |
5999 } | 6107 } |
6000 } | 6108 } |
6001 } | 6109 } |
OLD | NEW |