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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 object providing access to the types defined by the language. | 68 * The object providing access to the types defined by the language. |
69 */ | 69 */ |
70 final TypeProvider _typeProvider; | 70 final TypeProvider _typeProvider; |
71 | 71 |
72 /** | 72 /** |
| 73 * The type system primitives |
| 74 */ |
| 75 TypeSystem _typeSystem; |
| 76 |
| 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 /** |
78 * A flag indicating whether the visitor is currently within a constructor | 83 * A flag indicating whether the visitor is currently within a constructor |
79 * declaration that is 'const'. | 84 * declaration that is 'const'. |
80 * | 85 * |
81 * See [visitConstructorDeclaration]. | 86 * See [visitConstructorDeclaration]. |
82 */ | 87 */ |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 HashSet<String> _namesForReferenceToDeclaredVariableInInitializer = | 253 HashSet<String> _namesForReferenceToDeclaredVariableInInitializer = |
249 new HashSet<String>(); | 254 new HashSet<String>(); |
250 | 255 |
251 /** | 256 /** |
252 * A list of types used by the [CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS] | 257 * A list of types used by the [CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS] |
253 * and [CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS] error codes. | 258 * and [CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS] error codes. |
254 */ | 259 */ |
255 List<InterfaceType> _DISALLOWED_TYPES_TO_EXTEND_OR_IMPLEMENT; | 260 List<InterfaceType> _DISALLOWED_TYPES_TO_EXTEND_OR_IMPLEMENT; |
256 | 261 |
257 /** | 262 /** |
| 263 * If `true`, mixins are allowed to inherit from types other than Object, and |
| 264 * are allowed to reference `super`. |
| 265 */ |
| 266 final bool enableSuperMixins; |
| 267 |
| 268 /** |
258 * Initialize a newly created error verifier. | 269 * Initialize a newly created error verifier. |
259 */ | 270 */ |
260 ErrorVerifier(this._errorReporter, this._currentLibrary, this._typeProvider, | 271 ErrorVerifier(this._errorReporter, this._currentLibrary, this._typeProvider, |
261 this._inheritanceManager) { | 272 this._inheritanceManager, this.enableSuperMixins) { |
262 this._isInSystemLibrary = _currentLibrary.source.isInSystemLibrary; | 273 this._isInSystemLibrary = _currentLibrary.source.isInSystemLibrary; |
263 this._hasExtUri = _currentLibrary.hasExtUri; | 274 this._hasExtUri = _currentLibrary.hasExtUri; |
264 _isEnclosingConstructorConst = false; | 275 _isEnclosingConstructorConst = false; |
265 _isInCatchClause = false; | 276 _isInCatchClause = false; |
266 _isInStaticVariableDeclaration = false; | 277 _isInStaticVariableDeclaration = false; |
267 _isInInstanceVariableDeclaration = false; | 278 _isInInstanceVariableDeclaration = false; |
268 _isInInstanceVariableInitializer = false; | 279 _isInInstanceVariableInitializer = false; |
269 _isInConstructorInitializer = false; | 280 _isInConstructorInitializer = false; |
270 _isInStaticMethod = false; | 281 _isInStaticMethod = false; |
271 _boolType = _typeProvider.boolType; | 282 _boolType = _typeProvider.boolType; |
272 _intType = _typeProvider.intType; | 283 _intType = _typeProvider.intType; |
273 _DISALLOWED_TYPES_TO_EXTEND_OR_IMPLEMENT = _typeProvider.nonSubtypableTypes; | 284 _DISALLOWED_TYPES_TO_EXTEND_OR_IMPLEMENT = _typeProvider.nonSubtypableTypes; |
| 285 _typeSystem = _currentLibrary.context.typeSystem; |
274 } | 286 } |
275 | 287 |
276 @override | 288 @override |
277 Object visitAnnotation(Annotation node) { | 289 Object visitAnnotation(Annotation node) { |
278 _checkForInvalidAnnotationFromDeferredLibrary(node); | 290 _checkForInvalidAnnotationFromDeferredLibrary(node); |
279 return super.visitAnnotation(node); | 291 return super.visitAnnotation(node); |
280 } | 292 } |
281 | 293 |
282 @override | 294 @override |
283 Object visitArgumentList(ArgumentList node) { | 295 Object visitArgumentList(ArgumentList node) { |
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
571 return super.visitDefaultFormalParameter(node); | 583 return super.visitDefaultFormalParameter(node); |
572 } | 584 } |
573 | 585 |
574 @override | 586 @override |
575 Object visitDoStatement(DoStatement node) { | 587 Object visitDoStatement(DoStatement node) { |
576 _checkForNonBoolCondition(node.condition); | 588 _checkForNonBoolCondition(node.condition); |
577 return super.visitDoStatement(node); | 589 return super.visitDoStatement(node); |
578 } | 590 } |
579 | 591 |
580 @override | 592 @override |
| 593 Object visitEnumDeclaration(EnumDeclaration node) { |
| 594 ClassElement outerClass = _enclosingClass; |
| 595 try { |
| 596 _isInNativeClass = false; |
| 597 _enclosingClass = node.element; |
| 598 return super.visitEnumDeclaration(node); |
| 599 } finally { |
| 600 _enclosingClass = outerClass; |
| 601 } |
| 602 } |
| 603 |
| 604 @override |
581 Object visitExportDirective(ExportDirective node) { | 605 Object visitExportDirective(ExportDirective node) { |
582 ExportElement exportElement = node.element; | 606 ExportElement exportElement = node.element; |
583 if (exportElement != null) { | 607 if (exportElement != null) { |
584 LibraryElement exportedLibrary = exportElement.exportedLibrary; | 608 LibraryElement exportedLibrary = exportElement.exportedLibrary; |
585 _checkForAmbiguousExport(node, exportElement, exportedLibrary); | 609 _checkForAmbiguousExport(node, exportElement, exportedLibrary); |
586 _checkForExportDuplicateLibraryName(node, exportElement, exportedLibrary); | 610 _checkForExportDuplicateLibraryName(node, exportElement, exportedLibrary); |
587 _checkForExportInternalLibrary(node, exportElement); | 611 _checkForExportInternalLibrary(node, exportElement); |
588 } | 612 } |
589 return super.visitExportDirective(node); | 613 return super.visitExportDirective(node); |
590 } | 614 } |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
852 _enclosingFunction = previousFunction; | 876 _enclosingFunction = previousFunction; |
853 _isInStaticMethod = false; | 877 _isInStaticMethod = false; |
854 } | 878 } |
855 } | 879 } |
856 | 880 |
857 @override | 881 @override |
858 Object visitMethodInvocation(MethodInvocation node) { | 882 Object visitMethodInvocation(MethodInvocation node) { |
859 Expression target = node.realTarget; | 883 Expression target = node.realTarget; |
860 SimpleIdentifier methodName = node.methodName; | 884 SimpleIdentifier methodName = node.methodName; |
861 if (target != null) { | 885 if (target != null) { |
862 bool isConditional = node.operator.type == sc.TokenType.QUESTION_PERIOD; | 886 ClassElement typeReference = ElementResolver.getTypeReference(target); |
863 ClassElement typeReference = | |
864 ElementResolver.getTypeReference(target, isConditional); | |
865 _checkForStaticAccessToInstanceMember(typeReference, methodName); | 887 _checkForStaticAccessToInstanceMember(typeReference, methodName); |
866 _checkForInstanceAccessToStaticMember(typeReference, methodName); | 888 _checkForInstanceAccessToStaticMember(typeReference, methodName); |
867 } else { | 889 } else { |
868 _checkForUnqualifiedReferenceToNonLocalStaticMember(methodName); | 890 _checkForUnqualifiedReferenceToNonLocalStaticMember(methodName); |
869 } | 891 } |
870 return super.visitMethodInvocation(node); | 892 return super.visitMethodInvocation(node); |
871 } | 893 } |
872 | 894 |
873 @override | 895 @override |
874 Object visitNativeClause(NativeClause node) { | 896 Object visitNativeClause(NativeClause node) { |
(...skipping 16 matching lines...) Expand all Loading... |
891 Object visitPostfixExpression(PostfixExpression node) { | 913 Object visitPostfixExpression(PostfixExpression node) { |
892 _checkForAssignmentToFinal(node.operand); | 914 _checkForAssignmentToFinal(node.operand); |
893 _checkForIntNotAssignable(node.operand); | 915 _checkForIntNotAssignable(node.operand); |
894 return super.visitPostfixExpression(node); | 916 return super.visitPostfixExpression(node); |
895 } | 917 } |
896 | 918 |
897 @override | 919 @override |
898 Object visitPrefixedIdentifier(PrefixedIdentifier node) { | 920 Object visitPrefixedIdentifier(PrefixedIdentifier node) { |
899 if (node.parent is! Annotation) { | 921 if (node.parent is! Annotation) { |
900 ClassElement typeReference = | 922 ClassElement typeReference = |
901 ElementResolver.getTypeReference(node.prefix, false); | 923 ElementResolver.getTypeReference(node.prefix); |
902 SimpleIdentifier name = node.identifier; | 924 SimpleIdentifier name = node.identifier; |
903 _checkForStaticAccessToInstanceMember(typeReference, name); | 925 _checkForStaticAccessToInstanceMember(typeReference, name); |
904 _checkForInstanceAccessToStaticMember(typeReference, name); | 926 _checkForInstanceAccessToStaticMember(typeReference, name); |
905 } | 927 } |
906 return super.visitPrefixedIdentifier(node); | 928 return super.visitPrefixedIdentifier(node); |
907 } | 929 } |
908 | 930 |
909 @override | 931 @override |
910 Object visitPrefixExpression(PrefixExpression node) { | 932 Object visitPrefixExpression(PrefixExpression node) { |
911 sc.TokenType operatorType = node.operator.type; | 933 sc.TokenType operatorType = node.operator.type; |
912 Expression operand = node.operand; | 934 Expression operand = node.operand; |
913 if (operatorType == sc.TokenType.BANG) { | 935 if (operatorType == sc.TokenType.BANG) { |
914 _checkForNonBoolNegationExpression(operand); | 936 _checkForNonBoolNegationExpression(operand); |
915 } else if (operatorType.isIncrementOperator) { | 937 } else if (operatorType.isIncrementOperator) { |
916 _checkForAssignmentToFinal(operand); | 938 _checkForAssignmentToFinal(operand); |
917 } | 939 } |
918 _checkForIntNotAssignable(operand); | 940 _checkForIntNotAssignable(operand); |
919 return super.visitPrefixExpression(node); | 941 return super.visitPrefixExpression(node); |
920 } | 942 } |
921 | 943 |
922 @override | 944 @override |
923 Object visitPropertyAccess(PropertyAccess node) { | 945 Object visitPropertyAccess(PropertyAccess node) { |
924 bool isConditional = node.operator.type == sc.TokenType.QUESTION_PERIOD; | |
925 ClassElement typeReference = | 946 ClassElement typeReference = |
926 ElementResolver.getTypeReference(node.realTarget, isConditional); | 947 ElementResolver.getTypeReference(node.realTarget); |
927 SimpleIdentifier propertyName = node.propertyName; | 948 SimpleIdentifier propertyName = node.propertyName; |
928 _checkForStaticAccessToInstanceMember(typeReference, propertyName); | 949 _checkForStaticAccessToInstanceMember(typeReference, propertyName); |
929 _checkForInstanceAccessToStaticMember(typeReference, propertyName); | 950 _checkForInstanceAccessToStaticMember(typeReference, propertyName); |
930 return super.visitPropertyAccess(node); | 951 return super.visitPropertyAccess(node); |
931 } | 952 } |
932 | 953 |
933 @override | 954 @override |
934 Object visitRedirectingConstructorInvocation( | 955 Object visitRedirectingConstructorInvocation( |
935 RedirectingConstructorInvocation node) { | 956 RedirectingConstructorInvocation node) { |
936 _isInConstructorInitializer = true; | 957 _isInConstructorInitializer = true; |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1102 * See [StaticTypeWarningCode.EXPECTED_TWO_MAP_TYPE_ARGUMENTS]. | 1123 * See [StaticTypeWarningCode.EXPECTED_TWO_MAP_TYPE_ARGUMENTS]. |
1103 */ | 1124 */ |
1104 bool _checkExpectedTwoMapTypeArguments(TypeArgumentList typeArguments) { | 1125 bool _checkExpectedTwoMapTypeArguments(TypeArgumentList typeArguments) { |
1105 // check number of type arguments | 1126 // check number of type arguments |
1106 int num = typeArguments.arguments.length; | 1127 int num = typeArguments.arguments.length; |
1107 if (num == 2) { | 1128 if (num == 2) { |
1108 return false; | 1129 return false; |
1109 } | 1130 } |
1110 // report problem | 1131 // report problem |
1111 _errorReporter.reportErrorForNode( | 1132 _errorReporter.reportErrorForNode( |
1112 StaticTypeWarningCode.EXPECTED_TWO_MAP_TYPE_ARGUMENTS, typeArguments, | 1133 StaticTypeWarningCode.EXPECTED_TWO_MAP_TYPE_ARGUMENTS, |
| 1134 typeArguments, |
1113 [num]); | 1135 [num]); |
1114 return true; | 1136 return true; |
1115 } | 1137 } |
1116 | 1138 |
1117 /** | 1139 /** |
1118 * Verify that the given [constructor] declaration does not violate any of the | 1140 * Verify that the given [constructor] declaration does not violate any of the |
1119 * error codes relating to the initialization of fields in the enclosing | 1141 * error codes relating to the initialization of fields in the enclosing |
1120 * class. | 1142 * class. |
1121 * | 1143 * |
1122 * See [_initialFieldElementsMap], | 1144 * See [_initialFieldElementsMap], |
(...skipping 25 matching lines...) Expand all Loading... |
1148 if (parameter is FieldFormalParameter) { | 1170 if (parameter is FieldFormalParameter) { |
1149 FieldElement fieldElement = | 1171 FieldElement fieldElement = |
1150 (parameter.element as FieldFormalParameterElementImpl).field; | 1172 (parameter.element as FieldFormalParameterElementImpl).field; |
1151 INIT_STATE state = fieldElementsMap[fieldElement]; | 1173 INIT_STATE state = fieldElementsMap[fieldElement]; |
1152 if (state == INIT_STATE.NOT_INIT) { | 1174 if (state == INIT_STATE.NOT_INIT) { |
1153 fieldElementsMap[fieldElement] = INIT_STATE.INIT_IN_FIELD_FORMAL; | 1175 fieldElementsMap[fieldElement] = INIT_STATE.INIT_IN_FIELD_FORMAL; |
1154 } else if (state == INIT_STATE.INIT_IN_DECLARATION) { | 1176 } else if (state == INIT_STATE.INIT_IN_DECLARATION) { |
1155 if (fieldElement.isFinal || fieldElement.isConst) { | 1177 if (fieldElement.isFinal || fieldElement.isConst) { |
1156 _errorReporter.reportErrorForNode( | 1178 _errorReporter.reportErrorForNode( |
1157 StaticWarningCode.FINAL_INITIALIZED_IN_DECLARATION_AND_CONSTRUCT
OR, | 1179 StaticWarningCode.FINAL_INITIALIZED_IN_DECLARATION_AND_CONSTRUCT
OR, |
1158 formalParameter.identifier, [fieldElement.displayName]); | 1180 formalParameter.identifier, |
| 1181 [fieldElement.displayName]); |
1159 foundError = true; | 1182 foundError = true; |
1160 } | 1183 } |
1161 } else if (state == INIT_STATE.INIT_IN_FIELD_FORMAL) { | 1184 } else if (state == INIT_STATE.INIT_IN_FIELD_FORMAL) { |
1162 if (fieldElement.isFinal || fieldElement.isConst) { | 1185 if (fieldElement.isFinal || fieldElement.isConst) { |
1163 _errorReporter.reportErrorForNode( | 1186 _errorReporter.reportErrorForNode( |
1164 CompileTimeErrorCode.FINAL_INITIALIZED_MULTIPLE_TIMES, | 1187 CompileTimeErrorCode.FINAL_INITIALIZED_MULTIPLE_TIMES, |
1165 formalParameter.identifier, [fieldElement.displayName]); | 1188 formalParameter.identifier, |
| 1189 [fieldElement.displayName]); |
1166 foundError = true; | 1190 foundError = true; |
1167 } | 1191 } |
1168 } | 1192 } |
1169 } | 1193 } |
1170 } | 1194 } |
1171 // Visit all of the initializers | 1195 // Visit all of the initializers |
1172 NodeList<ConstructorInitializer> initializers = constructor.initializers; | 1196 NodeList<ConstructorInitializer> initializers = constructor.initializers; |
1173 for (ConstructorInitializer constructorInitializer in initializers) { | 1197 for (ConstructorInitializer constructorInitializer in initializers) { |
1174 if (constructorInitializer is RedirectingConstructorInvocation) { | 1198 if (constructorInitializer is RedirectingConstructorInvocation) { |
1175 return false; | 1199 return false; |
(...skipping 16 matching lines...) Expand all Loading... |
1192 foundError = true; | 1216 foundError = true; |
1193 } | 1217 } |
1194 } else if (state == INIT_STATE.INIT_IN_FIELD_FORMAL) { | 1218 } else if (state == INIT_STATE.INIT_IN_FIELD_FORMAL) { |
1195 _errorReporter.reportErrorForNode( | 1219 _errorReporter.reportErrorForNode( |
1196 CompileTimeErrorCode.FIELD_INITIALIZED_IN_PARAMETER_AND_INITIALI
ZER, | 1220 CompileTimeErrorCode.FIELD_INITIALIZED_IN_PARAMETER_AND_INITIALI
ZER, |
1197 fieldName); | 1221 fieldName); |
1198 foundError = true; | 1222 foundError = true; |
1199 } else if (state == INIT_STATE.INIT_IN_INITIALIZERS) { | 1223 } else if (state == INIT_STATE.INIT_IN_INITIALIZERS) { |
1200 _errorReporter.reportErrorForNode( | 1224 _errorReporter.reportErrorForNode( |
1201 CompileTimeErrorCode.FIELD_INITIALIZED_BY_MULTIPLE_INITIALIZERS, | 1225 CompileTimeErrorCode.FIELD_INITIALIZED_BY_MULTIPLE_INITIALIZERS, |
1202 fieldName, [fieldElement.displayName]); | 1226 fieldName, |
| 1227 [fieldElement.displayName]); |
1203 foundError = true; | 1228 foundError = true; |
1204 } | 1229 } |
1205 } | 1230 } |
1206 } | 1231 } |
1207 } | 1232 } |
1208 // Prepare a list of not initialized fields. | 1233 // Prepare a list of not initialized fields. |
1209 List<FieldElement> notInitFinalFields = <FieldElement>[]; | 1234 List<FieldElement> notInitFinalFields = <FieldElement>[]; |
1210 fieldElementsMap.forEach((FieldElement fieldElement, INIT_STATE state) { | 1235 fieldElementsMap.forEach((FieldElement fieldElement, INIT_STATE state) { |
1211 if (state == INIT_STATE.NOT_INIT) { | 1236 if (state == INIT_STATE.NOT_INIT) { |
1212 if (fieldElement.isFinal) { | 1237 if (fieldElement.isFinal) { |
1213 notInitFinalFields.add(fieldElement); | 1238 notInitFinalFields.add(fieldElement); |
1214 } | 1239 } |
1215 } | 1240 } |
1216 }); | 1241 }); |
1217 // Visit all of the states in the map to ensure that none were never | 1242 // Visit all of the states in the map to ensure that none were never |
1218 // initialized. | 1243 // initialized. |
1219 fieldElementsMap.forEach((FieldElement fieldElement, INIT_STATE state) { | 1244 fieldElementsMap.forEach((FieldElement fieldElement, INIT_STATE state) { |
1220 if (state == INIT_STATE.NOT_INIT) { | 1245 if (state == INIT_STATE.NOT_INIT) { |
1221 if (fieldElement.isConst) { | 1246 if (fieldElement.isConst) { |
1222 _errorReporter.reportErrorForNode( | 1247 _errorReporter.reportErrorForNode( |
1223 CompileTimeErrorCode.CONST_NOT_INITIALIZED, | 1248 CompileTimeErrorCode.CONST_NOT_INITIALIZED, |
1224 constructor.returnType, [fieldElement.name]); | 1249 constructor.returnType, |
| 1250 [fieldElement.name]); |
1225 foundError = true; | 1251 foundError = true; |
1226 } | 1252 } |
1227 } | 1253 } |
1228 }); | 1254 }); |
1229 if (notInitFinalFields.isNotEmpty) { | 1255 if (notInitFinalFields.isNotEmpty) { |
1230 foundError = true; | 1256 foundError = true; |
1231 AnalysisErrorWithProperties analysisError; | 1257 AnalysisErrorWithProperties analysisError; |
1232 if (notInitFinalFields.length == 1) { | 1258 if (notInitFinalFields.length == 1) { |
1233 analysisError = _errorReporter.newErrorWithProperties( | 1259 analysisError = _errorReporter.newErrorWithProperties( |
1234 StaticWarningCode.FINAL_NOT_INITIALIZED_CONSTRUCTOR_1, | 1260 StaticWarningCode.FINAL_NOT_INITIALIZED_CONSTRUCTOR_1, |
1235 constructor.returnType, [notInitFinalFields[0].name]); | 1261 constructor.returnType, |
| 1262 [notInitFinalFields[0].name]); |
1236 } else if (notInitFinalFields.length == 2) { | 1263 } else if (notInitFinalFields.length == 2) { |
1237 analysisError = _errorReporter.newErrorWithProperties( | 1264 analysisError = _errorReporter.newErrorWithProperties( |
1238 StaticWarningCode.FINAL_NOT_INITIALIZED_CONSTRUCTOR_2, | 1265 StaticWarningCode.FINAL_NOT_INITIALIZED_CONSTRUCTOR_2, |
1239 constructor.returnType, [ | 1266 constructor.returnType, |
1240 notInitFinalFields[0].name, | 1267 [notInitFinalFields[0].name, notInitFinalFields[1].name]); |
1241 notInitFinalFields[1].name | |
1242 ]); | |
1243 } else { | 1268 } else { |
1244 analysisError = _errorReporter.newErrorWithProperties( | 1269 analysisError = _errorReporter.newErrorWithProperties( |
1245 StaticWarningCode.FINAL_NOT_INITIALIZED_CONSTRUCTOR_3_PLUS, | 1270 StaticWarningCode.FINAL_NOT_INITIALIZED_CONSTRUCTOR_3_PLUS, |
1246 constructor.returnType, [ | 1271 constructor.returnType, [ |
1247 notInitFinalFields[0].name, | 1272 notInitFinalFields[0].name, |
1248 notInitFinalFields[1].name, | 1273 notInitFinalFields[1].name, |
1249 notInitFinalFields.length - 2 | 1274 notInitFinalFields.length - 2 |
1250 ]); | 1275 ]); |
1251 } | 1276 } |
1252 analysisError.setProperty( | 1277 analysisError.setProperty( |
(...skipping 16 matching lines...) Expand all Loading... |
1269 * [StaticWarningCode.INVALID_GETTER_OVERRIDE_RETURN_TYPE], | 1294 * [StaticWarningCode.INVALID_GETTER_OVERRIDE_RETURN_TYPE], |
1270 * [StaticWarningCode.INVALID_METHOD_OVERRIDE_RETURN_TYPE], | 1295 * [StaticWarningCode.INVALID_METHOD_OVERRIDE_RETURN_TYPE], |
1271 * [StaticWarningCode.INVALID_METHOD_OVERRIDE_NORMAL_PARAM_TYPE], | 1296 * [StaticWarningCode.INVALID_METHOD_OVERRIDE_NORMAL_PARAM_TYPE], |
1272 * [StaticWarningCode.INVALID_SETTER_OVERRIDE_NORMAL_PARAM_TYPE], | 1297 * [StaticWarningCode.INVALID_SETTER_OVERRIDE_NORMAL_PARAM_TYPE], |
1273 * [StaticWarningCode.INVALID_METHOD_OVERRIDE_OPTIONAL_PARAM_TYPE], | 1298 * [StaticWarningCode.INVALID_METHOD_OVERRIDE_OPTIONAL_PARAM_TYPE], |
1274 * [StaticWarningCode.INVALID_METHOD_OVERRIDE_NAMED_PARAM_TYPE], and | 1299 * [StaticWarningCode.INVALID_METHOD_OVERRIDE_NAMED_PARAM_TYPE], and |
1275 * [StaticWarningCode.INVALID_OVERRIDE_DIFFERENT_DEFAULT_VALUES]. | 1300 * [StaticWarningCode.INVALID_OVERRIDE_DIFFERENT_DEFAULT_VALUES]. |
1276 */ | 1301 */ |
1277 bool _checkForAllInvalidOverrideErrorCodes( | 1302 bool _checkForAllInvalidOverrideErrorCodes( |
1278 ExecutableElement executableElement, | 1303 ExecutableElement executableElement, |
1279 ExecutableElement overriddenExecutable, List<ParameterElement> parameters, | 1304 ExecutableElement overriddenExecutable, |
1280 List<AstNode> parameterLocations, SimpleIdentifier errorNameTarget) { | 1305 List<ParameterElement> parameters, |
| 1306 List<AstNode> parameterLocations, |
| 1307 SimpleIdentifier errorNameTarget) { |
1281 bool isGetter = false; | 1308 bool isGetter = false; |
1282 bool isSetter = false; | 1309 bool isSetter = false; |
1283 if (executableElement is PropertyAccessorElement) { | 1310 if (executableElement is PropertyAccessorElement) { |
1284 PropertyAccessorElement accessorElement = executableElement; | 1311 PropertyAccessorElement accessorElement = executableElement; |
1285 isGetter = accessorElement.isGetter; | 1312 isGetter = accessorElement.isGetter; |
1286 isSetter = accessorElement.isSetter; | 1313 isSetter = accessorElement.isSetter; |
1287 } | 1314 } |
1288 String executableElementName = executableElement.name; | 1315 String executableElementName = executableElement.name; |
1289 FunctionType overridingFT = executableElement.type; | 1316 FunctionType overridingFT = executableElement.type; |
1290 FunctionType overriddenFT = overriddenExecutable.type; | 1317 FunctionType overriddenFT = overriddenExecutable.type; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1331 _errorReporter.reportErrorForNode( | 1358 _errorReporter.reportErrorForNode( |
1332 StaticWarningCode.INVALID_OVERRIDE_NAMED, errorNameTarget, [ | 1359 StaticWarningCode.INVALID_OVERRIDE_NAMED, errorNameTarget, [ |
1333 overriddenParamName, | 1360 overriddenParamName, |
1334 overriddenExecutable.enclosingElement.displayName | 1361 overriddenExecutable.enclosingElement.displayName |
1335 ]); | 1362 ]); |
1336 return true; | 1363 return true; |
1337 } | 1364 } |
1338 } | 1365 } |
1339 // SWC.INVALID_METHOD_OVERRIDE_RETURN_TYPE | 1366 // SWC.INVALID_METHOD_OVERRIDE_RETURN_TYPE |
1340 if (overriddenFTReturnType != VoidTypeImpl.instance && | 1367 if (overriddenFTReturnType != VoidTypeImpl.instance && |
1341 !overridingFTReturnType.isAssignableTo(overriddenFTReturnType)) { | 1368 !_typeSystem.isAssignableTo( |
1342 _errorReporter.reportTypeErrorForNode(!isGetter | 1369 overridingFTReturnType, overriddenFTReturnType)) { |
| 1370 _errorReporter.reportTypeErrorForNode( |
| 1371 !isGetter |
1343 ? StaticWarningCode.INVALID_METHOD_OVERRIDE_RETURN_TYPE | 1372 ? StaticWarningCode.INVALID_METHOD_OVERRIDE_RETURN_TYPE |
1344 : StaticWarningCode.INVALID_GETTER_OVERRIDE_RETURN_TYPE, | 1373 : StaticWarningCode.INVALID_GETTER_OVERRIDE_RETURN_TYPE, |
1345 errorNameTarget, [ | 1374 errorNameTarget, |
| 1375 [ |
1346 overridingFTReturnType, | 1376 overridingFTReturnType, |
1347 overriddenFTReturnType, | 1377 overriddenFTReturnType, |
1348 overriddenExecutable.enclosingElement.displayName | 1378 overriddenExecutable.enclosingElement.displayName |
1349 ]); | 1379 ]); |
1350 return true; | 1380 return true; |
1351 } | 1381 } |
1352 // SWC.INVALID_METHOD_OVERRIDE_NORMAL_PARAM_TYPE | 1382 // SWC.INVALID_METHOD_OVERRIDE_NORMAL_PARAM_TYPE |
1353 if (parameterLocations == null) { | 1383 if (parameterLocations == null) { |
1354 return false; | 1384 return false; |
1355 } | 1385 } |
1356 int parameterIndex = 0; | 1386 int parameterIndex = 0; |
1357 for (int i = 0; i < overridingNormalPT.length; i++) { | 1387 for (int i = 0; i < overridingNormalPT.length; i++) { |
1358 if (!overridingNormalPT[i].isAssignableTo(overriddenNormalPT[i])) { | 1388 if (!_typeSystem.isAssignableTo( |
1359 _errorReporter.reportTypeErrorForNode(!isSetter | 1389 overridingNormalPT[i], overriddenNormalPT[i])) { |
| 1390 _errorReporter.reportTypeErrorForNode( |
| 1391 !isSetter |
1360 ? StaticWarningCode.INVALID_METHOD_OVERRIDE_NORMAL_PARAM_TYPE | 1392 ? StaticWarningCode.INVALID_METHOD_OVERRIDE_NORMAL_PARAM_TYPE |
1361 : StaticWarningCode.INVALID_SETTER_OVERRIDE_NORMAL_PARAM_TYPE, | 1393 : StaticWarningCode.INVALID_SETTER_OVERRIDE_NORMAL_PARAM_TYPE, |
1362 parameterLocations[parameterIndex], [ | 1394 parameterLocations[parameterIndex], |
| 1395 [ |
1363 overridingNormalPT[i], | 1396 overridingNormalPT[i], |
1364 overriddenNormalPT[i], | 1397 overriddenNormalPT[i], |
1365 overriddenExecutable.enclosingElement.displayName | 1398 overriddenExecutable.enclosingElement.displayName |
1366 ]); | 1399 ]); |
1367 return true; | 1400 return true; |
1368 } | 1401 } |
1369 parameterIndex++; | 1402 parameterIndex++; |
1370 } | 1403 } |
1371 // SWC.INVALID_METHOD_OVERRIDE_OPTIONAL_PARAM_TYPE | 1404 // SWC.INVALID_METHOD_OVERRIDE_OPTIONAL_PARAM_TYPE |
1372 for (int i = 0; i < overriddenPositionalPT.length; i++) { | 1405 for (int i = 0; i < overriddenPositionalPT.length; i++) { |
1373 if (!overridingPositionalPT[i] | 1406 if (!_typeSystem.isAssignableTo( |
1374 .isAssignableTo(overriddenPositionalPT[i])) { | 1407 overridingPositionalPT[i], overriddenPositionalPT[i])) { |
1375 _errorReporter.reportTypeErrorForNode( | 1408 _errorReporter.reportTypeErrorForNode( |
1376 StaticWarningCode.INVALID_METHOD_OVERRIDE_OPTIONAL_PARAM_TYPE, | 1409 StaticWarningCode.INVALID_METHOD_OVERRIDE_OPTIONAL_PARAM_TYPE, |
1377 parameterLocations[parameterIndex], [ | 1410 parameterLocations[parameterIndex], [ |
1378 overridingPositionalPT[i], | 1411 overridingPositionalPT[i], |
1379 overriddenPositionalPT[i], | 1412 overriddenPositionalPT[i], |
1380 overriddenExecutable.enclosingElement.displayName | 1413 overriddenExecutable.enclosingElement.displayName |
1381 ]); | 1414 ]); |
1382 return true; | 1415 return true; |
1383 } | 1416 } |
1384 parameterIndex++; | 1417 parameterIndex++; |
1385 } | 1418 } |
1386 // SWC.INVALID_METHOD_OVERRIDE_NAMED_PARAM_TYPE & | 1419 // SWC.INVALID_METHOD_OVERRIDE_NAMED_PARAM_TYPE & |
1387 // SWC.INVALID_OVERRIDE_DIFFERENT_DEFAULT_VALUES | 1420 // SWC.INVALID_OVERRIDE_DIFFERENT_DEFAULT_VALUES |
1388 for (String overriddenName in overriddenNamedPT.keys) { | 1421 for (String overriddenName in overriddenNamedPT.keys) { |
1389 DartType overridingType = overridingNamedPT[overriddenName]; | 1422 DartType overridingType = overridingNamedPT[overriddenName]; |
1390 if (overridingType == null) { | 1423 if (overridingType == null) { |
1391 // Error, this is never reached- INVALID_OVERRIDE_NAMED would have been | 1424 // Error, this is never reached- INVALID_OVERRIDE_NAMED would have been |
1392 // created above if this could be reached. | 1425 // created above if this could be reached. |
1393 continue; | 1426 continue; |
1394 } | 1427 } |
1395 DartType overriddenType = overriddenNamedPT[overriddenName]; | 1428 DartType overriddenType = overriddenNamedPT[overriddenName]; |
1396 if (!overriddenType.isAssignableTo(overridingType)) { | 1429 if (!_typeSystem.isAssignableTo(overriddenType, overridingType)) { |
1397 // lookup the parameter for the error to select | 1430 // lookup the parameter for the error to select |
1398 ParameterElement parameterToSelect = null; | 1431 ParameterElement parameterToSelect = null; |
1399 AstNode parameterLocationToSelect = null; | 1432 AstNode parameterLocationToSelect = null; |
1400 for (int i = 0; i < parameters.length; i++) { | 1433 for (int i = 0; i < parameters.length; i++) { |
1401 ParameterElement parameter = parameters[i]; | 1434 ParameterElement parameter = parameters[i]; |
1402 if (parameter.parameterKind == ParameterKind.NAMED && | 1435 if (parameter.parameterKind == ParameterKind.NAMED && |
1403 overriddenName == parameter.name) { | 1436 overriddenName == parameter.name) { |
1404 parameterToSelect = parameter; | 1437 parameterToSelect = parameter; |
1405 parameterLocationToSelect = parameterLocations[i]; | 1438 parameterLocationToSelect = parameterLocations[i]; |
1406 break; | 1439 break; |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1532 /** | 1565 /** |
1533 * Check the given [executableElement] against override-error codes. This | 1566 * Check the given [executableElement] against override-error codes. This |
1534 * method computes the given executableElement is overriding and calls | 1567 * method computes the given executableElement is overriding and calls |
1535 * [_checkForAllInvalidOverrideErrorCodes] when the [InheritanceManager] | 1568 * [_checkForAllInvalidOverrideErrorCodes] when the [InheritanceManager] |
1536 * returns a [MultiplyInheritedExecutableElement], this method loops through | 1569 * returns a [MultiplyInheritedExecutableElement], this method loops through |
1537 * the list in the [MultiplyInheritedExecutableElement]. The [parameters] are | 1570 * the list in the [MultiplyInheritedExecutableElement]. The [parameters] are |
1538 * the parameters of the executable element. The [errorNameTarget] is the node | 1571 * the parameters of the executable element. The [errorNameTarget] is the node |
1539 * to report problems on. | 1572 * to report problems on. |
1540 */ | 1573 */ |
1541 bool _checkForAllInvalidOverrideErrorCodesForExecutable( | 1574 bool _checkForAllInvalidOverrideErrorCodesForExecutable( |
1542 ExecutableElement executableElement, List<ParameterElement> parameters, | 1575 ExecutableElement executableElement, |
1543 List<AstNode> parameterLocations, SimpleIdentifier errorNameTarget) { | 1576 List<ParameterElement> parameters, |
| 1577 List<AstNode> parameterLocations, |
| 1578 SimpleIdentifier errorNameTarget) { |
1544 // | 1579 // |
1545 // Compute the overridden executable from the InheritanceManager | 1580 // Compute the overridden executable from the InheritanceManager |
1546 // | 1581 // |
1547 List<ExecutableElement> overriddenExecutables = _inheritanceManager | 1582 List<ExecutableElement> overriddenExecutables = _inheritanceManager |
1548 .lookupOverrides(_enclosingClass, executableElement.name); | 1583 .lookupOverrides(_enclosingClass, executableElement.name); |
1549 if (_checkForInstanceMethodNameCollidesWithSuperclassStatic( | 1584 if (_checkForInstanceMethodNameCollidesWithSuperclassStatic( |
1550 executableElement, errorNameTarget)) { | 1585 executableElement, errorNameTarget)) { |
1551 return true; | 1586 return true; |
1552 } | 1587 } |
1553 for (ExecutableElement overriddenElement in overriddenExecutables) { | 1588 for (ExecutableElement overriddenElement in overriddenExecutables) { |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1646 problemReported = true; | 1681 problemReported = true; |
1647 } else { | 1682 } else { |
1648 ClassElement mixinElement = (mixinType as InterfaceType).element; | 1683 ClassElement mixinElement = (mixinType as InterfaceType).element; |
1649 if (_checkForExtendsOrImplementsDeferredClass( | 1684 if (_checkForExtendsOrImplementsDeferredClass( |
1650 mixinName, CompileTimeErrorCode.MIXIN_DEFERRED_CLASS)) { | 1685 mixinName, CompileTimeErrorCode.MIXIN_DEFERRED_CLASS)) { |
1651 problemReported = true; | 1686 problemReported = true; |
1652 } | 1687 } |
1653 if (_checkForMixinDeclaresConstructor(mixinName, mixinElement)) { | 1688 if (_checkForMixinDeclaresConstructor(mixinName, mixinElement)) { |
1654 problemReported = true; | 1689 problemReported = true; |
1655 } | 1690 } |
1656 if (_checkForMixinInheritsNotFromObject(mixinName, mixinElement)) { | 1691 if (!enableSuperMixins && |
| 1692 _checkForMixinInheritsNotFromObject(mixinName, mixinElement)) { |
1657 problemReported = true; | 1693 problemReported = true; |
1658 } | 1694 } |
1659 if (_checkForMixinReferencesSuper(mixinName, mixinElement)) { | 1695 if (_checkForMixinReferencesSuper(mixinName, mixinElement)) { |
1660 problemReported = true; | 1696 problemReported = true; |
1661 } | 1697 } |
1662 } | 1698 } |
1663 } | 1699 } |
1664 return problemReported; | 1700 return problemReported; |
1665 } | 1701 } |
1666 | 1702 |
(...skipping 30 matching lines...) Expand all Loading... |
1697 // | 1733 // |
1698 // Prepare the constructor name | 1734 // Prepare the constructor name |
1699 // | 1735 // |
1700 String constructorStrName = constructorTypeName.name.name; | 1736 String constructorStrName = constructorTypeName.name.name; |
1701 if (redirectedConstructor.name != null) { | 1737 if (redirectedConstructor.name != null) { |
1702 constructorStrName += ".${redirectedConstructor.name.name}"; | 1738 constructorStrName += ".${redirectedConstructor.name.name}"; |
1703 } | 1739 } |
1704 ErrorCode errorCode = (declaration.constKeyword != null | 1740 ErrorCode errorCode = (declaration.constKeyword != null |
1705 ? CompileTimeErrorCode.REDIRECT_TO_MISSING_CONSTRUCTOR | 1741 ? CompileTimeErrorCode.REDIRECT_TO_MISSING_CONSTRUCTOR |
1706 : StaticWarningCode.REDIRECT_TO_MISSING_CONSTRUCTOR); | 1742 : StaticWarningCode.REDIRECT_TO_MISSING_CONSTRUCTOR); |
1707 _errorReporter.reportErrorForNode(errorCode, redirectedConstructor, [ | 1743 _errorReporter.reportErrorForNode(errorCode, redirectedConstructor, |
1708 constructorStrName, | 1744 [constructorStrName, redirectedType.displayName]); |
1709 redirectedType.displayName | |
1710 ]); | |
1711 return true; | 1745 return true; |
1712 } | 1746 } |
1713 return false; | 1747 return false; |
1714 } | 1748 } |
1715 FunctionType redirectedType = redirectedElement.type; | 1749 FunctionType redirectedType = redirectedElement.type; |
1716 DartType redirectedReturnType = redirectedType.returnType; | 1750 DartType redirectedReturnType = redirectedType.returnType; |
1717 // | 1751 // |
1718 // Report specific problem when return type is incompatible | 1752 // Report specific problem when return type is incompatible |
1719 // | 1753 // |
1720 FunctionType constructorType = declaration.element.type; | 1754 FunctionType constructorType = declaration.element.type; |
1721 DartType constructorReturnType = constructorType.returnType; | 1755 DartType constructorReturnType = constructorType.returnType; |
1722 if (!redirectedReturnType.isAssignableTo(constructorReturnType)) { | 1756 if (!_typeSystem.isAssignableTo( |
| 1757 redirectedReturnType, constructorReturnType)) { |
1723 _errorReporter.reportErrorForNode( | 1758 _errorReporter.reportErrorForNode( |
1724 StaticWarningCode.REDIRECT_TO_INVALID_RETURN_TYPE, | 1759 StaticWarningCode.REDIRECT_TO_INVALID_RETURN_TYPE, |
1725 redirectedConstructor, [redirectedReturnType, constructorReturnType]); | 1760 redirectedConstructor, |
| 1761 [redirectedReturnType, constructorReturnType]); |
1726 return true; | 1762 return true; |
1727 } | 1763 } |
1728 // | 1764 // |
1729 // Check parameters | 1765 // Check parameters |
1730 // | 1766 // |
1731 if (!redirectedType.isSubtypeOf(constructorType)) { | 1767 if (!_typeSystem.isSubtypeOf(redirectedType, constructorType)) { |
1732 _errorReporter.reportErrorForNode( | 1768 _errorReporter.reportErrorForNode( |
1733 StaticWarningCode.REDIRECT_TO_INVALID_FUNCTION_TYPE, | 1769 StaticWarningCode.REDIRECT_TO_INVALID_FUNCTION_TYPE, |
1734 redirectedConstructor, [redirectedType, constructorType]); | 1770 redirectedConstructor, |
| 1771 [redirectedType, constructorType]); |
1735 return true; | 1772 return true; |
1736 } | 1773 } |
1737 return false; | 1774 return false; |
1738 } | 1775 } |
1739 | 1776 |
1740 /** | 1777 /** |
1741 * Check that the return [statement] of the form <i>return e;</i> is not in a | 1778 * Check that the return [statement] of the form <i>return e;</i> is not in a |
1742 * generative constructor. | 1779 * generative constructor. |
1743 * | 1780 * |
1744 * Check that return statements without expressions are not in a generative | 1781 * Check that return statements without expressions are not in a generative |
(...skipping 22 matching lines...) Expand all Loading... |
1767 return false; | 1804 return false; |
1768 } | 1805 } |
1769 _errorReporter.reportErrorForNode( | 1806 _errorReporter.reportErrorForNode( |
1770 CompileTimeErrorCode.RETURN_IN_GENERATIVE_CONSTRUCTOR, | 1807 CompileTimeErrorCode.RETURN_IN_GENERATIVE_CONSTRUCTOR, |
1771 returnExpression); | 1808 returnExpression); |
1772 return true; | 1809 return true; |
1773 } | 1810 } |
1774 // RETURN_WITHOUT_VALUE | 1811 // RETURN_WITHOUT_VALUE |
1775 if (returnExpression == null) { | 1812 if (returnExpression == null) { |
1776 if (_inGenerator || | 1813 if (_inGenerator || |
1777 _computeReturnTypeForMethod(null) | 1814 _typeSystem.isAssignableTo( |
1778 .isAssignableTo(expectedReturnType)) { | 1815 _computeReturnTypeForMethod(null), expectedReturnType)) { |
1779 return false; | 1816 return false; |
1780 } | 1817 } |
1781 _hasReturnWithoutValue = true; | 1818 _hasReturnWithoutValue = true; |
1782 _errorReporter.reportErrorForNode( | 1819 _errorReporter.reportErrorForNode( |
1783 StaticWarningCode.RETURN_WITHOUT_VALUE, statement); | 1820 StaticWarningCode.RETURN_WITHOUT_VALUE, statement); |
1784 return true; | 1821 return true; |
1785 } else if (_inGenerator) { | 1822 } else if (_inGenerator) { |
1786 // RETURN_IN_GENERATOR | 1823 // RETURN_IN_GENERATOR |
1787 _errorReporter.reportErrorForNode( | 1824 _errorReporter.reportErrorForNode( |
1788 CompileTimeErrorCode.RETURN_IN_GENERATOR, statement); | 1825 CompileTimeErrorCode.RETURN_IN_GENERATOR, statement); |
(...skipping 17 matching lines...) Expand all Loading... |
1806 return false; | 1843 return false; |
1807 } | 1844 } |
1808 // check exported names | 1845 // check exported names |
1809 Namespace namespace = | 1846 Namespace namespace = |
1810 new NamespaceBuilder().createExportNamespaceForDirective(exportElement); | 1847 new NamespaceBuilder().createExportNamespaceForDirective(exportElement); |
1811 Map<String, Element> definedNames = namespace.definedNames; | 1848 Map<String, Element> definedNames = namespace.definedNames; |
1812 for (String name in definedNames.keys) { | 1849 for (String name in definedNames.keys) { |
1813 Element element = definedNames[name]; | 1850 Element element = definedNames[name]; |
1814 Element prevElement = _exportedElements[name]; | 1851 Element prevElement = _exportedElements[name]; |
1815 if (element != null && prevElement != null && prevElement != element) { | 1852 if (element != null && prevElement != null && prevElement != element) { |
1816 _errorReporter.reportErrorForNode(CompileTimeErrorCode.AMBIGUOUS_EXPORT, | 1853 _errorReporter.reportErrorForNode( |
1817 directive, [ | 1854 CompileTimeErrorCode.AMBIGUOUS_EXPORT, directive, [ |
1818 name, | 1855 name, |
1819 prevElement.library.definingCompilationUnit.displayName, | 1856 prevElement.library.definingCompilationUnit.displayName, |
1820 element.library.definingCompilationUnit.displayName | 1857 element.library.definingCompilationUnit.displayName |
1821 ]); | 1858 ]); |
1822 return true; | 1859 return true; |
1823 } else { | 1860 } else { |
1824 _exportedElements[name] = element; | 1861 _exportedElements[name] = element; |
1825 } | 1862 } |
1826 } | 1863 } |
1827 return false; | 1864 return false; |
1828 } | 1865 } |
1829 | 1866 |
1830 /** | 1867 /** |
1831 * Verify that the given [expression] can be assigned to its corresponding | 1868 * Verify that the given [expression] can be assigned to its corresponding |
1832 * parameters. The [expectedStaticType] is the expected static type of the | 1869 * parameters. The [expectedStaticType] is the expected static type of the |
1833 * parameter. The [actualStaticType] is the actual static type of the | 1870 * parameter. The [actualStaticType] is the actual static type of the |
1834 * argument. | 1871 * argument. |
1835 * | 1872 * |
1836 * This method corresponds to | 1873 * This method corresponds to |
1837 * [BestPracticesVerifier.checkForArgumentTypeNotAssignable]. | 1874 * [BestPracticesVerifier.checkForArgumentTypeNotAssignable]. |
1838 * | 1875 * |
1839 * See [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE], | 1876 * See [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE], |
1840 * [CompileTimeErrorCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE], | 1877 * [CompileTimeErrorCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE], |
1841 * [StaticWarningCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE], | 1878 * [StaticWarningCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE], |
1842 * [CompileTimeErrorCode.MAP_KEY_TYPE_NOT_ASSIGNABLE], | 1879 * [CompileTimeErrorCode.MAP_KEY_TYPE_NOT_ASSIGNABLE], |
1843 * [CompileTimeErrorCode.MAP_VALUE_TYPE_NOT_ASSIGNABLE], | 1880 * [CompileTimeErrorCode.MAP_VALUE_TYPE_NOT_ASSIGNABLE], |
1844 * [StaticWarningCode.MAP_KEY_TYPE_NOT_ASSIGNABLE], and | 1881 * [StaticWarningCode.MAP_KEY_TYPE_NOT_ASSIGNABLE], and |
1845 * [StaticWarningCode.MAP_VALUE_TYPE_NOT_ASSIGNABLE]. | 1882 * [StaticWarningCode.MAP_VALUE_TYPE_NOT_ASSIGNABLE]. |
1846 */ | 1883 */ |
1847 bool _checkForArgumentTypeNotAssignable(Expression expression, | 1884 bool _checkForArgumentTypeNotAssignable( |
1848 DartType expectedStaticType, DartType actualStaticType, | 1885 Expression expression, |
| 1886 DartType expectedStaticType, |
| 1887 DartType actualStaticType, |
1849 ErrorCode errorCode) { | 1888 ErrorCode errorCode) { |
1850 // | 1889 // |
1851 // Warning case: test static type information | 1890 // Warning case: test static type information |
1852 // | 1891 // |
1853 if (actualStaticType != null && expectedStaticType != null) { | 1892 if (actualStaticType != null && expectedStaticType != null) { |
1854 if (!actualStaticType.isAssignableTo(expectedStaticType)) { | 1893 if (!_typeSystem.isAssignableTo(actualStaticType, expectedStaticType)) { |
1855 _errorReporter.reportTypeErrorForNode( | 1894 _errorReporter.reportTypeErrorForNode( |
1856 errorCode, expression, [actualStaticType, expectedStaticType]); | 1895 errorCode, expression, [actualStaticType, expectedStaticType]); |
1857 return true; | 1896 return true; |
1858 } | 1897 } |
1859 } | 1898 } |
1860 return false; | 1899 return false; |
1861 } | 1900 } |
1862 | 1901 |
1863 /** | 1902 /** |
1864 * Verify that the given [argument] can be assigned to its corresponding | 1903 * Verify that the given [argument] can be assigned to its corresponding |
(...skipping 24 matching lines...) Expand all Loading... |
1889 * | 1928 * |
1890 * See [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE], | 1929 * See [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE], |
1891 * [CompileTimeErrorCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE], | 1930 * [CompileTimeErrorCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE], |
1892 * [StaticWarningCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE], | 1931 * [StaticWarningCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE], |
1893 * [CompileTimeErrorCode.MAP_KEY_TYPE_NOT_ASSIGNABLE], | 1932 * [CompileTimeErrorCode.MAP_KEY_TYPE_NOT_ASSIGNABLE], |
1894 * [CompileTimeErrorCode.MAP_VALUE_TYPE_NOT_ASSIGNABLE], | 1933 * [CompileTimeErrorCode.MAP_VALUE_TYPE_NOT_ASSIGNABLE], |
1895 * [StaticWarningCode.MAP_KEY_TYPE_NOT_ASSIGNABLE], and | 1934 * [StaticWarningCode.MAP_KEY_TYPE_NOT_ASSIGNABLE], and |
1896 * [StaticWarningCode.MAP_VALUE_TYPE_NOT_ASSIGNABLE]. | 1935 * [StaticWarningCode.MAP_VALUE_TYPE_NOT_ASSIGNABLE]. |
1897 */ | 1936 */ |
1898 bool _checkForArgumentTypeNotAssignableWithExpectedTypes( | 1937 bool _checkForArgumentTypeNotAssignableWithExpectedTypes( |
1899 Expression expression, DartType expectedStaticType, | 1938 Expression expression, |
1900 ErrorCode errorCode) => _checkForArgumentTypeNotAssignable( | 1939 DartType expectedStaticType, |
| 1940 ErrorCode errorCode) => |
| 1941 _checkForArgumentTypeNotAssignable( |
1901 expression, expectedStaticType, getStaticType(expression), errorCode); | 1942 expression, expectedStaticType, getStaticType(expression), errorCode); |
1902 | 1943 |
1903 /** | 1944 /** |
1904 * Verify that the arguments in the given [argumentList] can be assigned to | 1945 * Verify that the arguments in the given [argumentList] can be assigned to |
1905 * their corresponding parameters. | 1946 * their corresponding parameters. |
1906 * | 1947 * |
1907 * This method corresponds to | 1948 * This method corresponds to |
1908 * [BestPracticesVerifier.checkForArgumentTypesNotAssignableInList]. | 1949 * [BestPracticesVerifier.checkForArgumentTypesNotAssignableInList]. |
1909 * | 1950 * |
1910 * See [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]. | 1951 * See [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]. |
(...skipping 20 matching lines...) Expand all Loading... |
1931 */ | 1972 */ |
1932 bool _checkForAssignability(Expression expression, InterfaceType type, | 1973 bool _checkForAssignability(Expression expression, InterfaceType type, |
1933 ErrorCode errorCode, List<Object> arguments) { | 1974 ErrorCode errorCode, List<Object> arguments) { |
1934 if (expression == null) { | 1975 if (expression == null) { |
1935 return false; | 1976 return false; |
1936 } | 1977 } |
1937 DartType expressionType = expression.staticType; | 1978 DartType expressionType = expression.staticType; |
1938 if (expressionType == null) { | 1979 if (expressionType == null) { |
1939 return false; | 1980 return false; |
1940 } | 1981 } |
1941 if (expressionType.isAssignableTo(type)) { | 1982 if (_typeSystem.isAssignableTo(expressionType, type)) { |
1942 return false; | 1983 return false; |
1943 } | 1984 } |
1944 _errorReporter.reportErrorForNode(errorCode, expression, arguments); | 1985 _errorReporter.reportErrorForNode(errorCode, expression, arguments); |
1945 return true; | 1986 return true; |
1946 } | 1987 } |
1947 | 1988 |
1948 /** | 1989 /** |
1949 * Verify that the given [expression] is not final. | 1990 * Verify that the given [expression] is not final. |
1950 * | 1991 * |
1951 * See [StaticWarningCode.ASSIGNMENT_TO_CONST], | 1992 * See [StaticWarningCode.ASSIGNMENT_TO_CONST], |
(...skipping 23 matching lines...) Expand all Loading... |
1975 if (element.isConst) { | 2016 if (element.isConst) { |
1976 _errorReporter.reportErrorForNode( | 2017 _errorReporter.reportErrorForNode( |
1977 StaticWarningCode.ASSIGNMENT_TO_CONST, expression); | 2018 StaticWarningCode.ASSIGNMENT_TO_CONST, expression); |
1978 return true; | 2019 return true; |
1979 } | 2020 } |
1980 if (element.isFinal) { | 2021 if (element.isFinal) { |
1981 if (element is FieldElementImpl && | 2022 if (element is FieldElementImpl && |
1982 element.setter == null && | 2023 element.setter == null && |
1983 element.isSynthetic) { | 2024 element.isSynthetic) { |
1984 _errorReporter.reportErrorForNode( | 2025 _errorReporter.reportErrorForNode( |
1985 StaticWarningCode.ASSIGNMENT_TO_FINAL_NO_SETTER, highlightedNode, | 2026 StaticWarningCode.ASSIGNMENT_TO_FINAL_NO_SETTER, |
| 2027 highlightedNode, |
1986 [element.name, element.enclosingElement.displayName]); | 2028 [element.name, element.enclosingElement.displayName]); |
1987 return true; | 2029 return true; |
1988 } | 2030 } |
1989 _errorReporter.reportErrorForNode(StaticWarningCode.ASSIGNMENT_TO_FINAL, | 2031 _errorReporter.reportErrorForNode(StaticWarningCode.ASSIGNMENT_TO_FINAL, |
1990 highlightedNode, [element.name]); | 2032 highlightedNode, [element.name]); |
1991 return true; | 2033 return true; |
1992 } | 2034 } |
1993 return false; | 2035 return false; |
1994 } | 2036 } |
1995 if (element is FunctionElement) { | 2037 if (element is FunctionElement) { |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2110 memberName, _currentLibrary); | 2152 memberName, _currentLibrary); |
2111 } else if (method.isSetter) { | 2153 } else if (method.isSetter) { |
2112 overriddenMember = _enclosingClass.lookUpInheritedConcreteSetter( | 2154 overriddenMember = _enclosingClass.lookUpInheritedConcreteSetter( |
2113 memberName, _currentLibrary); | 2155 memberName, _currentLibrary); |
2114 } else { | 2156 } else { |
2115 overriddenMember = _enclosingClass.lookUpInheritedConcreteMethod( | 2157 overriddenMember = _enclosingClass.lookUpInheritedConcreteMethod( |
2116 memberName, _currentLibrary); | 2158 memberName, _currentLibrary); |
2117 } | 2159 } |
2118 if (overriddenMember == null) { | 2160 if (overriddenMember == null) { |
2119 _errorReporter.reportErrorForNode( | 2161 _errorReporter.reportErrorForNode( |
2120 StaticWarningCode.CONCRETE_CLASS_WITH_ABSTRACT_MEMBER, nameNode, [ | 2162 StaticWarningCode.CONCRETE_CLASS_WITH_ABSTRACT_MEMBER, |
2121 memberName, | 2163 nameNode, |
2122 _enclosingClass.displayName | 2164 [memberName, _enclosingClass.displayName]); |
2123 ]); | |
2124 return true; | 2165 return true; |
2125 } | 2166 } |
2126 } | 2167 } |
2127 return false; | 2168 return false; |
2128 } | 2169 } |
2129 | 2170 |
2130 /** | 2171 /** |
2131 * Verify all possible conflicts of the given [constructor]'s name with other | 2172 * Verify all possible conflicts of the given [constructor]'s name with other |
2132 * constructors and members of the same class. The [constructorElement] is the | 2173 * constructors and members of the same class. The [constructorElement] is the |
2133 * constructor's element. | 2174 * constructor's element. |
(...skipping 14 matching lines...) Expand all Loading... |
2148 for (ConstructorElement otherConstructor in constructors) { | 2189 for (ConstructorElement otherConstructor in constructors) { |
2149 if (identical(otherConstructor, constructorElement)) { | 2190 if (identical(otherConstructor, constructorElement)) { |
2150 continue; | 2191 continue; |
2151 } | 2192 } |
2152 if (name == otherConstructor.name) { | 2193 if (name == otherConstructor.name) { |
2153 if (name == null || name.length == 0) { | 2194 if (name == null || name.length == 0) { |
2154 _errorReporter.reportErrorForNode( | 2195 _errorReporter.reportErrorForNode( |
2155 CompileTimeErrorCode.DUPLICATE_CONSTRUCTOR_DEFAULT, constructor); | 2196 CompileTimeErrorCode.DUPLICATE_CONSTRUCTOR_DEFAULT, constructor); |
2156 } else { | 2197 } else { |
2157 _errorReporter.reportErrorForNode( | 2198 _errorReporter.reportErrorForNode( |
2158 CompileTimeErrorCode.DUPLICATE_CONSTRUCTOR_NAME, constructor, | 2199 CompileTimeErrorCode.DUPLICATE_CONSTRUCTOR_NAME, |
| 2200 constructor, |
2159 [name]); | 2201 [name]); |
2160 } | 2202 } |
2161 return true; | 2203 return true; |
2162 } | 2204 } |
2163 } | 2205 } |
2164 // conflict with class member | 2206 // conflict with class member |
2165 if (constructorName != null && | 2207 if (constructorName != null && |
2166 constructorElement != null && | 2208 constructorElement != null && |
2167 !constructorName.isSynthetic) { | 2209 !constructorName.isSynthetic) { |
2168 // fields | 2210 // fields |
2169 FieldElement field = classElement.getField(name); | 2211 FieldElement field = classElement.getField(name); |
2170 if (field != null) { | 2212 if (field != null) { |
2171 _errorReporter.reportErrorForNode( | 2213 _errorReporter.reportErrorForNode( |
2172 CompileTimeErrorCode.CONFLICTING_CONSTRUCTOR_NAME_AND_FIELD, | 2214 CompileTimeErrorCode.CONFLICTING_CONSTRUCTOR_NAME_AND_FIELD, |
2173 constructor, [name]); | 2215 constructor, |
| 2216 [name]); |
2174 return true; | 2217 return true; |
2175 } | 2218 } |
2176 // methods | 2219 // methods |
2177 MethodElement method = classElement.getMethod(name); | 2220 MethodElement method = classElement.getMethod(name); |
2178 if (method != null) { | 2221 if (method != null) { |
2179 _errorReporter.reportErrorForNode( | 2222 _errorReporter.reportErrorForNode( |
2180 CompileTimeErrorCode.CONFLICTING_CONSTRUCTOR_NAME_AND_METHOD, | 2223 CompileTimeErrorCode.CONFLICTING_CONSTRUCTOR_NAME_AND_METHOD, |
2181 constructor, [name]); | 2224 constructor, |
| 2225 [name]); |
2182 return true; | 2226 return true; |
2183 } | 2227 } |
2184 } | 2228 } |
2185 return false; | 2229 return false; |
2186 } | 2230 } |
2187 | 2231 |
2188 /** | 2232 /** |
2189 * Verify that the [_enclosingClass] does not have a method and getter pair | 2233 * Verify that the [_enclosingClass] does not have a method and getter pair |
2190 * with the same name on, via inheritance. | 2234 * with the same name on, via inheritance. |
2191 * | 2235 * |
2192 * See [CompileTimeErrorCode.CONFLICTING_GETTER_AND_METHOD], and | 2236 * See [CompileTimeErrorCode.CONFLICTING_GETTER_AND_METHOD], and |
2193 * [CompileTimeErrorCode.CONFLICTING_METHOD_AND_GETTER]. | 2237 * [CompileTimeErrorCode.CONFLICTING_METHOD_AND_GETTER]. |
2194 */ | 2238 */ |
2195 bool _checkForConflictingGetterAndMethod() { | 2239 bool _checkForConflictingGetterAndMethod() { |
2196 if (_enclosingClass == null) { | 2240 if (_enclosingClass == null) { |
2197 return false; | 2241 return false; |
2198 } | 2242 } |
2199 bool hasProblem = false; | 2243 bool hasProblem = false; |
2200 // method declared in the enclosing class vs. inherited getter | 2244 // method declared in the enclosing class vs. inherited getter |
2201 for (MethodElement method in _enclosingClass.methods) { | 2245 for (MethodElement method in _enclosingClass.methods) { |
2202 String name = method.name; | 2246 String name = method.name; |
2203 // find inherited property accessor (and can be only getter) | 2247 // find inherited property accessor (and can be only getter) |
2204 ExecutableElement inherited = | 2248 ExecutableElement inherited = |
2205 _inheritanceManager.lookupInheritance(_enclosingClass, name); | 2249 _inheritanceManager.lookupInheritance(_enclosingClass, name); |
2206 if (inherited is! PropertyAccessorElement) { | 2250 if (inherited is! PropertyAccessorElement) { |
2207 continue; | 2251 continue; |
2208 } | 2252 } |
2209 // report problem | 2253 // report problem |
2210 hasProblem = true; | 2254 hasProblem = true; |
2211 _errorReporter.reportErrorForOffset( | 2255 _errorReporter.reportErrorForElement( |
2212 CompileTimeErrorCode.CONFLICTING_GETTER_AND_METHOD, method.nameOffset, | 2256 CompileTimeErrorCode.CONFLICTING_GETTER_AND_METHOD, method, [ |
2213 name.length, [ | |
2214 _enclosingClass.displayName, | 2257 _enclosingClass.displayName, |
2215 inherited.enclosingElement.displayName, | 2258 inherited.enclosingElement.displayName, |
2216 name | 2259 name |
2217 ]); | 2260 ]); |
2218 } | 2261 } |
2219 // getter declared in the enclosing class vs. inherited method | 2262 // getter declared in the enclosing class vs. inherited method |
2220 for (PropertyAccessorElement accessor in _enclosingClass.accessors) { | 2263 for (PropertyAccessorElement accessor in _enclosingClass.accessors) { |
2221 if (!accessor.isGetter) { | 2264 if (!accessor.isGetter) { |
2222 continue; | 2265 continue; |
2223 } | 2266 } |
2224 String name = accessor.name; | 2267 String name = accessor.name; |
2225 // find inherited method | 2268 // find inherited method |
2226 ExecutableElement inherited = | 2269 ExecutableElement inherited = |
2227 _inheritanceManager.lookupInheritance(_enclosingClass, name); | 2270 _inheritanceManager.lookupInheritance(_enclosingClass, name); |
2228 if (inherited is! MethodElement) { | 2271 if (inherited is! MethodElement) { |
2229 continue; | 2272 continue; |
2230 } | 2273 } |
2231 // report problem | 2274 // report problem |
2232 hasProblem = true; | 2275 hasProblem = true; |
2233 _errorReporter.reportErrorForOffset( | 2276 _errorReporter.reportErrorForElement( |
2234 CompileTimeErrorCode.CONFLICTING_METHOD_AND_GETTER, | 2277 CompileTimeErrorCode.CONFLICTING_METHOD_AND_GETTER, accessor, [ |
2235 accessor.nameOffset, name.length, [ | |
2236 _enclosingClass.displayName, | 2278 _enclosingClass.displayName, |
2237 inherited.enclosingElement.displayName, | 2279 inherited.enclosingElement.displayName, |
2238 name | 2280 name |
2239 ]); | 2281 ]); |
2240 } | 2282 } |
2241 // done | 2283 // done |
2242 return hasProblem; | 2284 return hasProblem; |
2243 } | 2285 } |
2244 | 2286 |
2245 /** | 2287 /** |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2291 } | 2333 } |
2292 // prepare "super" type to report its name | 2334 // prepare "super" type to report its name |
2293 ClassElement superElementClass = | 2335 ClassElement superElementClass = |
2294 superElement.enclosingElement as ClassElement; | 2336 superElement.enclosingElement as ClassElement; |
2295 InterfaceType superElementType = superElementClass.type; | 2337 InterfaceType superElementType = superElementClass.type; |
2296 // report problem | 2338 // report problem |
2297 hasProblem = true; | 2339 hasProblem = true; |
2298 if (getter) { | 2340 if (getter) { |
2299 _errorReporter.reportErrorForElement( | 2341 _errorReporter.reportErrorForElement( |
2300 StaticWarningCode.CONFLICTING_INSTANCE_GETTER_AND_SUPERCLASS_MEMBER, | 2342 StaticWarningCode.CONFLICTING_INSTANCE_GETTER_AND_SUPERCLASS_MEMBER, |
2301 accessor, [superElementType.displayName]); | 2343 accessor, |
| 2344 [superElementType.displayName]); |
2302 } else { | 2345 } else { |
2303 _errorReporter.reportErrorForElement( | 2346 _errorReporter.reportErrorForElement( |
2304 StaticWarningCode.CONFLICTING_INSTANCE_SETTER_AND_SUPERCLASS_MEMBER, | 2347 StaticWarningCode.CONFLICTING_INSTANCE_SETTER_AND_SUPERCLASS_MEMBER, |
2305 accessor, [superElementType.displayName]); | 2348 accessor, |
| 2349 [superElementType.displayName]); |
2306 } | 2350 } |
2307 } | 2351 } |
2308 // done | 2352 // done |
2309 return hasProblem; | 2353 return hasProblem; |
2310 } | 2354 } |
2311 | 2355 |
2312 /** | 2356 /** |
2313 * Verify that the enclosing class does not have a setter with the same name | 2357 * Verify that the enclosing class does not have a setter with the same name |
2314 * as the given instance method declaration. | 2358 * as the given instance method declaration. |
2315 * | 2359 * |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2377 addThisMemberToTheMap = false; | 2421 addThisMemberToTheMap = false; |
2378 } | 2422 } |
2379 } else if (isSetter) { | 2423 } else if (isSetter) { |
2380 String methodName = name.name; | 2424 String methodName = name.name; |
2381 ClassMember conflictingMethod = memberHashMap[methodName]; | 2425 ClassMember conflictingMethod = memberHashMap[methodName]; |
2382 if (conflictingMethod != null && | 2426 if (conflictingMethod != null && |
2383 conflictingMethod is MethodDeclaration && | 2427 conflictingMethod is MethodDeclaration && |
2384 !conflictingMethod.isGetter) { | 2428 !conflictingMethod.isGetter) { |
2385 // report problem | 2429 // report problem |
2386 _errorReporter.reportErrorForNode( | 2430 _errorReporter.reportErrorForNode( |
2387 StaticWarningCode.CONFLICTING_INSTANCE_METHOD_SETTER2, name, [ | 2431 StaticWarningCode.CONFLICTING_INSTANCE_METHOD_SETTER2, |
2388 _enclosingClass.displayName, | 2432 name, |
2389 name.name | 2433 [_enclosingClass.displayName, name.name]); |
2390 ]); | |
2391 foundError = true; | 2434 foundError = true; |
2392 addThisMemberToTheMap = false; | 2435 addThisMemberToTheMap = false; |
2393 } | 2436 } |
2394 } | 2437 } |
2395 // Finally, add this member into the HashMap. | 2438 // Finally, add this member into the HashMap. |
2396 if (addThisMemberToTheMap) { | 2439 if (addThisMemberToTheMap) { |
2397 if (method.isSetter) { | 2440 if (method.isSetter) { |
2398 memberHashMap["${name.name}="] = method; | 2441 memberHashMap["${name.name}="] = method; |
2399 } else { | 2442 } else { |
2400 memberHashMap[name.name] = method; | 2443 memberHashMap[name.name] = method; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2436 // OK, also static | 2479 // OK, also static |
2437 if (setter.isStatic) { | 2480 if (setter.isStatic) { |
2438 return false; | 2481 return false; |
2439 } | 2482 } |
2440 // prepare "setter" type to report its name | 2483 // prepare "setter" type to report its name |
2441 ClassElement setterClass = setter.enclosingElement as ClassElement; | 2484 ClassElement setterClass = setter.enclosingElement as ClassElement; |
2442 InterfaceType setterType = setterClass.type; | 2485 InterfaceType setterType = setterClass.type; |
2443 // report problem | 2486 // report problem |
2444 _errorReporter.reportErrorForNode( | 2487 _errorReporter.reportErrorForNode( |
2445 StaticWarningCode.CONFLICTING_STATIC_GETTER_AND_INSTANCE_SETTER, | 2488 StaticWarningCode.CONFLICTING_STATIC_GETTER_AND_INSTANCE_SETTER, |
2446 nameNode, [setterType.displayName]); | 2489 nameNode, |
| 2490 [setterType.displayName]); |
2447 return true; | 2491 return true; |
2448 } | 2492 } |
2449 | 2493 |
2450 /** | 2494 /** |
2451 * Verify that the enclosing class does not have an instance member with the | 2495 * Verify that the enclosing class does not have an instance member with the |
2452 * same name as the given static [method] declaration. | 2496 * same name as the given static [method] declaration. |
2453 * | 2497 * |
2454 * See [StaticWarningCode.CONFLICTING_STATIC_SETTER_AND_INSTANCE_MEMBER]. | 2498 * See [StaticWarningCode.CONFLICTING_STATIC_SETTER_AND_INSTANCE_MEMBER]. |
2455 */ | 2499 */ |
2456 bool _checkForConflictingStaticSetterAndInstanceMember( | 2500 bool _checkForConflictingStaticSetterAndInstanceMember( |
(...skipping 27 matching lines...) Expand all Loading... |
2484 // OK, also static | 2528 // OK, also static |
2485 if (member.isStatic) { | 2529 if (member.isStatic) { |
2486 return false; | 2530 return false; |
2487 } | 2531 } |
2488 // prepare "member" type to report its name | 2532 // prepare "member" type to report its name |
2489 ClassElement memberClass = member.enclosingElement as ClassElement; | 2533 ClassElement memberClass = member.enclosingElement as ClassElement; |
2490 InterfaceType memberType = memberClass.type; | 2534 InterfaceType memberType = memberClass.type; |
2491 // report problem | 2535 // report problem |
2492 _errorReporter.reportErrorForNode( | 2536 _errorReporter.reportErrorForNode( |
2493 StaticWarningCode.CONFLICTING_STATIC_SETTER_AND_INSTANCE_MEMBER, | 2537 StaticWarningCode.CONFLICTING_STATIC_SETTER_AND_INSTANCE_MEMBER, |
2494 nameNode, [memberType.displayName]); | 2538 nameNode, |
| 2539 [memberType.displayName]); |
2495 return true; | 2540 return true; |
2496 } | 2541 } |
2497 | 2542 |
2498 /** | 2543 /** |
2499 * Verify all conflicts between type variable and enclosing class. | 2544 * Verify all conflicts between type variable and enclosing class. |
2500 * TODO(scheglov) | 2545 * TODO(scheglov) |
2501 * | 2546 * |
2502 * See [CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_CLASS], and | 2547 * See [CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_CLASS], and |
2503 * [CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_MEMBER]. | 2548 * [CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_MEMBER]. |
2504 */ | 2549 */ |
2505 bool _checkForConflictingTypeVariableErrorCodes( | 2550 bool _checkForConflictingTypeVariableErrorCodes( |
2506 ClassDeclaration declaration) { | 2551 ClassDeclaration declaration) { |
2507 bool problemReported = false; | 2552 bool problemReported = false; |
2508 for (TypeParameterElement typeParameter in _enclosingClass.typeParameters) { | 2553 for (TypeParameterElement typeParameter in _enclosingClass.typeParameters) { |
2509 String name = typeParameter.name; | 2554 String name = typeParameter.name; |
2510 // name is same as the name of the enclosing class | 2555 // name is same as the name of the enclosing class |
2511 if (_enclosingClass.name == name) { | 2556 if (_enclosingClass.name == name) { |
2512 _errorReporter.reportErrorForOffset( | 2557 _errorReporter.reportErrorForElement( |
2513 CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_CLASS, | 2558 CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_CLASS, |
2514 typeParameter.nameOffset, name.length, [name]); | 2559 typeParameter, |
| 2560 [name]); |
2515 problemReported = true; | 2561 problemReported = true; |
2516 } | 2562 } |
2517 // check members | 2563 // check members |
2518 if (_enclosingClass.getMethod(name) != null || | 2564 if (_enclosingClass.getMethod(name) != null || |
2519 _enclosingClass.getGetter(name) != null || | 2565 _enclosingClass.getGetter(name) != null || |
2520 _enclosingClass.getSetter(name) != null) { | 2566 _enclosingClass.getSetter(name) != null) { |
2521 _errorReporter.reportErrorForOffset( | 2567 _errorReporter.reportErrorForElement( |
2522 CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_MEMBER, | 2568 CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_MEMBER, |
2523 typeParameter.nameOffset, name.length, [name]); | 2569 typeParameter, |
| 2570 [name]); |
2524 problemReported = true; | 2571 problemReported = true; |
2525 } | 2572 } |
2526 } | 2573 } |
2527 return problemReported; | 2574 return problemReported; |
2528 } | 2575 } |
2529 | 2576 |
2530 /** | 2577 /** |
2531 * Verify that if the given [constructor] declaration is 'const' then there | 2578 * Verify that if the given [constructor] declaration is 'const' then there |
2532 * are no invocations of non-'const' super constructors. | 2579 * are no invocations of non-'const' super constructors. |
2533 * | 2580 * |
(...skipping 18 matching lines...) Expand all Loading... |
2552 // try to find and check super constructor invocation | 2599 // try to find and check super constructor invocation |
2553 for (ConstructorInitializer initializer in constructor.initializers) { | 2600 for (ConstructorInitializer initializer in constructor.initializers) { |
2554 if (initializer is SuperConstructorInvocation) { | 2601 if (initializer is SuperConstructorInvocation) { |
2555 SuperConstructorInvocation superInvocation = initializer; | 2602 SuperConstructorInvocation superInvocation = initializer; |
2556 ConstructorElement element = superInvocation.staticElement; | 2603 ConstructorElement element = superInvocation.staticElement; |
2557 if (element == null || element.isConst) { | 2604 if (element == null || element.isConst) { |
2558 return false; | 2605 return false; |
2559 } | 2606 } |
2560 _errorReporter.reportErrorForNode( | 2607 _errorReporter.reportErrorForNode( |
2561 CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_NON_CONST_SUPER, | 2608 CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_NON_CONST_SUPER, |
2562 superInvocation, [element.enclosingElement.displayName]); | 2609 superInvocation, |
| 2610 [element.enclosingElement.displayName]); |
2563 return true; | 2611 return true; |
2564 } | 2612 } |
2565 } | 2613 } |
2566 // no explicit super constructor invocation, check default constructor | 2614 // no explicit super constructor invocation, check default constructor |
2567 InterfaceType supertype = _enclosingClass.supertype; | 2615 InterfaceType supertype = _enclosingClass.supertype; |
2568 if (supertype == null) { | 2616 if (supertype == null) { |
2569 return false; | 2617 return false; |
2570 } | 2618 } |
2571 if (supertype.isObject) { | 2619 if (supertype.isObject) { |
2572 return false; | 2620 return false; |
2573 } | 2621 } |
2574 ConstructorElement unnamedConstructor = | 2622 ConstructorElement unnamedConstructor = |
2575 supertype.element.unnamedConstructor; | 2623 supertype.element.unnamedConstructor; |
2576 if (unnamedConstructor == null) { | 2624 if (unnamedConstructor == null) { |
2577 return false; | 2625 return false; |
2578 } | 2626 } |
2579 if (unnamedConstructor.isConst) { | 2627 if (unnamedConstructor.isConst) { |
2580 return false; | 2628 return false; |
2581 } | 2629 } |
2582 // default constructor is not 'const', report problem | 2630 // default constructor is not 'const', report problem |
2583 _errorReporter.reportErrorForNode( | 2631 _errorReporter.reportErrorForNode( |
2584 CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_NON_CONST_SUPER, | 2632 CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_NON_CONST_SUPER, |
2585 constructor.returnType, [supertype.displayName]); | 2633 constructor.returnType, |
| 2634 [supertype.displayName]); |
2586 return true; | 2635 return true; |
2587 } | 2636 } |
2588 | 2637 |
2589 /** | 2638 /** |
2590 * Verify that if the given [constructor] declaration is 'const' then there | 2639 * Verify that if the given [constructor] declaration is 'const' then there |
2591 * are no non-final instance variable. The [constructorElement] is the | 2640 * are no non-final instance variable. The [constructorElement] is the |
2592 * constructor element. | 2641 * constructor element. |
2593 * | 2642 * |
2594 * See [CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_NON_FINAL_FIELD]. | 2643 * See [CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_NON_FINAL_FIELD]. |
2595 */ | 2644 */ |
(...skipping 20 matching lines...) Expand all Loading... |
2616 * creating a deferred type. The [constructorName] is the constructor name, | 2665 * creating a deferred type. The [constructorName] is the constructor name, |
2617 * always non-`null`. The [typeName] is the name of the type defining the | 2666 * always non-`null`. The [typeName] is the name of the type defining the |
2618 * constructor, always non-`null`. | 2667 * constructor, always non-`null`. |
2619 * | 2668 * |
2620 * See [CompileTimeErrorCode.CONST_DEFERRED_CLASS]. | 2669 * See [CompileTimeErrorCode.CONST_DEFERRED_CLASS]. |
2621 */ | 2670 */ |
2622 bool _checkForConstDeferredClass(InstanceCreationExpression expression, | 2671 bool _checkForConstDeferredClass(InstanceCreationExpression expression, |
2623 ConstructorName constructorName, TypeName typeName) { | 2672 ConstructorName constructorName, TypeName typeName) { |
2624 if (typeName.isDeferred) { | 2673 if (typeName.isDeferred) { |
2625 _errorReporter.reportErrorForNode( | 2674 _errorReporter.reportErrorForNode( |
2626 CompileTimeErrorCode.CONST_DEFERRED_CLASS, constructorName, | 2675 CompileTimeErrorCode.CONST_DEFERRED_CLASS, |
| 2676 constructorName, |
2627 [typeName.name.name]); | 2677 [typeName.name.name]); |
2628 return true; | 2678 return true; |
2629 } | 2679 } |
2630 return false; | 2680 return false; |
2631 } | 2681 } |
2632 | 2682 |
2633 /** | 2683 /** |
2634 * Verify that the given throw [expression] is not enclosed in a 'const' | 2684 * Verify that the given throw [expression] is not enclosed in a 'const' |
2635 * constructor declaration. | 2685 * constructor declaration. |
2636 * | 2686 * |
(...skipping 26 matching lines...) Expand all Loading... |
2663 * Verify that the given instance creation [expression] is not being invoked | 2713 * Verify that the given instance creation [expression] is not being invoked |
2664 * on an abstract class. The [typeName] is the [TypeName] of the | 2714 * on an abstract class. The [typeName] is the [TypeName] of the |
2665 * [ConstructorName] from the [InstanceCreationExpression], this is the AST | 2715 * [ConstructorName] from the [InstanceCreationExpression], this is the AST |
2666 * node that the error is attached to. The [type] is the type being | 2716 * node that the error is attached to. The [type] is the type being |
2667 * constructed with this [InstanceCreationExpression]. | 2717 * constructed with this [InstanceCreationExpression]. |
2668 * | 2718 * |
2669 * See [StaticWarningCode.CONST_WITH_ABSTRACT_CLASS], and | 2719 * See [StaticWarningCode.CONST_WITH_ABSTRACT_CLASS], and |
2670 * [StaticWarningCode.NEW_WITH_ABSTRACT_CLASS]. | 2720 * [StaticWarningCode.NEW_WITH_ABSTRACT_CLASS]. |
2671 */ | 2721 */ |
2672 bool _checkForConstOrNewWithAbstractClass( | 2722 bool _checkForConstOrNewWithAbstractClass( |
2673 InstanceCreationExpression expression, TypeName typeName, | 2723 InstanceCreationExpression expression, |
| 2724 TypeName typeName, |
2674 InterfaceType type) { | 2725 InterfaceType type) { |
2675 if (type.element.isAbstract) { | 2726 if (type.element.isAbstract) { |
2676 ConstructorElement element = expression.staticElement; | 2727 ConstructorElement element = expression.staticElement; |
2677 if (element != null && !element.isFactory) { | 2728 if (element != null && !element.isFactory) { |
2678 if ((expression.keyword as sc.KeywordToken).keyword == | 2729 if ((expression.keyword as sc.KeywordToken).keyword == |
2679 sc.Keyword.CONST) { | 2730 sc.Keyword.CONST) { |
2680 _errorReporter.reportErrorForNode( | 2731 _errorReporter.reportErrorForNode( |
2681 StaticWarningCode.CONST_WITH_ABSTRACT_CLASS, typeName); | 2732 StaticWarningCode.CONST_WITH_ABSTRACT_CLASS, typeName); |
2682 } else { | 2733 } else { |
2683 _errorReporter.reportErrorForNode( | 2734 _errorReporter.reportErrorForNode( |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2767 * constructor name, always non-`null`. The [typeName] is the name of the type | 2818 * constructor name, always non-`null`. The [typeName] is the name of the type |
2768 * defining the constructor, always non-`null`. | 2819 * defining the constructor, always non-`null`. |
2769 * | 2820 * |
2770 * This method assumes that the instance creation was tested to be 'const' | 2821 * This method assumes that the instance creation was tested to be 'const' |
2771 * before being called. | 2822 * before being called. |
2772 * | 2823 * |
2773 * See [CompileTimeErrorCode.CONST_WITH_UNDEFINED_CONSTRUCTOR], and | 2824 * See [CompileTimeErrorCode.CONST_WITH_UNDEFINED_CONSTRUCTOR], and |
2774 * [CompileTimeErrorCode.CONST_WITH_UNDEFINED_CONSTRUCTOR_DEFAULT]. | 2825 * [CompileTimeErrorCode.CONST_WITH_UNDEFINED_CONSTRUCTOR_DEFAULT]. |
2775 */ | 2826 */ |
2776 bool _checkForConstWithUndefinedConstructor( | 2827 bool _checkForConstWithUndefinedConstructor( |
2777 InstanceCreationExpression expression, ConstructorName constructorName, | 2828 InstanceCreationExpression expression, |
| 2829 ConstructorName constructorName, |
2778 TypeName typeName) { | 2830 TypeName typeName) { |
2779 // OK if resolved | 2831 // OK if resolved |
2780 if (expression.staticElement != null) { | 2832 if (expression.staticElement != null) { |
2781 return false; | 2833 return false; |
2782 } | 2834 } |
2783 DartType type = typeName.type; | 2835 DartType type = typeName.type; |
2784 if (type is InterfaceType) { | 2836 if (type is InterfaceType) { |
2785 ClassElement element = type.element; | 2837 ClassElement element = type.element; |
2786 if (element != null && element.isEnum) { | 2838 if (element != null && element.isEnum) { |
2787 // We have already reported the error. | 2839 // We have already reported the error. |
2788 return false; | 2840 return false; |
2789 } | 2841 } |
2790 } | 2842 } |
2791 Identifier className = typeName.name; | 2843 Identifier className = typeName.name; |
2792 // report as named or default constructor absence | 2844 // report as named or default constructor absence |
2793 SimpleIdentifier name = constructorName.name; | 2845 SimpleIdentifier name = constructorName.name; |
2794 if (name != null) { | 2846 if (name != null) { |
2795 _errorReporter.reportErrorForNode( | 2847 _errorReporter.reportErrorForNode( |
2796 CompileTimeErrorCode.CONST_WITH_UNDEFINED_CONSTRUCTOR, name, [ | 2848 CompileTimeErrorCode.CONST_WITH_UNDEFINED_CONSTRUCTOR, |
2797 className, | 2849 name, |
2798 name | 2850 [className, name]); |
2799 ]); | |
2800 } else { | 2851 } else { |
2801 _errorReporter.reportErrorForNode( | 2852 _errorReporter.reportErrorForNode( |
2802 CompileTimeErrorCode.CONST_WITH_UNDEFINED_CONSTRUCTOR_DEFAULT, | 2853 CompileTimeErrorCode.CONST_WITH_UNDEFINED_CONSTRUCTOR_DEFAULT, |
2803 constructorName, [className]); | 2854 constructorName, |
| 2855 [className]); |
2804 } | 2856 } |
2805 return true; | 2857 return true; |
2806 } | 2858 } |
2807 | 2859 |
2808 /** | 2860 /** |
2809 * Verify that there are no default parameters in the given function type | 2861 * Verify that there are no default parameters in the given function type |
2810 * [alias]. | 2862 * [alias]. |
2811 * | 2863 * |
2812 * See [CompileTimeErrorCode.DEFAULT_VALUE_IN_FUNCTION_TYPE_ALIAS]. | 2864 * See [CompileTimeErrorCode.DEFAULT_VALUE_IN_FUNCTION_TYPE_ALIAS]. |
2813 */ | 2865 */ |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2942 // determine the display name, use the extended display name if the | 2994 // determine the display name, use the extended display name if the |
2943 // enclosing class of the inherited member is in a different source | 2995 // enclosing class of the inherited member is in a different source |
2944 String displayName; | 2996 String displayName; |
2945 Element enclosingElement = inheritedMember.enclosingElement; | 2997 Element enclosingElement = inheritedMember.enclosingElement; |
2946 if (enclosingElement.source == _enclosingClass.source) { | 2998 if (enclosingElement.source == _enclosingClass.source) { |
2947 displayName = enclosingElement.displayName; | 2999 displayName = enclosingElement.displayName; |
2948 } else { | 3000 } else { |
2949 displayName = enclosingElement.getExtendedDisplayName(null); | 3001 displayName = enclosingElement.getExtendedDisplayName(null); |
2950 } | 3002 } |
2951 // report problem | 3003 // report problem |
2952 _errorReporter.reportErrorForOffset( | 3004 _errorReporter.reportErrorForElement( |
2953 CompileTimeErrorCode.DUPLICATE_DEFINITION_INHERITANCE, | 3005 CompileTimeErrorCode.DUPLICATE_DEFINITION_INHERITANCE, |
2954 staticMember.nameOffset, name.length, [name, displayName]); | 3006 staticMember, |
| 3007 [name, displayName]); |
2955 return true; | 3008 return true; |
2956 } | 3009 } |
2957 | 3010 |
2958 /** | 3011 /** |
2959 * Verify that if the given list [literal] has type arguments then there is | 3012 * Verify that if the given list [literal] has type arguments then there is |
2960 * exactly one. The [typeArguments] are the type arguments. | 3013 * exactly one. The [typeArguments] are the type arguments. |
2961 * | 3014 * |
2962 * See [StaticTypeWarningCode.EXPECTED_ONE_LIST_TYPE_ARGUMENTS]. | 3015 * See [StaticTypeWarningCode.EXPECTED_ONE_LIST_TYPE_ARGUMENTS]. |
2963 */ | 3016 */ |
2964 bool _checkForExpectedOneListTypeArgument( | 3017 bool _checkForExpectedOneListTypeArgument( |
2965 ListLiteral literal, TypeArgumentList typeArguments) { | 3018 ListLiteral literal, TypeArgumentList typeArguments) { |
2966 // check number of type arguments | 3019 // check number of type arguments |
2967 int num = typeArguments.arguments.length; | 3020 int num = typeArguments.arguments.length; |
2968 if (num == 1) { | 3021 if (num == 1) { |
2969 return false; | 3022 return false; |
2970 } | 3023 } |
2971 // report problem | 3024 // report problem |
2972 _errorReporter.reportErrorForNode( | 3025 _errorReporter.reportErrorForNode( |
2973 StaticTypeWarningCode.EXPECTED_ONE_LIST_TYPE_ARGUMENTS, typeArguments, | 3026 StaticTypeWarningCode.EXPECTED_ONE_LIST_TYPE_ARGUMENTS, |
| 3027 typeArguments, |
2974 [num]); | 3028 [num]); |
2975 return true; | 3029 return true; |
2976 } | 3030 } |
2977 | 3031 |
2978 /** | 3032 /** |
2979 * Verify that the given export [directive] has a unique name among other | 3033 * Verify that the given export [directive] has a unique name among other |
2980 * exported libraries. The [exportElement] is the [ExportElement] retrieved | 3034 * exported libraries. The [exportElement] is the [ExportElement] retrieved |
2981 * from the node, if the element in the node was `null`, then this method is | 3035 * from the node, if the element in the node was `null`, then this method is |
2982 * not called. The [exportedLibrary] is the library element containing the | 3036 * not called. The [exportedLibrary] is the library element containing the |
2983 * exported element. | 3037 * exported element. |
2984 * | 3038 * |
2985 * See [CompileTimeErrorCode.EXPORT_DUPLICATED_LIBRARY_NAME]. | 3039 * See [CompileTimeErrorCode.EXPORT_DUPLICATED_LIBRARY_NAME]. |
2986 */ | 3040 */ |
2987 bool _checkForExportDuplicateLibraryName(ExportDirective directive, | 3041 bool _checkForExportDuplicateLibraryName(ExportDirective directive, |
2988 ExportElement exportElement, LibraryElement exportedLibrary) { | 3042 ExportElement exportElement, LibraryElement exportedLibrary) { |
2989 if (exportedLibrary == null) { | 3043 if (exportedLibrary == null) { |
2990 return false; | 3044 return false; |
2991 } | 3045 } |
2992 String name = exportedLibrary.name; | 3046 String name = exportedLibrary.name; |
2993 // check if there is other exported library with the same name | 3047 // check if there is other exported library with the same name |
2994 LibraryElement prevLibrary = _nameToExportElement[name]; | 3048 LibraryElement prevLibrary = _nameToExportElement[name]; |
2995 if (prevLibrary != null) { | 3049 if (prevLibrary != null) { |
2996 if (prevLibrary != exportedLibrary) { | 3050 if (prevLibrary != exportedLibrary) { |
2997 if (name.isEmpty) { | 3051 if (!name.isEmpty) { |
2998 _errorReporter.reportErrorForNode( | |
2999 StaticWarningCode.EXPORT_DUPLICATED_LIBRARY_UNNAMED, directive, [ | |
3000 prevLibrary.definingCompilationUnit.displayName, | |
3001 exportedLibrary.definingCompilationUnit.displayName | |
3002 ]); | |
3003 } else { | |
3004 _errorReporter.reportErrorForNode( | 3052 _errorReporter.reportErrorForNode( |
3005 StaticWarningCode.EXPORT_DUPLICATED_LIBRARY_NAMED, directive, [ | 3053 StaticWarningCode.EXPORT_DUPLICATED_LIBRARY_NAMED, directive, [ |
3006 prevLibrary.definingCompilationUnit.displayName, | 3054 prevLibrary.definingCompilationUnit.displayName, |
3007 exportedLibrary.definingCompilationUnit.displayName, | 3055 exportedLibrary.definingCompilationUnit.displayName, |
3008 name | 3056 name |
3009 ]); | 3057 ]); |
3010 } | 3058 } |
3011 return true; | 3059 return true; |
3012 } | 3060 } |
3013 } else { | 3061 } else { |
(...skipping 21 matching lines...) Expand all Loading... |
3035 String uri = exportElement.uri; | 3083 String uri = exportElement.uri; |
3036 SdkLibrary sdkLibrary = sdk.getSdkLibrary(uri); | 3084 SdkLibrary sdkLibrary = sdk.getSdkLibrary(uri); |
3037 if (sdkLibrary == null) { | 3085 if (sdkLibrary == null) { |
3038 return false; | 3086 return false; |
3039 } | 3087 } |
3040 if (!sdkLibrary.isInternal) { | 3088 if (!sdkLibrary.isInternal) { |
3041 return false; | 3089 return false; |
3042 } | 3090 } |
3043 // report problem | 3091 // report problem |
3044 _errorReporter.reportErrorForNode( | 3092 _errorReporter.reportErrorForNode( |
3045 CompileTimeErrorCode.EXPORT_INTERNAL_LIBRARY, directive, | 3093 CompileTimeErrorCode.EXPORT_INTERNAL_LIBRARY, |
| 3094 directive, |
3046 [directive.uri]); | 3095 [directive.uri]); |
3047 return true; | 3096 return true; |
3048 } | 3097 } |
3049 | 3098 |
3050 /** | 3099 /** |
3051 * Verify that the given extends [clause] does not extend a deferred class. | 3100 * Verify that the given extends [clause] does not extend a deferred class. |
3052 * | 3101 * |
3053 * See [CompileTimeErrorCode.EXTENDS_DEFERRED_CLASS]. | 3102 * See [CompileTimeErrorCode.EXTENDS_DEFERRED_CLASS]. |
3054 */ | 3103 */ |
3055 bool _checkForExtendsDeferredClass(ExtendsClause clause) { | 3104 bool _checkForExtendsDeferredClass(ExtendsClause clause) { |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3136 * [_checkForAllMixinErrorCodes], | 3185 * [_checkForAllMixinErrorCodes], |
3137 * [CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS], | 3186 * [CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS], |
3138 * [CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS], and | 3187 * [CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS], and |
3139 * [CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS]. | 3188 * [CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS]. |
3140 */ | 3189 */ |
3141 bool _checkForExtendsOrImplementsDisallowedClass( | 3190 bool _checkForExtendsOrImplementsDisallowedClass( |
3142 TypeName typeName, ErrorCode errorCode) { | 3191 TypeName typeName, ErrorCode errorCode) { |
3143 if (typeName.isSynthetic) { | 3192 if (typeName.isSynthetic) { |
3144 return false; | 3193 return false; |
3145 } | 3194 } |
| 3195 // The SDK implementation may implement disallowed types. For example, |
| 3196 // JSNumber in dart2js and _Smi in Dart VM both implement int. |
| 3197 if (_currentLibrary.source.isInSystemLibrary) { |
| 3198 return false; |
| 3199 } |
3146 DartType superType = typeName.type; | 3200 DartType superType = typeName.type; |
3147 for (InterfaceType disallowedType | 3201 for (InterfaceType disallowedType |
3148 in _DISALLOWED_TYPES_TO_EXTEND_OR_IMPLEMENT) { | 3202 in _DISALLOWED_TYPES_TO_EXTEND_OR_IMPLEMENT) { |
3149 if (superType != null && superType == disallowedType) { | 3203 if (superType != null && superType == disallowedType) { |
3150 // if the violating type happens to be 'num', we need to rule out the | 3204 // if the violating type happens to be 'num', we need to rule out the |
3151 // case where the enclosing class is 'int' or 'double' | 3205 // case where the enclosing class is 'int' or 'double' |
3152 if (superType == _typeProvider.numType) { | 3206 if (superType == _typeProvider.numType) { |
3153 AstNode grandParent = typeName.parent.parent; | 3207 AstNode grandParent = typeName.parent.parent; |
3154 // Note: this is a corner case that won't happen often, so adding a | 3208 // Note: this is a corner case that won't happen often, so adding a |
3155 // field currentClass (see currentFunction) to ErrorVerifier isn't | 3209 // field currentClass (see currentFunction) to ErrorVerifier isn't |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3195 // prepare expression type | 3249 // prepare expression type |
3196 Expression expression = initializer.expression; | 3250 Expression expression = initializer.expression; |
3197 if (expression == null) { | 3251 if (expression == null) { |
3198 return false; | 3252 return false; |
3199 } | 3253 } |
3200 // test the static type of the expression | 3254 // test the static type of the expression |
3201 DartType staticType = getStaticType(expression); | 3255 DartType staticType = getStaticType(expression); |
3202 if (staticType == null) { | 3256 if (staticType == null) { |
3203 return false; | 3257 return false; |
3204 } | 3258 } |
3205 if (staticType.isAssignableTo(fieldType)) { | 3259 if (_typeSystem.isAssignableTo(staticType, fieldType)) { |
3206 return false; | 3260 return false; |
3207 } | 3261 } |
3208 // report problem | 3262 // report problem |
3209 if (_isEnclosingConstructorConst) { | 3263 if (_isEnclosingConstructorConst) { |
3210 // TODO(paulberry): this error should be based on the actual type of the | 3264 // TODO(paulberry): this error should be based on the actual type of the |
3211 // constant, not the static type. See dartbug.com/21119. | 3265 // constant, not the static type. See dartbug.com/21119. |
3212 _errorReporter.reportTypeErrorForNode( | 3266 _errorReporter.reportTypeErrorForNode( |
3213 CheckedModeCompileTimeErrorCode.CONST_FIELD_INITIALIZER_NOT_ASSIGNABLE
, | 3267 CheckedModeCompileTimeErrorCode.CONST_FIELD_INITIALIZER_NOT_ASSIGNABLE
, |
3214 expression, [staticType, fieldType]); | 3268 expression, |
| 3269 [staticType, fieldType]); |
3215 } | 3270 } |
3216 _errorReporter.reportTypeErrorForNode( | 3271 _errorReporter.reportTypeErrorForNode( |
3217 StaticWarningCode.FIELD_INITIALIZER_NOT_ASSIGNABLE, expression, [ | 3272 StaticWarningCode.FIELD_INITIALIZER_NOT_ASSIGNABLE, |
3218 staticType, | 3273 expression, |
3219 fieldType | 3274 [staticType, fieldType]); |
3220 ]); | |
3221 return true; | 3275 return true; |
3222 // TODO(brianwilkerson) Define a hint corresponding to these errors and | 3276 // TODO(brianwilkerson) Define a hint corresponding to these errors and |
3223 // report it if appropriate. | 3277 // report it if appropriate. |
3224 // // test the propagated type of the expression | 3278 // // test the propagated type of the expression |
3225 // Type propagatedType = expression.getPropagatedType(); | 3279 // Type propagatedType = expression.getPropagatedType(); |
3226 // if (propagatedType != null && propagatedType.isAssignableTo(fieldType)
) { | 3280 // if (propagatedType != null && propagatedType.isAssignableTo(fieldType)
) { |
3227 // return false; | 3281 // return false; |
3228 // } | 3282 // } |
3229 // // report problem | 3283 // // report problem |
3230 // if (isEnclosingConstructorConst) { | 3284 // if (isEnclosingConstructorConst) { |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3290 if (_isInNativeClass) { | 3344 if (_isInNativeClass) { |
3291 return false; | 3345 return false; |
3292 } | 3346 } |
3293 bool foundError = false; | 3347 bool foundError = false; |
3294 if (!list.isSynthetic) { | 3348 if (!list.isSynthetic) { |
3295 NodeList<VariableDeclaration> variables = list.variables; | 3349 NodeList<VariableDeclaration> variables = list.variables; |
3296 for (VariableDeclaration variable in variables) { | 3350 for (VariableDeclaration variable in variables) { |
3297 if (variable.initializer == null) { | 3351 if (variable.initializer == null) { |
3298 if (list.isConst) { | 3352 if (list.isConst) { |
3299 _errorReporter.reportErrorForNode( | 3353 _errorReporter.reportErrorForNode( |
3300 CompileTimeErrorCode.CONST_NOT_INITIALIZED, variable.name, | 3354 CompileTimeErrorCode.CONST_NOT_INITIALIZED, |
| 3355 variable.name, |
3301 [variable.name.name]); | 3356 [variable.name.name]); |
3302 } else if (list.isFinal) { | 3357 } else if (list.isFinal) { |
3303 _errorReporter.reportErrorForNode( | 3358 _errorReporter.reportErrorForNode( |
3304 StaticWarningCode.FINAL_NOT_INITIALIZED, variable.name, | 3359 StaticWarningCode.FINAL_NOT_INITIALIZED, |
| 3360 variable.name, |
3305 [variable.name.name]); | 3361 [variable.name.name]); |
3306 } | 3362 } |
3307 foundError = true; | 3363 foundError = true; |
3308 } | 3364 } |
3309 } | 3365 } |
3310 } | 3366 } |
3311 return foundError; | 3367 return foundError; |
3312 } | 3368 } |
3313 | 3369 |
3314 /** | 3370 /** |
(...skipping 28 matching lines...) Expand all Loading... |
3343 * respectively. If not, report the error using [returnType]. | 3399 * respectively. If not, report the error using [returnType]. |
3344 */ | 3400 */ |
3345 void _checkForIllegalReturnType(TypeName returnType) { | 3401 void _checkForIllegalReturnType(TypeName returnType) { |
3346 if (returnType == null) { | 3402 if (returnType == null) { |
3347 // No declared return type, so the return type must be dynamic, which is | 3403 // No declared return type, so the return type must be dynamic, which is |
3348 // assignable to everything. | 3404 // assignable to everything. |
3349 return; | 3405 return; |
3350 } | 3406 } |
3351 if (_enclosingFunction.isAsynchronous) { | 3407 if (_enclosingFunction.isAsynchronous) { |
3352 if (_enclosingFunction.isGenerator) { | 3408 if (_enclosingFunction.isGenerator) { |
3353 if (!_enclosingFunction.returnType | 3409 if (!_typeSystem.isAssignableTo( |
3354 .isAssignableTo(_typeProvider.streamDynamicType)) { | 3410 _enclosingFunction.returnType, _typeProvider.streamDynamicType)) { |
3355 _errorReporter.reportErrorForNode( | 3411 _errorReporter.reportErrorForNode( |
3356 StaticTypeWarningCode.ILLEGAL_ASYNC_GENERATOR_RETURN_TYPE, | 3412 StaticTypeWarningCode.ILLEGAL_ASYNC_GENERATOR_RETURN_TYPE, |
3357 returnType); | 3413 returnType); |
3358 } | 3414 } |
3359 } else { | 3415 } else { |
3360 if (!_enclosingFunction.returnType | 3416 if (!_typeSystem.isAssignableTo( |
3361 .isAssignableTo(_typeProvider.futureDynamicType)) { | 3417 _enclosingFunction.returnType, _typeProvider.futureDynamicType)) { |
3362 _errorReporter.reportErrorForNode( | 3418 _errorReporter.reportErrorForNode( |
3363 StaticTypeWarningCode.ILLEGAL_ASYNC_RETURN_TYPE, returnType); | 3419 StaticTypeWarningCode.ILLEGAL_ASYNC_RETURN_TYPE, returnType); |
3364 } | 3420 } |
3365 } | 3421 } |
3366 } else if (_enclosingFunction.isGenerator) { | 3422 } else if (_enclosingFunction.isGenerator) { |
3367 if (!_enclosingFunction.returnType | 3423 if (!_typeSystem.isAssignableTo( |
3368 .isAssignableTo(_typeProvider.iterableDynamicType)) { | 3424 _enclosingFunction.returnType, _typeProvider.iterableDynamicType)) { |
3369 _errorReporter.reportErrorForNode( | 3425 _errorReporter.reportErrorForNode( |
3370 StaticTypeWarningCode.ILLEGAL_SYNC_GENERATOR_RETURN_TYPE, | 3426 StaticTypeWarningCode.ILLEGAL_SYNC_GENERATOR_RETURN_TYPE, |
3371 returnType); | 3427 returnType); |
3372 } | 3428 } |
3373 } | 3429 } |
3374 } | 3430 } |
3375 | 3431 |
3376 /** | 3432 /** |
3377 * Verify that the given implements [clause] does not implement classes that | 3433 * Verify that the given implements [clause] does not implement classes that |
3378 * are deferred. | 3434 * are deferred. |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3500 // prepare imported library | 3556 // prepare imported library |
3501 LibraryElement nodeLibrary = importElement.importedLibrary; | 3557 LibraryElement nodeLibrary = importElement.importedLibrary; |
3502 if (nodeLibrary == null) { | 3558 if (nodeLibrary == null) { |
3503 return false; | 3559 return false; |
3504 } | 3560 } |
3505 String name = nodeLibrary.name; | 3561 String name = nodeLibrary.name; |
3506 // check if there is another imported library with the same name | 3562 // check if there is another imported library with the same name |
3507 LibraryElement prevLibrary = _nameToImportElement[name]; | 3563 LibraryElement prevLibrary = _nameToImportElement[name]; |
3508 if (prevLibrary != null) { | 3564 if (prevLibrary != null) { |
3509 if (prevLibrary != nodeLibrary) { | 3565 if (prevLibrary != nodeLibrary) { |
3510 if (name.isEmpty) { | 3566 if (!name.isEmpty) { |
3511 _errorReporter.reportErrorForNode( | |
3512 StaticWarningCode.IMPORT_DUPLICATED_LIBRARY_UNNAMED, directive, [ | |
3513 prevLibrary.definingCompilationUnit.displayName, | |
3514 nodeLibrary.definingCompilationUnit.displayName | |
3515 ]); | |
3516 } else { | |
3517 _errorReporter.reportErrorForNode( | 3567 _errorReporter.reportErrorForNode( |
3518 StaticWarningCode.IMPORT_DUPLICATED_LIBRARY_NAMED, directive, [ | 3568 StaticWarningCode.IMPORT_DUPLICATED_LIBRARY_NAMED, directive, [ |
3519 prevLibrary.definingCompilationUnit.displayName, | 3569 prevLibrary.definingCompilationUnit.displayName, |
3520 nodeLibrary.definingCompilationUnit.displayName, | 3570 nodeLibrary.definingCompilationUnit.displayName, |
3521 name | 3571 name |
3522 ]); | 3572 ]); |
3523 } | 3573 } |
3524 return true; | 3574 return true; |
3525 } | 3575 } |
3526 } else { | 3576 } else { |
(...skipping 21 matching lines...) Expand all Loading... |
3548 String uri = importElement.uri; | 3598 String uri = importElement.uri; |
3549 SdkLibrary sdkLibrary = sdk.getSdkLibrary(uri); | 3599 SdkLibrary sdkLibrary = sdk.getSdkLibrary(uri); |
3550 if (sdkLibrary == null) { | 3600 if (sdkLibrary == null) { |
3551 return false; | 3601 return false; |
3552 } | 3602 } |
3553 if (!sdkLibrary.isInternal) { | 3603 if (!sdkLibrary.isInternal) { |
3554 return false; | 3604 return false; |
3555 } | 3605 } |
3556 // report problem | 3606 // report problem |
3557 _errorReporter.reportErrorForNode( | 3607 _errorReporter.reportErrorForNode( |
3558 CompileTimeErrorCode.IMPORT_INTERNAL_LIBRARY, directive, | 3608 CompileTimeErrorCode.IMPORT_INTERNAL_LIBRARY, |
| 3609 directive, |
3559 [directive.uri]); | 3610 [directive.uri]); |
3560 return true; | 3611 return true; |
3561 } | 3612 } |
3562 | 3613 |
3563 /** | 3614 /** |
3564 * For each class declaration, this method is called which verifies that all | 3615 * For each class declaration, this method is called which verifies that all |
3565 * inherited members are inherited consistently. | 3616 * inherited members are inherited consistently. |
3566 * | 3617 * |
3567 * See [StaticTypeWarningCode.INCONSISTENT_METHOD_INHERITANCE]. | 3618 * See [StaticTypeWarningCode.INCONSISTENT_METHOD_INHERITANCE]. |
3568 */ | 3619 */ |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3607 // OK, top-level element | 3658 // OK, top-level element |
3608 if (executableElement.enclosingElement is! ClassElement) { | 3659 if (executableElement.enclosingElement is! ClassElement) { |
3609 return false; | 3660 return false; |
3610 } | 3661 } |
3611 // OK, instance member | 3662 // OK, instance member |
3612 if (!executableElement.isStatic) { | 3663 if (!executableElement.isStatic) { |
3613 return false; | 3664 return false; |
3614 } | 3665 } |
3615 // report problem | 3666 // report problem |
3616 _errorReporter.reportErrorForNode( | 3667 _errorReporter.reportErrorForNode( |
3617 StaticTypeWarningCode.INSTANCE_ACCESS_TO_STATIC_MEMBER, name, | 3668 StaticTypeWarningCode.INSTANCE_ACCESS_TO_STATIC_MEMBER, |
| 3669 name, |
3618 [name.name]); | 3670 [name.name]); |
3619 return true; | 3671 return true; |
3620 } | 3672 } |
3621 | 3673 |
3622 /** | 3674 /** |
3623 * Check whether the given [executableElement] collides with the name of a | 3675 * Check whether the given [executableElement] collides with the name of a |
3624 * static method in one of its superclasses, and reports the appropriate | 3676 * static method in one of its superclasses, and reports the appropriate |
3625 * warning if it does. The [errorNameTarget] is the node to report problems | 3677 * warning if it does. The [errorNameTarget] is the node to report problems |
3626 * on. | 3678 * on. |
3627 * | 3679 * |
(...skipping 20 matching lines...) Expand all Loading... |
3648 if (fieldElt != null) { | 3700 if (fieldElt != null) { |
3649 // Ignore if private in a different library - cannot collide. | 3701 // Ignore if private in a different library - cannot collide. |
3650 if (executableElementPrivate && | 3702 if (executableElementPrivate && |
3651 _currentLibrary != superclassLibrary) { | 3703 _currentLibrary != superclassLibrary) { |
3652 continue; | 3704 continue; |
3653 } | 3705 } |
3654 // instance vs. static | 3706 // instance vs. static |
3655 if (fieldElt.isStatic) { | 3707 if (fieldElt.isStatic) { |
3656 _errorReporter.reportErrorForNode( | 3708 _errorReporter.reportErrorForNode( |
3657 StaticWarningCode.INSTANCE_METHOD_NAME_COLLIDES_WITH_SUPERCLASS_
STATIC, | 3709 StaticWarningCode.INSTANCE_METHOD_NAME_COLLIDES_WITH_SUPERCLASS_
STATIC, |
3658 errorNameTarget, [ | 3710 errorNameTarget, |
3659 executableElementName, | 3711 [executableElementName, fieldElt.enclosingElement.displayName]); |
3660 fieldElt.enclosingElement.displayName | |
3661 ]); | |
3662 return true; | 3712 return true; |
3663 } | 3713 } |
3664 } | 3714 } |
3665 // Check methods. | 3715 // Check methods. |
3666 List<MethodElement> methodElements = superclassElement.methods; | 3716 List<MethodElement> methodElements = superclassElement.methods; |
3667 for (MethodElement methodElement in methodElements) { | 3717 for (MethodElement methodElement in methodElements) { |
3668 // We need the same name. | 3718 // We need the same name. |
3669 if (methodElement.name != executableElementName) { | 3719 if (methodElement.name != executableElementName) { |
3670 continue; | 3720 continue; |
3671 } | 3721 } |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3737 */ | 3787 */ |
3738 bool _checkForInvalidAssignment(Expression lhs, Expression rhs) { | 3788 bool _checkForInvalidAssignment(Expression lhs, Expression rhs) { |
3739 if (lhs == null || rhs == null) { | 3789 if (lhs == null || rhs == null) { |
3740 return false; | 3790 return false; |
3741 } | 3791 } |
3742 VariableElement leftVariableElement = getVariableElement(lhs); | 3792 VariableElement leftVariableElement = getVariableElement(lhs); |
3743 DartType leftType = (leftVariableElement == null) | 3793 DartType leftType = (leftVariableElement == null) |
3744 ? getStaticType(lhs) | 3794 ? getStaticType(lhs) |
3745 : leftVariableElement.type; | 3795 : leftVariableElement.type; |
3746 DartType staticRightType = getStaticType(rhs); | 3796 DartType staticRightType = getStaticType(rhs); |
3747 if (!staticRightType.isAssignableTo(leftType)) { | 3797 if (!_typeSystem.isAssignableTo(staticRightType, leftType)) { |
3748 _errorReporter.reportTypeErrorForNode( | 3798 _errorReporter.reportTypeErrorForNode( |
3749 StaticTypeWarningCode.INVALID_ASSIGNMENT, rhs, [ | 3799 StaticTypeWarningCode.INVALID_ASSIGNMENT, |
3750 staticRightType, | 3800 rhs, |
3751 leftType | 3801 [staticRightType, leftType]); |
3752 ]); | |
3753 return true; | 3802 return true; |
3754 } | 3803 } |
3755 return false; | 3804 return false; |
3756 } | 3805 } |
3757 | 3806 |
3758 /** | 3807 /** |
3759 * Given an [assignment] using a compound assignment operator, this verifies | 3808 * Given an [assignment] using a compound assignment operator, this verifies |
3760 * that the given assignment is valid. The [lhs] is the left hand side | 3809 * that the given assignment is valid. The [lhs] is the left hand side |
3761 * expression. The [rhs] is the right hand side expression. | 3810 * expression. The [rhs] is the right hand side expression. |
3762 * | 3811 * |
3763 * See [StaticTypeWarningCode.INVALID_ASSIGNMENT]. | 3812 * See [StaticTypeWarningCode.INVALID_ASSIGNMENT]. |
3764 */ | 3813 */ |
3765 bool _checkForInvalidCompoundAssignment( | 3814 bool _checkForInvalidCompoundAssignment( |
3766 AssignmentExpression assignment, Expression lhs, Expression rhs) { | 3815 AssignmentExpression assignment, Expression lhs, Expression rhs) { |
3767 if (lhs == null) { | 3816 if (lhs == null) { |
3768 return false; | 3817 return false; |
3769 } | 3818 } |
3770 VariableElement leftVariableElement = getVariableElement(lhs); | 3819 VariableElement leftVariableElement = getVariableElement(lhs); |
3771 DartType leftType = (leftVariableElement == null) | 3820 DartType leftType = (leftVariableElement == null) |
3772 ? getStaticType(lhs) | 3821 ? getStaticType(lhs) |
3773 : leftVariableElement.type; | 3822 : leftVariableElement.type; |
3774 MethodElement invokedMethod = assignment.staticElement; | 3823 MethodElement invokedMethod = assignment.staticElement; |
3775 if (invokedMethod == null) { | 3824 if (invokedMethod == null) { |
3776 return false; | 3825 return false; |
3777 } | 3826 } |
3778 DartType rightType = invokedMethod.type.returnType; | 3827 DartType rightType = invokedMethod.type.returnType; |
3779 if (leftType == null || rightType == null) { | 3828 if (leftType == null || rightType == null) { |
3780 return false; | 3829 return false; |
3781 } | 3830 } |
3782 if (!rightType.isAssignableTo(leftType)) { | 3831 if (!_typeSystem.isAssignableTo(rightType, leftType)) { |
3783 _errorReporter.reportTypeErrorForNode( | 3832 _errorReporter.reportTypeErrorForNode( |
3784 StaticTypeWarningCode.INVALID_ASSIGNMENT, rhs, [rightType, leftType]); | 3833 StaticTypeWarningCode.INVALID_ASSIGNMENT, rhs, [rightType, leftType]); |
3785 return true; | 3834 return true; |
3786 } | 3835 } |
3787 return false; | 3836 return false; |
3788 } | 3837 } |
3789 | 3838 |
3790 /** | 3839 /** |
3791 * Check the given [initializer] to ensure that the field being initialized is | 3840 * Check the given [initializer] to ensure that the field being initialized is |
3792 * a valid field. The [fieldName] is the field name from the | 3841 * a valid field. The [fieldName] is the field name from the |
3793 * [ConstructorFieldInitializer]. The [staticElement] is the static element | 3842 * [ConstructorFieldInitializer]. The [staticElement] is the static element |
3794 * from the name in the [ConstructorFieldInitializer]. | 3843 * from the name in the [ConstructorFieldInitializer]. |
3795 */ | 3844 */ |
3796 void _checkForInvalidField(ConstructorFieldInitializer initializer, | 3845 void _checkForInvalidField(ConstructorFieldInitializer initializer, |
3797 SimpleIdentifier fieldName, Element staticElement) { | 3846 SimpleIdentifier fieldName, Element staticElement) { |
3798 if (staticElement is FieldElement) { | 3847 if (staticElement is FieldElement) { |
3799 FieldElement fieldElement = staticElement; | 3848 FieldElement fieldElement = staticElement; |
3800 if (fieldElement.isSynthetic) { | 3849 if (fieldElement.isSynthetic) { |
3801 _errorReporter.reportErrorForNode( | 3850 _errorReporter.reportErrorForNode( |
3802 CompileTimeErrorCode.INITIALIZER_FOR_NON_EXISTENT_FIELD, | 3851 CompileTimeErrorCode.INITIALIZER_FOR_NON_EXISTENT_FIELD, |
3803 initializer, [fieldName]); | 3852 initializer, |
| 3853 [fieldName]); |
3804 } else if (fieldElement.isStatic) { | 3854 } else if (fieldElement.isStatic) { |
3805 _errorReporter.reportErrorForNode( | 3855 _errorReporter.reportErrorForNode( |
3806 CompileTimeErrorCode.INITIALIZER_FOR_STATIC_FIELD, initializer, | 3856 CompileTimeErrorCode.INITIALIZER_FOR_STATIC_FIELD, |
| 3857 initializer, |
3807 [fieldName]); | 3858 [fieldName]); |
3808 } | 3859 } |
3809 } else { | 3860 } else { |
3810 _errorReporter.reportErrorForNode( | 3861 _errorReporter.reportErrorForNode( |
3811 CompileTimeErrorCode.INITIALIZER_FOR_NON_EXISTENT_FIELD, initializer, | 3862 CompileTimeErrorCode.INITIALIZER_FOR_NON_EXISTENT_FIELD, |
| 3863 initializer, |
3812 [fieldName]); | 3864 [fieldName]); |
3813 return; | 3865 return; |
3814 } | 3866 } |
3815 } | 3867 } |
3816 | 3868 |
3817 /** | 3869 /** |
3818 * Check to see whether the given function [body] has a modifier associated | 3870 * Check to see whether the given function [body] has a modifier associated |
3819 * with it, and report it as an error if it does. | 3871 * with it, and report it as an error if it does. |
3820 */ | 3872 */ |
3821 bool _checkForInvalidModifierOnBody( | 3873 bool _checkForInvalidModifierOnBody( |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3873 if (typeNames.length < 1) { | 3925 if (typeNames.length < 1) { |
3874 return false; | 3926 return false; |
3875 } | 3927 } |
3876 DartType listElementType = typeNames[0].type; | 3928 DartType listElementType = typeNames[0].type; |
3877 // Check every list element. | 3929 // Check every list element. |
3878 bool hasProblems = false; | 3930 bool hasProblems = false; |
3879 for (Expression element in literal.elements) { | 3931 for (Expression element in literal.elements) { |
3880 if (literal.constKeyword != null) { | 3932 if (literal.constKeyword != null) { |
3881 // TODO(paulberry): this error should be based on the actual type of the | 3933 // TODO(paulberry): this error should be based on the actual type of the |
3882 // list element, not the static type. See dartbug.com/21119. | 3934 // list element, not the static type. See dartbug.com/21119. |
3883 if (_checkForArgumentTypeNotAssignableWithExpectedTypes(element, | 3935 if (_checkForArgumentTypeNotAssignableWithExpectedTypes( |
| 3936 element, |
3884 listElementType, | 3937 listElementType, |
3885 CheckedModeCompileTimeErrorCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE)) { | 3938 CheckedModeCompileTimeErrorCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE)) { |
3886 hasProblems = true; | 3939 hasProblems = true; |
3887 } | 3940 } |
3888 } | 3941 } |
3889 if (_checkForArgumentTypeNotAssignableWithExpectedTypes(element, | 3942 if (_checkForArgumentTypeNotAssignableWithExpectedTypes( |
| 3943 element, |
3890 listElementType, | 3944 listElementType, |
3891 StaticWarningCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE)) { | 3945 StaticWarningCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE)) { |
3892 hasProblems = true; | 3946 hasProblems = true; |
3893 } | 3947 } |
3894 } | 3948 } |
3895 return hasProblems; | 3949 return hasProblems; |
3896 } | 3950 } |
3897 | 3951 |
3898 /** | 3952 /** |
3899 * Verify that the key/value of entries of the given map [literal] are | 3953 * Verify that the key/value of entries of the given map [literal] are |
(...skipping 20 matching lines...) Expand all Loading... |
3920 for (MapLiteralEntry entry in entries) { | 3974 for (MapLiteralEntry entry in entries) { |
3921 Expression key = entry.key; | 3975 Expression key = entry.key; |
3922 Expression value = entry.value; | 3976 Expression value = entry.value; |
3923 if (literal.constKeyword != null) { | 3977 if (literal.constKeyword != null) { |
3924 // TODO(paulberry): this error should be based on the actual type of the | 3978 // TODO(paulberry): this error should be based on the actual type of the |
3925 // list element, not the static type. See dartbug.com/21119. | 3979 // list element, not the static type. See dartbug.com/21119. |
3926 if (_checkForArgumentTypeNotAssignableWithExpectedTypes(key, keyType, | 3980 if (_checkForArgumentTypeNotAssignableWithExpectedTypes(key, keyType, |
3927 CheckedModeCompileTimeErrorCode.MAP_KEY_TYPE_NOT_ASSIGNABLE)) { | 3981 CheckedModeCompileTimeErrorCode.MAP_KEY_TYPE_NOT_ASSIGNABLE)) { |
3928 hasProblems = true; | 3982 hasProblems = true; |
3929 } | 3983 } |
3930 if (_checkForArgumentTypeNotAssignableWithExpectedTypes(value, | 3984 if (_checkForArgumentTypeNotAssignableWithExpectedTypes( |
| 3985 value, |
3931 valueType, | 3986 valueType, |
3932 CheckedModeCompileTimeErrorCode.MAP_VALUE_TYPE_NOT_ASSIGNABLE)) { | 3987 CheckedModeCompileTimeErrorCode.MAP_VALUE_TYPE_NOT_ASSIGNABLE)) { |
3933 hasProblems = true; | 3988 hasProblems = true; |
3934 } | 3989 } |
3935 } | 3990 } |
3936 if (_checkForArgumentTypeNotAssignableWithExpectedTypes( | 3991 if (_checkForArgumentTypeNotAssignableWithExpectedTypes( |
3937 key, keyType, StaticWarningCode.MAP_KEY_TYPE_NOT_ASSIGNABLE)) { | 3992 key, keyType, StaticWarningCode.MAP_KEY_TYPE_NOT_ASSIGNABLE)) { |
3938 hasProblems = true; | 3993 hasProblems = true; |
3939 } | 3994 } |
3940 if (_checkForArgumentTypeNotAssignableWithExpectedTypes( | 3995 if (_checkForArgumentTypeNotAssignableWithExpectedTypes( |
(...skipping 15 matching lines...) Expand all Loading... |
3956 return false; | 4011 return false; |
3957 } | 4012 } |
3958 String className = _enclosingClass.name; | 4013 String className = _enclosingClass.name; |
3959 if (className == null) { | 4014 if (className == null) { |
3960 return false; | 4015 return false; |
3961 } | 4016 } |
3962 bool problemReported = false; | 4017 bool problemReported = false; |
3963 // check accessors | 4018 // check accessors |
3964 for (PropertyAccessorElement accessor in _enclosingClass.accessors) { | 4019 for (PropertyAccessorElement accessor in _enclosingClass.accessors) { |
3965 if (className == accessor.name) { | 4020 if (className == accessor.name) { |
3966 _errorReporter.reportErrorForOffset( | 4021 _errorReporter.reportErrorForElement( |
3967 CompileTimeErrorCode.MEMBER_WITH_CLASS_NAME, accessor.nameOffset, | 4022 CompileTimeErrorCode.MEMBER_WITH_CLASS_NAME, accessor); |
3968 className.length); | |
3969 problemReported = true; | 4023 problemReported = true; |
3970 } | 4024 } |
3971 } | 4025 } |
3972 // don't check methods, they would be constructors | 4026 // don't check methods, they would be constructors |
3973 // done | 4027 // done |
3974 return problemReported; | 4028 return problemReported; |
3975 } | 4029 } |
3976 | 4030 |
3977 /** | 4031 /** |
3978 * Check to make sure that all similarly typed accessors are of the same type | 4032 * Check to make sure that all similarly typed accessors are of the same type |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4039 getterType = _getGetterType(propertyAccessorElement); | 4093 getterType = _getGetterType(propertyAccessorElement); |
4040 setterType = _getSetterType(counterpartAccessor); | 4094 setterType = _getSetterType(counterpartAccessor); |
4041 } else if (propertyAccessorElement.isSetter) { | 4095 } else if (propertyAccessorElement.isSetter) { |
4042 setterType = _getSetterType(propertyAccessorElement); | 4096 setterType = _getSetterType(propertyAccessorElement); |
4043 getterType = _getGetterType(counterpartAccessor); | 4097 getterType = _getGetterType(counterpartAccessor); |
4044 } | 4098 } |
4045 // If either types are not assignable to each other, report an error | 4099 // If either types are not assignable to each other, report an error |
4046 // (if the getter is null, it is dynamic which is assignable to everything). | 4100 // (if the getter is null, it is dynamic which is assignable to everything). |
4047 if (setterType != null && | 4101 if (setterType != null && |
4048 getterType != null && | 4102 getterType != null && |
4049 !getterType.isAssignableTo(setterType)) { | 4103 !_typeSystem.isAssignableTo(getterType, setterType)) { |
4050 if (enclosingClassForCounterpart == null) { | 4104 if (enclosingClassForCounterpart == null) { |
4051 _errorReporter.reportTypeErrorForNode( | 4105 _errorReporter.reportTypeErrorForNode( |
4052 StaticWarningCode.MISMATCHED_GETTER_AND_SETTER_TYPES, | 4106 StaticWarningCode.MISMATCHED_GETTER_AND_SETTER_TYPES, |
4053 accessorDeclaration, [accessorTextName, setterType, getterType]); | 4107 accessorDeclaration, |
| 4108 [accessorTextName, setterType, getterType]); |
4054 return true; | 4109 return true; |
4055 } else { | 4110 } else { |
4056 _errorReporter.reportTypeErrorForNode( | 4111 _errorReporter.reportTypeErrorForNode( |
4057 StaticWarningCode.MISMATCHED_GETTER_AND_SETTER_TYPES_FROM_SUPERTYPE, | 4112 StaticWarningCode.MISMATCHED_GETTER_AND_SETTER_TYPES_FROM_SUPERTYPE, |
4058 accessorDeclaration, [ | 4113 accessorDeclaration, [ |
4059 accessorTextName, | 4114 accessorTextName, |
4060 setterType, | 4115 setterType, |
4061 getterType, | 4116 getterType, |
4062 enclosingClassForCounterpart.displayName | 4117 enclosingClassForCounterpart.displayName |
4063 ]); | 4118 ]); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4106 String constantName = _getConstantName((member as SwitchCase).expression); | 4161 String constantName = _getConstantName((member as SwitchCase).expression); |
4107 if (constantName != null) { | 4162 if (constantName != null) { |
4108 constantNames.remove(constantName); | 4163 constantNames.remove(constantName); |
4109 } | 4164 } |
4110 } | 4165 } |
4111 int nameCount = constantNames.length; | 4166 int nameCount = constantNames.length; |
4112 if (nameCount == 0) { | 4167 if (nameCount == 0) { |
4113 return false; | 4168 return false; |
4114 } | 4169 } |
4115 for (int i = 0; i < nameCount; i++) { | 4170 for (int i = 0; i < nameCount; i++) { |
4116 _errorReporter.reportErrorForNode( | 4171 int offset = statement.offset; |
4117 CompileTimeErrorCode.MISSING_ENUM_CONSTANT_IN_SWITCH, statement, | 4172 int end = statement.rightParenthesis.end; |
| 4173 _errorReporter.reportErrorForOffset( |
| 4174 CompileTimeErrorCode.MISSING_ENUM_CONSTANT_IN_SWITCH, |
| 4175 offset, |
| 4176 end - offset, |
4118 [constantNames[i]]); | 4177 [constantNames[i]]); |
4119 } | 4178 } |
4120 return true; | 4179 return true; |
4121 } | 4180 } |
4122 | 4181 |
4123 /** | 4182 /** |
4124 * Verify that the given function [body] does not contain return statements | 4183 * Verify that the given function [body] does not contain return statements |
4125 * that both have and do not have return values. | 4184 * that both have and do not have return values. |
4126 * | 4185 * |
4127 * See [StaticWarningCode.MIXED_RETURN_TYPES]. | 4186 * See [StaticWarningCode.MIXED_RETURN_TYPES]. |
(...skipping 23 matching lines...) Expand all Loading... |
4151 * constructor. The [mixinName] is the node to report problem on. The | 4210 * constructor. The [mixinName] is the node to report problem on. The |
4152 * [mixinElement] is the mixing to evaluate. | 4211 * [mixinElement] is the mixing to evaluate. |
4153 * | 4212 * |
4154 * See [CompileTimeErrorCode.MIXIN_DECLARES_CONSTRUCTOR]. | 4213 * See [CompileTimeErrorCode.MIXIN_DECLARES_CONSTRUCTOR]. |
4155 */ | 4214 */ |
4156 bool _checkForMixinDeclaresConstructor( | 4215 bool _checkForMixinDeclaresConstructor( |
4157 TypeName mixinName, ClassElement mixinElement) { | 4216 TypeName mixinName, ClassElement mixinElement) { |
4158 for (ConstructorElement constructor in mixinElement.constructors) { | 4217 for (ConstructorElement constructor in mixinElement.constructors) { |
4159 if (!constructor.isSynthetic && !constructor.isFactory) { | 4218 if (!constructor.isSynthetic && !constructor.isFactory) { |
4160 _errorReporter.reportErrorForNode( | 4219 _errorReporter.reportErrorForNode( |
4161 CompileTimeErrorCode.MIXIN_DECLARES_CONSTRUCTOR, mixinName, | 4220 CompileTimeErrorCode.MIXIN_DECLARES_CONSTRUCTOR, |
| 4221 mixinName, |
4162 [mixinElement.name]); | 4222 [mixinElement.name]); |
4163 return true; | 4223 return true; |
4164 } | 4224 } |
4165 } | 4225 } |
4166 return false; | 4226 return false; |
4167 } | 4227 } |
4168 | 4228 |
4169 /** | 4229 /** |
4170 * Report the error [CompileTimeErrorCode.MIXIN_HAS_NO_CONSTRUCTORS] if | 4230 * Report the error [CompileTimeErrorCode.MIXIN_HAS_NO_CONSTRUCTORS] if |
4171 * appropriate. | 4231 * appropriate. |
(...skipping 13 matching lines...) Expand all Loading... |
4185 * | 4245 * |
4186 * See [CompileTimeErrorCode.MIXIN_INHERITS_FROM_NOT_OBJECT]. | 4246 * See [CompileTimeErrorCode.MIXIN_INHERITS_FROM_NOT_OBJECT]. |
4187 */ | 4247 */ |
4188 bool _checkForMixinInheritsNotFromObject( | 4248 bool _checkForMixinInheritsNotFromObject( |
4189 TypeName mixinName, ClassElement mixinElement) { | 4249 TypeName mixinName, ClassElement mixinElement) { |
4190 InterfaceType mixinSupertype = mixinElement.supertype; | 4250 InterfaceType mixinSupertype = mixinElement.supertype; |
4191 if (mixinSupertype != null) { | 4251 if (mixinSupertype != null) { |
4192 if (!mixinSupertype.isObject || | 4252 if (!mixinSupertype.isObject || |
4193 !mixinElement.isMixinApplication && mixinElement.mixins.length != 0) { | 4253 !mixinElement.isMixinApplication && mixinElement.mixins.length != 0) { |
4194 _errorReporter.reportErrorForNode( | 4254 _errorReporter.reportErrorForNode( |
4195 CompileTimeErrorCode.MIXIN_INHERITS_FROM_NOT_OBJECT, mixinName, | 4255 CompileTimeErrorCode.MIXIN_INHERITS_FROM_NOT_OBJECT, |
| 4256 mixinName, |
4196 [mixinElement.name]); | 4257 [mixinElement.name]); |
4197 return true; | 4258 return true; |
4198 } | 4259 } |
4199 } | 4260 } |
4200 return false; | 4261 return false; |
4201 } | 4262 } |
4202 | 4263 |
4203 /** | 4264 /** |
4204 * Verify that the given mixin does not reference 'super'. The [mixinName] is | 4265 * Verify that the given mixin does not reference 'super'. The [mixinName] is |
4205 * the node to report problem on. The [mixinElement] is the mixing to | 4266 * the node to report problem on. The [mixinElement] is the mixing to |
4206 * evaluate. | 4267 * evaluate. |
4207 * | 4268 * |
4208 * See [CompileTimeErrorCode.MIXIN_REFERENCES_SUPER]. | 4269 * See [CompileTimeErrorCode.MIXIN_REFERENCES_SUPER]. |
4209 */ | 4270 */ |
4210 bool _checkForMixinReferencesSuper( | 4271 bool _checkForMixinReferencesSuper( |
4211 TypeName mixinName, ClassElement mixinElement) { | 4272 TypeName mixinName, ClassElement mixinElement) { |
4212 if (mixinElement.hasReferenceToSuper) { | 4273 if (!enableSuperMixins && mixinElement.hasReferenceToSuper) { |
4213 _errorReporter.reportErrorForNode( | 4274 _errorReporter.reportErrorForNode( |
4214 CompileTimeErrorCode.MIXIN_REFERENCES_SUPER, mixinName, | 4275 CompileTimeErrorCode.MIXIN_REFERENCES_SUPER, |
| 4276 mixinName, |
4215 [mixinElement.name]); | 4277 [mixinElement.name]); |
4216 } | 4278 } |
4217 return false; | 4279 return false; |
4218 } | 4280 } |
4219 | 4281 |
4220 /** | 4282 /** |
4221 * Verify that the given [constructor] has at most one 'super' initializer. | 4283 * Verify that the given [constructor] has at most one 'super' initializer. |
4222 * | 4284 * |
4223 * See [CompileTimeErrorCode.MULTIPLE_SUPER_INITIALIZERS]. | 4285 * See [CompileTimeErrorCode.MULTIPLE_SUPER_INITIALIZERS]. |
4224 */ | 4286 */ |
(...skipping 29 matching lines...) Expand all Loading... |
4254 * Verify that the given instance creation [expression] invokes an existing | 4316 * Verify that the given instance creation [expression] invokes an existing |
4255 * constructor. The [constructorName] is the constructor name. The [typeName] | 4317 * constructor. The [constructorName] is the constructor name. The [typeName] |
4256 * is the name of the type defining the constructor. | 4318 * is the name of the type defining the constructor. |
4257 * | 4319 * |
4258 * This method assumes that the instance creation was tested to be 'new' | 4320 * This method assumes that the instance creation was tested to be 'new' |
4259 * before being called. | 4321 * before being called. |
4260 * | 4322 * |
4261 * See [StaticWarningCode.NEW_WITH_UNDEFINED_CONSTRUCTOR]. | 4323 * See [StaticWarningCode.NEW_WITH_UNDEFINED_CONSTRUCTOR]. |
4262 */ | 4324 */ |
4263 bool _checkForNewWithUndefinedConstructor( | 4325 bool _checkForNewWithUndefinedConstructor( |
4264 InstanceCreationExpression expression, ConstructorName constructorName, | 4326 InstanceCreationExpression expression, |
| 4327 ConstructorName constructorName, |
4265 TypeName typeName) { | 4328 TypeName typeName) { |
4266 // OK if resolved | 4329 // OK if resolved |
4267 if (expression.staticElement != null) { | 4330 if (expression.staticElement != null) { |
4268 return false; | 4331 return false; |
4269 } | 4332 } |
4270 DartType type = typeName.type; | 4333 DartType type = typeName.type; |
4271 if (type is InterfaceType) { | 4334 if (type is InterfaceType) { |
4272 ClassElement element = type.element; | 4335 ClassElement element = type.element; |
4273 if (element != null && element.isEnum) { | 4336 if (element != null && element.isEnum) { |
4274 // We have already reported the error. | 4337 // We have already reported the error. |
4275 return false; | 4338 return false; |
4276 } | 4339 } |
4277 } | 4340 } |
4278 // prepare class name | 4341 // prepare class name |
4279 Identifier className = typeName.name; | 4342 Identifier className = typeName.name; |
4280 // report as named or default constructor absence | 4343 // report as named or default constructor absence |
4281 SimpleIdentifier name = constructorName.name; | 4344 SimpleIdentifier name = constructorName.name; |
4282 if (name != null) { | 4345 if (name != null) { |
4283 _errorReporter.reportErrorForNode( | 4346 _errorReporter.reportErrorForNode( |
4284 StaticWarningCode.NEW_WITH_UNDEFINED_CONSTRUCTOR, name, [ | 4347 StaticWarningCode.NEW_WITH_UNDEFINED_CONSTRUCTOR, |
4285 className, | 4348 name, |
4286 name | 4349 [className, name]); |
4287 ]); | |
4288 } else { | 4350 } else { |
4289 _errorReporter.reportErrorForNode( | 4351 _errorReporter.reportErrorForNode( |
4290 StaticWarningCode.NEW_WITH_UNDEFINED_CONSTRUCTOR_DEFAULT, | 4352 StaticWarningCode.NEW_WITH_UNDEFINED_CONSTRUCTOR_DEFAULT, |
4291 constructorName, [className]); | 4353 constructorName, |
| 4354 [className]); |
4292 } | 4355 } |
4293 return true; | 4356 return true; |
4294 } | 4357 } |
4295 | 4358 |
4296 /** | 4359 /** |
4297 * Check that if the given class [declaration] implicitly calls default | 4360 * Check that if the given class [declaration] implicitly calls default |
4298 * constructor of its superclass, there should be such default constructor - | 4361 * constructor of its superclass, there should be such default constructor - |
4299 * implicit or explicit. | 4362 * implicit or explicit. |
4300 * | 4363 * |
4301 * See [CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT]. | 4364 * See [CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT]. |
(...skipping 15 matching lines...) Expand all Loading... |
4317 if (superType == null) { | 4380 if (superType == null) { |
4318 return false; | 4381 return false; |
4319 } | 4382 } |
4320 ClassElement superElement = superType.element; | 4383 ClassElement superElement = superType.element; |
4321 // try to find default generative super constructor | 4384 // try to find default generative super constructor |
4322 ConstructorElement superUnnamedConstructor = | 4385 ConstructorElement superUnnamedConstructor = |
4323 superElement.unnamedConstructor; | 4386 superElement.unnamedConstructor; |
4324 if (superUnnamedConstructor != null) { | 4387 if (superUnnamedConstructor != null) { |
4325 if (superUnnamedConstructor.isFactory) { | 4388 if (superUnnamedConstructor.isFactory) { |
4326 _errorReporter.reportErrorForNode( | 4389 _errorReporter.reportErrorForNode( |
4327 CompileTimeErrorCode.NON_GENERATIVE_CONSTRUCTOR, declaration.name, | 4390 CompileTimeErrorCode.NON_GENERATIVE_CONSTRUCTOR, |
| 4391 declaration.name, |
4328 [superUnnamedConstructor]); | 4392 [superUnnamedConstructor]); |
4329 return true; | 4393 return true; |
4330 } | 4394 } |
4331 if (superUnnamedConstructor.isDefaultConstructor && | 4395 if (superUnnamedConstructor.isDefaultConstructor && |
4332 _enclosingClass | 4396 _enclosingClass |
4333 .isSuperConstructorAccessible(superUnnamedConstructor)) { | 4397 .isSuperConstructorAccessible(superUnnamedConstructor)) { |
4334 return true; | 4398 return true; |
4335 } | 4399 } |
4336 } | 4400 } |
4337 // report problem | 4401 // report problem |
4338 _errorReporter.reportErrorForNode( | 4402 _errorReporter.reportErrorForNode( |
4339 CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT, | 4403 CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT, |
4340 declaration.name, [superType.displayName]); | 4404 declaration.name, |
| 4405 [superType.displayName]); |
4341 return true; | 4406 return true; |
4342 } | 4407 } |
4343 | 4408 |
4344 /** | 4409 /** |
4345 * Check that the given class declaration overrides all members required by | 4410 * Check that the given class declaration overrides all members required by |
4346 * its superclasses and interfaces. The [classNameNode] is the | 4411 * its superclasses and interfaces. The [classNameNode] is the |
4347 * [SimpleIdentifier] to be used if there is a violation, this is either the | 4412 * [SimpleIdentifier] to be used if there is a violation, this is either the |
4348 * named from the [ClassDeclaration] or from the [ClassTypeAlias]. | 4413 * named from the [ClassDeclaration] or from the [ClassTypeAlias]. |
4349 * | 4414 * |
4350 * See [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE], | 4415 * See [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE], |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4426 if ((elt is MethodElement && !elt.isAbstract) || | 4491 if ((elt is MethodElement && !elt.isAbstract) || |
4427 (elt is PropertyAccessorElement && !elt.isAbstract)) { | 4492 (elt is PropertyAccessorElement && !elt.isAbstract)) { |
4428 // Since we are comparing two function types, we need to do the | 4493 // Since we are comparing two function types, we need to do the |
4429 // appropriate type substitutions first (). | 4494 // appropriate type substitutions first (). |
4430 FunctionType foundConcreteFT = _inheritanceManager | 4495 FunctionType foundConcreteFT = _inheritanceManager |
4431 .substituteTypeArgumentsInMemberFromInheritance( | 4496 .substituteTypeArgumentsInMemberFromInheritance( |
4432 concreteType, memberName, enclosingType); | 4497 concreteType, memberName, enclosingType); |
4433 FunctionType requiredMemberFT = _inheritanceManager | 4498 FunctionType requiredMemberFT = _inheritanceManager |
4434 .substituteTypeArgumentsInMemberFromInheritance( | 4499 .substituteTypeArgumentsInMemberFromInheritance( |
4435 requiredMemberType, memberName, enclosingType); | 4500 requiredMemberType, memberName, enclosingType); |
4436 if (foundConcreteFT.isSubtypeOf(requiredMemberFT)) { | 4501 if (_typeSystem.isSubtypeOf(foundConcreteFT, requiredMemberFT)) { |
4437 continue; | 4502 continue; |
4438 } | 4503 } |
4439 } | 4504 } |
4440 } | 4505 } |
4441 // The not qualifying concrete executable element was found, add it to the | 4506 // The not qualifying concrete executable element was found, add it to the |
4442 // list. | 4507 // list. |
4443 missingOverrides.add(executableElt); | 4508 missingOverrides.add(executableElt); |
4444 } | 4509 } |
4445 // Now that we have the set of missing overrides, generate a warning on this | 4510 // Now that we have the set of missing overrides, generate a warning on this |
4446 // class. | 4511 // class. |
(...skipping 25 matching lines...) Expand all Loading... |
4472 } else { | 4537 } else { |
4473 newStrMember = "$prefix'${missingOverridesArray[i].displayName}'"; | 4538 newStrMember = "$prefix'${missingOverridesArray[i].displayName}'"; |
4474 } | 4539 } |
4475 stringMembersArrayListSet.add(newStrMember); | 4540 stringMembersArrayListSet.add(newStrMember); |
4476 } | 4541 } |
4477 List<String> stringMembersArray = new List.from(stringMembersArrayListSet); | 4542 List<String> stringMembersArray = new List.from(stringMembersArrayListSet); |
4478 AnalysisErrorWithProperties analysisError; | 4543 AnalysisErrorWithProperties analysisError; |
4479 if (stringMembersArray.length == 1) { | 4544 if (stringMembersArray.length == 1) { |
4480 analysisError = _errorReporter.newErrorWithProperties( | 4545 analysisError = _errorReporter.newErrorWithProperties( |
4481 StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE, | 4546 StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE, |
4482 classNameNode, [stringMembersArray[0]]); | 4547 classNameNode, |
| 4548 [stringMembersArray[0]]); |
4483 } else if (stringMembersArray.length == 2) { | 4549 } else if (stringMembersArray.length == 2) { |
4484 analysisError = _errorReporter.newErrorWithProperties( | 4550 analysisError = _errorReporter.newErrorWithProperties( |
4485 StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_TWO, | 4551 StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_TWO, |
4486 classNameNode, [stringMembersArray[0], stringMembersArray[1]]); | 4552 classNameNode, |
| 4553 [stringMembersArray[0], stringMembersArray[1]]); |
4487 } else if (stringMembersArray.length == 3) { | 4554 } else if (stringMembersArray.length == 3) { |
4488 analysisError = _errorReporter.newErrorWithProperties( | 4555 analysisError = _errorReporter.newErrorWithProperties( |
4489 StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_THREE, | 4556 StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_THREE, |
4490 classNameNode, [ | 4557 classNameNode, [ |
4491 stringMembersArray[0], | 4558 stringMembersArray[0], |
4492 stringMembersArray[1], | 4559 stringMembersArray[1], |
4493 stringMembersArray[2] | 4560 stringMembersArray[2] |
4494 ]); | 4561 ]); |
4495 } else if (stringMembersArray.length == 4) { | 4562 } else if (stringMembersArray.length == 4) { |
4496 analysisError = _errorReporter.newErrorWithProperties( | 4563 analysisError = _errorReporter.newErrorWithProperties( |
(...skipping 22 matching lines...) Expand all Loading... |
4519 } | 4586 } |
4520 | 4587 |
4521 /** | 4588 /** |
4522 * Check to ensure that the [condition] is of type bool, are. Otherwise an | 4589 * Check to ensure that the [condition] is of type bool, are. Otherwise an |
4523 * error is reported on the expression. | 4590 * error is reported on the expression. |
4524 * | 4591 * |
4525 * See [StaticTypeWarningCode.NON_BOOL_CONDITION]. | 4592 * See [StaticTypeWarningCode.NON_BOOL_CONDITION]. |
4526 */ | 4593 */ |
4527 bool _checkForNonBoolCondition(Expression condition) { | 4594 bool _checkForNonBoolCondition(Expression condition) { |
4528 DartType conditionType = getStaticType(condition); | 4595 DartType conditionType = getStaticType(condition); |
4529 if (conditionType != null && !conditionType.isAssignableTo(_boolType)) { | 4596 if (conditionType != null && |
| 4597 !_typeSystem.isAssignableTo(conditionType, _boolType)) { |
4530 _errorReporter.reportErrorForNode( | 4598 _errorReporter.reportErrorForNode( |
4531 StaticTypeWarningCode.NON_BOOL_CONDITION, condition); | 4599 StaticTypeWarningCode.NON_BOOL_CONDITION, condition); |
4532 return true; | 4600 return true; |
4533 } | 4601 } |
4534 return false; | 4602 return false; |
4535 } | 4603 } |
4536 | 4604 |
4537 /** | 4605 /** |
4538 * Verify that the given assert [statement] has either a 'bool' or | 4606 * Verify that the given assert [statement] has either a 'bool' or |
4539 * '() -> bool' input. | 4607 * '() -> bool' input. |
4540 * | 4608 * |
4541 * See [StaticTypeWarningCode.NON_BOOL_EXPRESSION]. | 4609 * See [StaticTypeWarningCode.NON_BOOL_EXPRESSION]. |
4542 */ | 4610 */ |
4543 bool _checkForNonBoolExpression(AssertStatement statement) { | 4611 bool _checkForNonBoolExpression(AssertStatement statement) { |
4544 Expression expression = statement.condition; | 4612 Expression expression = statement.condition; |
4545 DartType type = getStaticType(expression); | 4613 DartType type = getStaticType(expression); |
4546 if (type is InterfaceType) { | 4614 if (type is InterfaceType) { |
4547 if (!type.isAssignableTo(_boolType)) { | 4615 if (!_typeSystem.isAssignableTo(type, _boolType)) { |
4548 _errorReporter.reportErrorForNode( | 4616 _errorReporter.reportErrorForNode( |
4549 StaticTypeWarningCode.NON_BOOL_EXPRESSION, expression); | 4617 StaticTypeWarningCode.NON_BOOL_EXPRESSION, expression); |
4550 return true; | 4618 return true; |
4551 } | 4619 } |
4552 } else if (type is FunctionType) { | 4620 } else if (type is FunctionType) { |
4553 FunctionType functionType = type; | 4621 FunctionType functionType = type; |
4554 if (functionType.typeArguments.length == 0 && | 4622 if (functionType.typeArguments.length == 0 && |
4555 !functionType.returnType.isAssignableTo(_boolType)) { | 4623 !_typeSystem.isAssignableTo(functionType.returnType, _boolType)) { |
4556 _errorReporter.reportErrorForNode( | 4624 _errorReporter.reportErrorForNode( |
4557 StaticTypeWarningCode.NON_BOOL_EXPRESSION, expression); | 4625 StaticTypeWarningCode.NON_BOOL_EXPRESSION, expression); |
4558 return true; | 4626 return true; |
4559 } | 4627 } |
4560 } | 4628 } |
4561 return false; | 4629 return false; |
4562 } | 4630 } |
4563 | 4631 |
4564 /** | 4632 /** |
4565 * Checks to ensure that the given [expression] is assignable to bool. | 4633 * Checks to ensure that the given [expression] is assignable to bool. |
4566 * | 4634 * |
4567 * See [StaticTypeWarningCode.NON_BOOL_NEGATION_EXPRESSION]. | 4635 * See [StaticTypeWarningCode.NON_BOOL_NEGATION_EXPRESSION]. |
4568 */ | 4636 */ |
4569 bool _checkForNonBoolNegationExpression(Expression expression) { | 4637 bool _checkForNonBoolNegationExpression(Expression expression) { |
4570 DartType conditionType = getStaticType(expression); | 4638 DartType conditionType = getStaticType(expression); |
4571 if (conditionType != null && !conditionType.isAssignableTo(_boolType)) { | 4639 if (conditionType != null && |
| 4640 !_typeSystem.isAssignableTo(conditionType, _boolType)) { |
4572 _errorReporter.reportErrorForNode( | 4641 _errorReporter.reportErrorForNode( |
4573 StaticTypeWarningCode.NON_BOOL_NEGATION_EXPRESSION, expression); | 4642 StaticTypeWarningCode.NON_BOOL_NEGATION_EXPRESSION, expression); |
4574 return true; | 4643 return true; |
4575 } | 4644 } |
4576 return false; | 4645 return false; |
4577 } | 4646 } |
4578 | 4647 |
4579 /** | 4648 /** |
4580 * Verify the given map [literal] either: | 4649 * Verify the given map [literal] either: |
4581 * * has `const modifier` | 4650 * * has `const modifier` |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4812 RedirectingConstructorInvocation invocation = initializer; | 4881 RedirectingConstructorInvocation invocation = initializer; |
4813 ConstructorElement redirectingElement = invocation.staticElement; | 4882 ConstructorElement redirectingElement = invocation.staticElement; |
4814 if (redirectingElement == null) { | 4883 if (redirectingElement == null) { |
4815 String enclosingTypeName = _enclosingClass.displayName; | 4884 String enclosingTypeName = _enclosingClass.displayName; |
4816 String constructorStrName = enclosingTypeName; | 4885 String constructorStrName = enclosingTypeName; |
4817 if (invocation.constructorName != null) { | 4886 if (invocation.constructorName != null) { |
4818 constructorStrName += ".${invocation.constructorName.name}"; | 4887 constructorStrName += ".${invocation.constructorName.name}"; |
4819 } | 4888 } |
4820 _errorReporter.reportErrorForNode( | 4889 _errorReporter.reportErrorForNode( |
4821 CompileTimeErrorCode.REDIRECT_GENERATIVE_TO_MISSING_CONSTRUCTOR, | 4890 CompileTimeErrorCode.REDIRECT_GENERATIVE_TO_MISSING_CONSTRUCTOR, |
4822 invocation, [constructorStrName, enclosingTypeName]); | 4891 invocation, |
| 4892 [constructorStrName, enclosingTypeName]); |
4823 } else { | 4893 } else { |
4824 if (redirectingElement.isFactory) { | 4894 if (redirectingElement.isFactory) { |
4825 _errorReporter.reportErrorForNode( | 4895 _errorReporter.reportErrorForNode( |
4826 CompileTimeErrorCode.REDIRECT_GENERATIVE_TO_NON_GENERATIVE_CON
STRUCTOR, | 4896 CompileTimeErrorCode.REDIRECT_GENERATIVE_TO_NON_GENERATIVE_CON
STRUCTOR, |
4827 initializer); | 4897 initializer); |
4828 } | 4898 } |
4829 } | 4899 } |
4830 } | 4900 } |
4831 numRedirections++; | 4901 numRedirections++; |
4832 } | 4902 } |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4956 return false; | 5026 return false; |
4957 } | 5027 } |
4958 _errorReporter.reportTypeErrorForNode( | 5028 _errorReporter.reportTypeErrorForNode( |
4959 StaticTypeWarningCode.RETURN_OF_INVALID_TYPE, returnExpression, [ | 5029 StaticTypeWarningCode.RETURN_OF_INVALID_TYPE, returnExpression, [ |
4960 staticReturnType, | 5030 staticReturnType, |
4961 expectedReturnType, | 5031 expectedReturnType, |
4962 _enclosingFunction.displayName | 5032 _enclosingFunction.displayName |
4963 ]); | 5033 ]); |
4964 return true; | 5034 return true; |
4965 } | 5035 } |
4966 if (staticReturnType.isAssignableTo(expectedReturnType)) { | 5036 if (_typeSystem.isAssignableTo(staticReturnType, expectedReturnType)) { |
4967 return false; | 5037 return false; |
4968 } | 5038 } |
4969 _errorReporter.reportTypeErrorForNode( | 5039 _errorReporter.reportTypeErrorForNode( |
4970 StaticTypeWarningCode.RETURN_OF_INVALID_TYPE, returnExpression, [ | 5040 StaticTypeWarningCode.RETURN_OF_INVALID_TYPE, |
4971 staticReturnType, | 5041 returnExpression, |
4972 expectedReturnType, | 5042 [staticReturnType, expectedReturnType, _enclosingFunction.displayName]); |
4973 _enclosingFunction.displayName | |
4974 ]); | |
4975 return true; | 5043 return true; |
4976 // TODO(brianwilkerson) Define a hint corresponding to the warning and | 5044 // TODO(brianwilkerson) Define a hint corresponding to the warning and |
4977 // report it if appropriate. | 5045 // report it if appropriate. |
4978 // Type propagatedReturnType = returnExpression.getPropagatedType(); | 5046 // Type propagatedReturnType = returnExpression.getPropagatedType(); |
4979 // boolean isPropagatedAssignable = propagatedReturnType.isAssignableTo(e
xpectedReturnType); | 5047 // boolean isPropagatedAssignable = propagatedReturnType.isAssignableTo(e
xpectedReturnType); |
4980 // if (isStaticAssignable || isPropagatedAssignable) { | 5048 // if (isStaticAssignable || isPropagatedAssignable) { |
4981 // return false; | 5049 // return false; |
4982 // } | 5050 // } |
4983 // errorReporter.reportTypeErrorForNode( | 5051 // errorReporter.reportTypeErrorForNode( |
4984 // StaticTypeWarningCode.RETURN_OF_INVALID_TYPE, | 5052 // StaticTypeWarningCode.RETURN_OF_INVALID_TYPE, |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5034 NodeList<SwitchMember> members = statement.members; | 5102 NodeList<SwitchMember> members = statement.members; |
5035 for (SwitchMember switchMember in members) { | 5103 for (SwitchMember switchMember in members) { |
5036 if (switchMember is! SwitchCase) { | 5104 if (switchMember is! SwitchCase) { |
5037 continue; | 5105 continue; |
5038 } | 5106 } |
5039 SwitchCase switchCase = switchMember as SwitchCase; | 5107 SwitchCase switchCase = switchMember as SwitchCase; |
5040 // prepare 'case' type | 5108 // prepare 'case' type |
5041 Expression caseExpression = switchCase.expression; | 5109 Expression caseExpression = switchCase.expression; |
5042 DartType caseType = getStaticType(caseExpression); | 5110 DartType caseType = getStaticType(caseExpression); |
5043 // check types | 5111 // check types |
5044 if (expressionType.isAssignableTo(caseType)) { | 5112 if (_typeSystem.isAssignableTo(expressionType, caseType)) { |
5045 return false; | 5113 return false; |
5046 } | 5114 } |
5047 // report problem | 5115 // report problem |
5048 _errorReporter.reportErrorForNode( | 5116 _errorReporter.reportErrorForNode( |
5049 StaticWarningCode.SWITCH_EXPRESSION_NOT_ASSIGNABLE, expression, [ | 5117 StaticWarningCode.SWITCH_EXPRESSION_NOT_ASSIGNABLE, |
5050 expressionType, | 5118 expression, |
5051 caseType | 5119 [expressionType, caseType]); |
5052 ]); | |
5053 return true; | 5120 return true; |
5054 } | 5121 } |
5055 return false; | 5122 return false; |
5056 } | 5123 } |
5057 | 5124 |
5058 /** | 5125 /** |
5059 * Verify that the given function type [alias] does not reference itself | 5126 * Verify that the given function type [alias] does not reference itself |
5060 * directly. | 5127 * directly. |
5061 * | 5128 * |
5062 * See [CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REFERENCE_ITSELF]. | 5129 * See [CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REFERENCE_ITSELF]. |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5117 bool foundError = false; | 5184 bool foundError = false; |
5118 for (int i = 0; i < loopThroughIndex; i++) { | 5185 for (int i = 0; i < loopThroughIndex; i++) { |
5119 TypeName argTypeName = typeNameArgList[i]; | 5186 TypeName argTypeName = typeNameArgList[i]; |
5120 DartType argType = argTypeName.type; | 5187 DartType argType = argTypeName.type; |
5121 DartType boundType = boundingElts[i].bound; | 5188 DartType boundType = boundingElts[i].bound; |
5122 if (argType != null && boundType != null) { | 5189 if (argType != null && boundType != null) { |
5123 if (typeArguments.length != 0 && | 5190 if (typeArguments.length != 0 && |
5124 typeArguments.length == typeParameters.length) { | 5191 typeArguments.length == typeParameters.length) { |
5125 boundType = boundType.substitute2(typeArguments, typeParameters); | 5192 boundType = boundType.substitute2(typeArguments, typeParameters); |
5126 } | 5193 } |
5127 if (!argType.isSubtypeOf(boundType)) { | 5194 if (!_typeSystem.isSubtypeOf(argType, boundType)) { |
5128 ErrorCode errorCode; | 5195 ErrorCode errorCode; |
5129 if (_isInConstInstanceCreation) { | 5196 if (_isInConstInstanceCreation) { |
5130 errorCode = CompileTimeErrorCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS; | 5197 errorCode = CompileTimeErrorCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS; |
5131 } else { | 5198 } else { |
5132 errorCode = StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS; | 5199 errorCode = StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS; |
5133 } | 5200 } |
5134 _errorReporter.reportTypeErrorForNode( | 5201 _errorReporter.reportTypeErrorForNode( |
5135 errorCode, argTypeName, [argType, boundType]); | 5202 errorCode, argTypeName, [argType, boundType]); |
5136 foundError = true; | 5203 foundError = true; |
5137 } | 5204 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5169 DartType bound = element.bound; | 5236 DartType bound = element.bound; |
5170 if (bound == null) { | 5237 if (bound == null) { |
5171 return false; | 5238 return false; |
5172 } | 5239 } |
5173 // OK, type parameter is not supertype of its bound | 5240 // OK, type parameter is not supertype of its bound |
5174 if (!bound.isMoreSpecificThan(element.type)) { | 5241 if (!bound.isMoreSpecificThan(element.type)) { |
5175 return false; | 5242 return false; |
5176 } | 5243 } |
5177 // report problem | 5244 // report problem |
5178 _errorReporter.reportErrorForNode( | 5245 _errorReporter.reportErrorForNode( |
5179 StaticTypeWarningCode.TYPE_PARAMETER_SUPERTYPE_OF_ITS_BOUND, parameter, | 5246 StaticTypeWarningCode.TYPE_PARAMETER_SUPERTYPE_OF_ITS_BOUND, |
| 5247 parameter, |
5180 [element.displayName]); | 5248 [element.displayName]); |
5181 return true; | 5249 return true; |
5182 } | 5250 } |
5183 | 5251 |
5184 /** | 5252 /** |
5185 * Check that if the given generative [constructor] has neither an explicit | 5253 * Check that if the given generative [constructor] has neither an explicit |
5186 * super constructor invocation nor a redirecting constructor invocation, that | 5254 * super constructor invocation nor a redirecting constructor invocation, that |
5187 * the superclass has a default generative constructor. | 5255 * the superclass has a default generative constructor. |
5188 * | 5256 * |
5189 * See [CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALIZER_DEFAULT], | 5257 * See [CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALIZER_DEFAULT], |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5225 if (superType == null) { | 5293 if (superType == null) { |
5226 return false; | 5294 return false; |
5227 } | 5295 } |
5228 ClassElement superElement = superType.element; | 5296 ClassElement superElement = superType.element; |
5229 ConstructorElement superUnnamedConstructor = | 5297 ConstructorElement superUnnamedConstructor = |
5230 superElement.unnamedConstructor; | 5298 superElement.unnamedConstructor; |
5231 if (superUnnamedConstructor != null) { | 5299 if (superUnnamedConstructor != null) { |
5232 if (superUnnamedConstructor.isFactory) { | 5300 if (superUnnamedConstructor.isFactory) { |
5233 _errorReporter.reportErrorForNode( | 5301 _errorReporter.reportErrorForNode( |
5234 CompileTimeErrorCode.NON_GENERATIVE_CONSTRUCTOR, | 5302 CompileTimeErrorCode.NON_GENERATIVE_CONSTRUCTOR, |
5235 constructor.returnType, [superUnnamedConstructor]); | 5303 constructor.returnType, |
| 5304 [superUnnamedConstructor]); |
5236 return true; | 5305 return true; |
5237 } | 5306 } |
5238 if (!superUnnamedConstructor.isDefaultConstructor || | 5307 if (!superUnnamedConstructor.isDefaultConstructor || |
5239 !_enclosingClass | 5308 !_enclosingClass |
5240 .isSuperConstructorAccessible(superUnnamedConstructor)) { | 5309 .isSuperConstructorAccessible(superUnnamedConstructor)) { |
5241 int offset; | 5310 int offset; |
5242 int length; | 5311 int length; |
5243 { | 5312 { |
5244 Identifier returnType = constructor.returnType; | 5313 Identifier returnType = constructor.returnType; |
5245 SimpleIdentifier name = constructor.name; | 5314 SimpleIdentifier name = constructor.name; |
5246 offset = returnType.offset; | 5315 offset = returnType.offset; |
5247 length = (name != null ? name.end : returnType.end) - offset; | 5316 length = (name != null ? name.end : returnType.end) - offset; |
5248 } | 5317 } |
5249 _errorReporter.reportErrorForOffset( | 5318 _errorReporter.reportErrorForOffset( |
5250 CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_EXPLICIT, offset, | 5319 CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_EXPLICIT, |
5251 length, [superType.displayName]); | 5320 offset, |
| 5321 length, |
| 5322 [superType.displayName]); |
5252 } | 5323 } |
5253 return false; | 5324 return false; |
5254 } | 5325 } |
5255 _errorReporter.reportErrorForNode( | 5326 _errorReporter.reportErrorForNode( |
5256 CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALIZER_DEFAULT, | 5327 CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALIZER_DEFAULT, |
5257 constructor.returnType, [superElement.name]); | 5328 constructor.returnType, |
| 5329 [superElement.name]); |
5258 return true; | 5330 return true; |
5259 } | 5331 } |
5260 | 5332 |
5261 /** | 5333 /** |
5262 * Check that if the given [name] is a reference to a static member it is | 5334 * Check that if the given [name] is a reference to a static member it is |
5263 * defined in the enclosing class rather than in a superclass. | 5335 * defined in the enclosing class rather than in a superclass. |
5264 * | 5336 * |
5265 * See [StaticTypeWarningCode.UNQUALIFIED_REFERENCE_TO_NON_LOCAL_STATIC_MEMBER
]. | 5337 * See [StaticTypeWarningCode.UNQUALIFIED_REFERENCE_TO_NON_LOCAL_STATIC_MEMBER
]. |
5266 */ | 5338 */ |
5267 bool _checkForUnqualifiedReferenceToNonLocalStaticMember( | 5339 bool _checkForUnqualifiedReferenceToNonLocalStaticMember( |
5268 SimpleIdentifier name) { | 5340 SimpleIdentifier name) { |
5269 Element element = name.staticElement; | 5341 Element element = name.staticElement; |
5270 if (element == null || element is TypeParameterElement) { | 5342 if (element == null || element is TypeParameterElement) { |
5271 return false; | 5343 return false; |
5272 } | 5344 } |
5273 Element enclosingElement = element.enclosingElement; | 5345 Element enclosingElement = element.enclosingElement; |
5274 if (enclosingElement is! ClassElement) { | 5346 if (enclosingElement is! ClassElement) { |
5275 return false; | 5347 return false; |
5276 } | 5348 } |
5277 if ((element is MethodElement && !element.isStatic) || | 5349 if ((element is MethodElement && !element.isStatic) || |
5278 (element is PropertyAccessorElement && !element.isStatic)) { | 5350 (element is PropertyAccessorElement && !element.isStatic)) { |
5279 return false; | 5351 return false; |
5280 } | 5352 } |
5281 if (identical(enclosingElement, _enclosingClass)) { | 5353 if (identical(enclosingElement, _enclosingClass)) { |
5282 return false; | 5354 return false; |
5283 } | 5355 } |
5284 _errorReporter.reportErrorForNode( | 5356 _errorReporter.reportErrorForNode( |
5285 StaticTypeWarningCode.UNQUALIFIED_REFERENCE_TO_NON_LOCAL_STATIC_MEMBER, | 5357 StaticTypeWarningCode.UNQUALIFIED_REFERENCE_TO_NON_LOCAL_STATIC_MEMBER, |
5286 name, [name.name]); | 5358 name, |
| 5359 [name.name]); |
5287 return true; | 5360 return true; |
5288 } | 5361 } |
5289 | 5362 |
5290 void _checkForValidField(FieldFormalParameter parameter) { | 5363 void _checkForValidField(FieldFormalParameter parameter) { |
5291 ParameterElement element = parameter.element; | 5364 ParameterElement element = parameter.element; |
5292 if (element is FieldFormalParameterElement) { | 5365 if (element is FieldFormalParameterElement) { |
5293 FieldElement fieldElement = element.field; | 5366 FieldElement fieldElement = element.field; |
5294 if (fieldElement == null || fieldElement.isSynthetic) { | 5367 if (fieldElement == null || fieldElement.isSynthetic) { |
5295 _errorReporter.reportErrorForNode( | 5368 _errorReporter.reportErrorForNode( |
5296 CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_NON_EXISTENT_FIELD, | 5369 CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_NON_EXISTENT_FIELD, |
5297 parameter, [parameter.identifier.name]); | 5370 parameter, |
| 5371 [parameter.identifier.name]); |
5298 } else { | 5372 } else { |
5299 ParameterElement parameterElement = parameter.element; | 5373 ParameterElement parameterElement = parameter.element; |
5300 if (parameterElement is FieldFormalParameterElementImpl) { | 5374 if (parameterElement is FieldFormalParameterElementImpl) { |
5301 FieldFormalParameterElementImpl fieldFormal = parameterElement; | 5375 FieldFormalParameterElementImpl fieldFormal = parameterElement; |
5302 DartType declaredType = fieldFormal.type; | 5376 DartType declaredType = fieldFormal.type; |
5303 DartType fieldType = fieldElement.type; | 5377 DartType fieldType = fieldElement.type; |
5304 if (fieldElement.isSynthetic) { | 5378 if (fieldElement.isSynthetic) { |
5305 _errorReporter.reportErrorForNode( | 5379 _errorReporter.reportErrorForNode( |
5306 CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_NON_EXISTENT_FIELD, | 5380 CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_NON_EXISTENT_FIELD, |
5307 parameter, [parameter.identifier.name]); | 5381 parameter, |
| 5382 [parameter.identifier.name]); |
5308 } else if (fieldElement.isStatic) { | 5383 } else if (fieldElement.isStatic) { |
5309 _errorReporter.reportErrorForNode( | 5384 _errorReporter.reportErrorForNode( |
5310 CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_STATIC_FIELD, | 5385 CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_STATIC_FIELD, |
5311 parameter, [parameter.identifier.name]); | 5386 parameter, |
| 5387 [parameter.identifier.name]); |
5312 } else if (declaredType != null && | 5388 } else if (declaredType != null && |
5313 fieldType != null && | 5389 fieldType != null && |
5314 !declaredType.isAssignableTo(fieldType)) { | 5390 !_typeSystem.isAssignableTo(declaredType, fieldType)) { |
5315 _errorReporter.reportTypeErrorForNode( | 5391 _errorReporter.reportTypeErrorForNode( |
5316 StaticWarningCode.FIELD_INITIALIZING_FORMAL_NOT_ASSIGNABLE, | 5392 StaticWarningCode.FIELD_INITIALIZING_FORMAL_NOT_ASSIGNABLE, |
5317 parameter, [declaredType, fieldType]); | 5393 parameter, |
| 5394 [declaredType, fieldType]); |
5318 } | 5395 } |
5319 } else { | 5396 } else { |
5320 if (fieldElement.isSynthetic) { | 5397 if (fieldElement.isSynthetic) { |
5321 _errorReporter.reportErrorForNode( | 5398 _errorReporter.reportErrorForNode( |
5322 CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_NON_EXISTENT_FIELD, | 5399 CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_NON_EXISTENT_FIELD, |
5323 parameter, [parameter.identifier.name]); | 5400 parameter, |
| 5401 [parameter.identifier.name]); |
5324 } else if (fieldElement.isStatic) { | 5402 } else if (fieldElement.isStatic) { |
5325 _errorReporter.reportErrorForNode( | 5403 _errorReporter.reportErrorForNode( |
5326 CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_STATIC_FIELD, | 5404 CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_STATIC_FIELD, |
5327 parameter, [parameter.identifier.name]); | 5405 parameter, |
| 5406 [parameter.identifier.name]); |
5328 } | 5407 } |
5329 } | 5408 } |
5330 } | 5409 } |
5331 } | 5410 } |
5332 // else { | 5411 // else { |
5333 // // TODO(jwren) Report error, constructor initializer variable is a top
level element | 5412 // // TODO(jwren) Report error, constructor initializer variable is a top
level element |
5334 // // (Either here or in ErrorVerifier.checkForAllFinalInitializedErrorCo
des) | 5413 // // (Either here or in ErrorVerifier.checkForAllFinalInitializedErrorCo
des) |
5335 // } | 5414 // } |
5336 } | 5415 } |
5337 | 5416 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5393 "<<" == name || | 5472 "<<" == name || |
5394 ">>" == name || | 5473 ">>" == name || |
5395 "[]" == name) { | 5474 "[]" == name) { |
5396 expected = 1; | 5475 expected = 1; |
5397 } else if ("~" == name) { | 5476 } else if ("~" == name) { |
5398 expected = 0; | 5477 expected = 0; |
5399 } | 5478 } |
5400 if (expected != -1 && numParameters != expected) { | 5479 if (expected != -1 && numParameters != expected) { |
5401 _errorReporter.reportErrorForNode( | 5480 _errorReporter.reportErrorForNode( |
5402 CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_OPERATOR, | 5481 CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_OPERATOR, |
5403 nameNode, [name, expected, numParameters]); | 5482 nameNode, |
| 5483 [name, expected, numParameters]); |
5404 return true; | 5484 return true; |
5405 } | 5485 } |
5406 // check for operator "-" | 5486 // check for operator "-" |
5407 if ("-" == name && numParameters > 1) { | 5487 if ("-" == name && numParameters > 1) { |
5408 _errorReporter.reportErrorForNode( | 5488 _errorReporter.reportErrorForNode( |
5409 CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_OPERATOR_MINUS, | 5489 CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_OPERATOR_MINUS, |
5410 nameNode, [numParameters]); | 5490 nameNode, |
| 5491 [numParameters]); |
5411 return true; | 5492 return true; |
5412 } | 5493 } |
5413 // OK | 5494 // OK |
5414 return false; | 5495 return false; |
5415 } | 5496 } |
5416 | 5497 |
5417 /** | 5498 /** |
5418 * Verify that the given setter [parameterList] has only one required | 5499 * Verify that the given setter [parameterList] has only one required |
5419 * parameter. The [setterName] is the name of the setter to report problems | 5500 * parameter. The [setterName] is the name of the setter to report problems |
5420 * on. | 5501 * on. |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5460 DartType impliedReturnType; | 5541 DartType impliedReturnType; |
5461 if (isYieldEach) { | 5542 if (isYieldEach) { |
5462 impliedReturnType = staticYieldedType; | 5543 impliedReturnType = staticYieldedType; |
5463 } else if (_enclosingFunction.isAsynchronous) { | 5544 } else if (_enclosingFunction.isAsynchronous) { |
5464 impliedReturnType = | 5545 impliedReturnType = |
5465 _typeProvider.streamType.substitute4(<DartType>[staticYieldedType]); | 5546 _typeProvider.streamType.substitute4(<DartType>[staticYieldedType]); |
5466 } else { | 5547 } else { |
5467 impliedReturnType = | 5548 impliedReturnType = |
5468 _typeProvider.iterableType.substitute4(<DartType>[staticYieldedType]); | 5549 _typeProvider.iterableType.substitute4(<DartType>[staticYieldedType]); |
5469 } | 5550 } |
5470 if (!impliedReturnType.isAssignableTo(declaredReturnType)) { | 5551 if (!_typeSystem.isAssignableTo(impliedReturnType, declaredReturnType)) { |
5471 _errorReporter.reportTypeErrorForNode( | 5552 _errorReporter.reportTypeErrorForNode( |
5472 StaticTypeWarningCode.YIELD_OF_INVALID_TYPE, yieldExpression, [ | 5553 StaticTypeWarningCode.YIELD_OF_INVALID_TYPE, |
5473 impliedReturnType, | 5554 yieldExpression, |
5474 declaredReturnType | 5555 [impliedReturnType, declaredReturnType]); |
5475 ]); | |
5476 return true; | 5556 return true; |
5477 } | 5557 } |
5478 if (isYieldEach) { | 5558 if (isYieldEach) { |
5479 // Since the declared return type might have been "dynamic", we need to | 5559 // Since the declared return type might have been "dynamic", we need to |
5480 // also check that the implied return type is assignable to generic | 5560 // also check that the implied return type is assignable to generic |
5481 // Stream/Iterable. | 5561 // Stream/Iterable. |
5482 DartType requiredReturnType; | 5562 DartType requiredReturnType; |
5483 if (_enclosingFunction.isAsynchronous) { | 5563 if (_enclosingFunction.isAsynchronous) { |
5484 requiredReturnType = _typeProvider.streamDynamicType; | 5564 requiredReturnType = _typeProvider.streamDynamicType; |
5485 } else { | 5565 } else { |
5486 requiredReturnType = _typeProvider.iterableDynamicType; | 5566 requiredReturnType = _typeProvider.iterableDynamicType; |
5487 } | 5567 } |
5488 if (!impliedReturnType.isAssignableTo(requiredReturnType)) { | 5568 if (!_typeSystem.isAssignableTo(impliedReturnType, requiredReturnType)) { |
5489 _errorReporter.reportTypeErrorForNode( | 5569 _errorReporter.reportTypeErrorForNode( |
5490 StaticTypeWarningCode.YIELD_OF_INVALID_TYPE, yieldExpression, [ | 5570 StaticTypeWarningCode.YIELD_OF_INVALID_TYPE, |
5491 impliedReturnType, | 5571 yieldExpression, |
5492 requiredReturnType | 5572 [impliedReturnType, requiredReturnType]); |
5493 ]); | |
5494 return true; | 5573 return true; |
5495 } | 5574 } |
5496 } | 5575 } |
5497 return false; | 5576 return false; |
5498 } | 5577 } |
5499 | 5578 |
5500 /** | 5579 /** |
5501 * Verify that if the given class [declaration] implements the class Function | 5580 * Verify that if the given class [declaration] implements the class Function |
5502 * that it has a concrete implementation of the call method. | 5581 * that it has a concrete implementation of the call method. |
5503 * | 5582 * |
5504 * See [StaticWarningCode.FUNCTION_WITHOUT_CALL]. | 5583 * See [StaticWarningCode.FUNCTION_WITHOUT_CALL]. |
5505 */ | 5584 */ |
5506 bool _checkImplementsFunctionWithoutCall(ClassDeclaration declaration) { | 5585 bool _checkImplementsFunctionWithoutCall(ClassDeclaration declaration) { |
5507 if (declaration.isAbstract) { | 5586 if (declaration.isAbstract) { |
5508 return false; | 5587 return false; |
5509 } | 5588 } |
5510 ClassElement classElement = declaration.element; | 5589 ClassElement classElement = declaration.element; |
5511 if (classElement == null) { | 5590 if (classElement == null) { |
5512 return false; | 5591 return false; |
5513 } | 5592 } |
5514 if (!classElement.type.isSubtypeOf(_typeProvider.functionType)) { | 5593 if (!_typeSystem.isSubtypeOf( |
| 5594 classElement.type, _typeProvider.functionType)) { |
5515 return false; | 5595 return false; |
5516 } | 5596 } |
5517 // If there is a noSuchMethod method, then don't report the warning, | 5597 // If there is a noSuchMethod method, then don't report the warning, |
5518 // see dartbug.com/16078 | 5598 // see dartbug.com/16078 |
5519 if (classElement.getMethod(FunctionElement.NO_SUCH_METHOD_METHOD_NAME) != | 5599 if (classElement.getMethod(FunctionElement.NO_SUCH_METHOD_METHOD_NAME) != |
5520 null) { | 5600 null) { |
5521 return false; | 5601 return false; |
5522 } | 5602 } |
5523 ExecutableElement callMethod = _inheritanceManager.lookupMember( | 5603 ExecutableElement callMethod = _inheritanceManager.lookupMember( |
5524 classElement, FunctionElement.CALL_METHOD_NAME); | 5604 classElement, FunctionElement.CALL_METHOD_NAME); |
(...skipping 23 matching lines...) Expand all Loading... |
5548 ImplementsClause implementsClause = declaration.implementsClause; | 5628 ImplementsClause implementsClause = declaration.implementsClause; |
5549 if (implementsClause == null) { | 5629 if (implementsClause == null) { |
5550 return false; | 5630 return false; |
5551 } | 5631 } |
5552 // check interfaces | 5632 // check interfaces |
5553 bool hasProblem = false; | 5633 bool hasProblem = false; |
5554 for (TypeName interfaceNode in implementsClause.interfaces) { | 5634 for (TypeName interfaceNode in implementsClause.interfaces) { |
5555 if (interfaceNode.type == superType) { | 5635 if (interfaceNode.type == superType) { |
5556 hasProblem = true; | 5636 hasProblem = true; |
5557 _errorReporter.reportErrorForNode( | 5637 _errorReporter.reportErrorForNode( |
5558 CompileTimeErrorCode.IMPLEMENTS_SUPER_CLASS, interfaceNode, | 5638 CompileTimeErrorCode.IMPLEMENTS_SUPER_CLASS, |
| 5639 interfaceNode, |
5559 [superType.displayName]); | 5640 [superType.displayName]); |
5560 } | 5641 } |
5561 } | 5642 } |
5562 // done | 5643 // done |
5563 return hasProblem; | 5644 return hasProblem; |
5564 } | 5645 } |
5565 | 5646 |
5566 DartType _computeReturnTypeForMethod(Expression returnExpression) { | 5647 DartType _computeReturnTypeForMethod(Expression returnExpression) { |
5567 // This method should never be called for generators, since generators are | 5648 // This method should never be called for generators, since generators are |
5568 // never allowed to contain return statements with expressions. | 5649 // never allowed to contain return statements with expressions. |
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5867 if (size > 1) { | 5948 if (size > 1) { |
5868 // Construct a string showing the cyclic implements path: | 5949 // Construct a string showing the cyclic implements path: |
5869 // "A, B, C, D, A" | 5950 // "A, B, C, D, A" |
5870 String separator = ", "; | 5951 String separator = ", "; |
5871 StringBuffer buffer = new StringBuffer(); | 5952 StringBuffer buffer = new StringBuffer(); |
5872 for (int i = 0; i < size; i++) { | 5953 for (int i = 0; i < size; i++) { |
5873 buffer.write(path[i].displayName); | 5954 buffer.write(path[i].displayName); |
5874 buffer.write(separator); | 5955 buffer.write(separator); |
5875 } | 5956 } |
5876 buffer.write(element.displayName); | 5957 buffer.write(element.displayName); |
5877 _errorReporter.reportErrorForOffset( | 5958 _errorReporter.reportErrorForElement( |
5878 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE, | 5959 CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE, |
5879 _enclosingClass.nameOffset, enclosingClassName.length, [ | 5960 _enclosingClass, |
5880 enclosingClassName, | 5961 [enclosingClassName, buffer.toString()]); |
5881 buffer.toString() | |
5882 ]); | |
5883 return true; | 5962 return true; |
5884 } else { | 5963 } else { |
5885 // RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_EXTENDS or | 5964 // RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_EXTENDS or |
5886 // RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_IMPLEMENTS or | 5965 // RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_IMPLEMENTS or |
5887 // RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_WITH | 5966 // RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_WITH |
5888 _errorReporter.reportErrorForOffset(_getBaseCaseErrorCode(element), | 5967 _errorReporter.reportErrorForElement(_getBaseCaseErrorCode(element), |
5889 _enclosingClass.nameOffset, enclosingClassName.length, | 5968 _enclosingClass, [enclosingClassName]); |
5890 [enclosingClassName]); | |
5891 return true; | 5969 return true; |
5892 } | 5970 } |
5893 } | 5971 } |
5894 if (path.indexOf(element) > 0) { | 5972 if (path.indexOf(element) > 0) { |
5895 return false; | 5973 return false; |
5896 } | 5974 } |
5897 path.add(element); | 5975 path.add(element); |
5898 // n-case | 5976 // n-case |
5899 InterfaceType supertype = element.supertype; | 5977 InterfaceType supertype = element.supertype; |
5900 if (supertype != null && | 5978 if (supertype != null && |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5985 toCheck.add(type.element); | 6063 toCheck.add(type.element); |
5986 // type arguments | 6064 // type arguments |
5987 if (type is InterfaceType) { | 6065 if (type is InterfaceType) { |
5988 InterfaceType interfaceType = type; | 6066 InterfaceType interfaceType = type; |
5989 for (DartType typeArgument in interfaceType.typeArguments) { | 6067 for (DartType typeArgument in interfaceType.typeArguments) { |
5990 _addTypeToCheck(typeArgument); | 6068 _addTypeToCheck(typeArgument); |
5991 } | 6069 } |
5992 } | 6070 } |
5993 } | 6071 } |
5994 } | 6072 } |
OLD | NEW |