| 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 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 415 !_checkForAllMixinErrorCodes(withClause)) { | 415 !_checkForAllMixinErrorCodes(withClause)) { |
| 416 _checkForExtendsDeferredClass(extendsClause); | 416 _checkForExtendsDeferredClass(extendsClause); |
| 417 _checkForImplementsDeferredClass(implementsClause); | 417 _checkForImplementsDeferredClass(implementsClause); |
| 418 _checkForNonAbstractClassInheritsAbstractMember(node.name); | 418 _checkForNonAbstractClassInheritsAbstractMember(node.name); |
| 419 _checkForInconsistentMethodInheritance(); | 419 _checkForInconsistentMethodInheritance(); |
| 420 _checkForRecursiveInterfaceInheritance(_enclosingClass); | 420 _checkForRecursiveInterfaceInheritance(_enclosingClass); |
| 421 _checkForConflictingGetterAndMethod(); | 421 _checkForConflictingGetterAndMethod(); |
| 422 _checkForConflictingInstanceGetterAndSuperclassMember(); | 422 _checkForConflictingInstanceGetterAndSuperclassMember(); |
| 423 _checkImplementsSuperClass(node); | 423 _checkImplementsSuperClass(node); |
| 424 _checkImplementsFunctionWithoutCall(node); | 424 _checkImplementsFunctionWithoutCall(node); |
| 425 _checkForMixinHasNoConstructors(node); |
| 425 } | 426 } |
| 426 } | 427 } |
| 427 visitClassDeclarationIncrementally(node); | 428 visitClassDeclarationIncrementally(node); |
| 428 _checkForFinalNotInitializedInClass(node); | 429 _checkForFinalNotInitializedInClass(node); |
| 429 _checkForDuplicateDefinitionInheritance(); | 430 _checkForDuplicateDefinitionInheritance(); |
| 430 _checkForConflictingInstanceMethodSetter(node); | 431 _checkForConflictingInstanceMethodSetter(node); |
| 431 return super.visitClassDeclaration(node); | 432 return super.visitClassDeclaration(node); |
| 432 } finally { | 433 } finally { |
| 433 _isInNativeClass = false; | 434 _isInNativeClass = false; |
| 434 _initialFieldElementsMap = null; | 435 _initialFieldElementsMap = null; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 467 // Only check for all of the inheritance logic around clauses if there | 468 // Only check for all of the inheritance logic around clauses if there |
| 468 // isn't an error code such as "Cannot extend double" already on the | 469 // isn't an error code such as "Cannot extend double" already on the |
| 469 // class. | 470 // class. |
| 470 if (!_checkForExtendsDisallowedClassInTypeAlias(node) && | 471 if (!_checkForExtendsDisallowedClassInTypeAlias(node) && |
| 471 !_checkForImplementsDisallowedClass(implementsClause) && | 472 !_checkForImplementsDisallowedClass(implementsClause) && |
| 472 !_checkForAllMixinErrorCodes(node.withClause)) { | 473 !_checkForAllMixinErrorCodes(node.withClause)) { |
| 473 _checkForExtendsDeferredClassInTypeAlias(node); | 474 _checkForExtendsDeferredClassInTypeAlias(node); |
| 474 _checkForImplementsDeferredClass(implementsClause); | 475 _checkForImplementsDeferredClass(implementsClause); |
| 475 _checkForRecursiveInterfaceInheritance(_enclosingClass); | 476 _checkForRecursiveInterfaceInheritance(_enclosingClass); |
| 476 _checkForNonAbstractClassInheritsAbstractMember(node.name); | 477 _checkForNonAbstractClassInheritsAbstractMember(node.name); |
| 478 _checkForMixinHasNoConstructors(node); |
| 477 } | 479 } |
| 478 } finally { | 480 } finally { |
| 479 _enclosingClass = outerClassElement; | 481 _enclosingClass = outerClassElement; |
| 480 } | 482 } |
| 481 return super.visitClassTypeAlias(node); | 483 return super.visitClassTypeAlias(node); |
| 482 } | 484 } |
| 483 | 485 |
| 484 @override | 486 @override |
| 485 Object visitComment(Comment node) { | 487 Object visitComment(Comment node) { |
| 486 _isInComment = true; | 488 _isInComment = true; |
| (...skipping 3671 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4158 _errorReporter.reportErrorForNode( | 4160 _errorReporter.reportErrorForNode( |
| 4159 CompileTimeErrorCode.MIXIN_DECLARES_CONSTRUCTOR, mixinName, | 4161 CompileTimeErrorCode.MIXIN_DECLARES_CONSTRUCTOR, mixinName, |
| 4160 [mixinElement.name]); | 4162 [mixinElement.name]); |
| 4161 return true; | 4163 return true; |
| 4162 } | 4164 } |
| 4163 } | 4165 } |
| 4164 return false; | 4166 return false; |
| 4165 } | 4167 } |
| 4166 | 4168 |
| 4167 /** | 4169 /** |
| 4170 * Report the error [CompileTimeErrorCode.MIXIN_HAS_NO_CONSTRUCTORS] if |
| 4171 * appropriate. |
| 4172 */ |
| 4173 void _checkForMixinHasNoConstructors(AstNode node) { |
| 4174 if ((_enclosingClass as ClassElementImpl).doesMixinLackConstructors) { |
| 4175 ErrorCode errorCode = CompileTimeErrorCode.MIXIN_HAS_NO_CONSTRUCTORS; |
| 4176 _errorReporter.reportErrorForNode( |
| 4177 errorCode, node, [_enclosingClass.supertype]); |
| 4178 } |
| 4179 } |
| 4180 |
| 4181 /** |
| 4168 * Verify that the given mixin has the 'Object' superclass. The [mixinName] is | 4182 * Verify that the given mixin has the 'Object' superclass. The [mixinName] is |
| 4169 * the node to report problem on. The [mixinElement] is the mixing to | 4183 * the node to report problem on. The [mixinElement] is the mixing to |
| 4170 * evaluate. | 4184 * evaluate. |
| 4171 * | 4185 * |
| 4172 * See [CompileTimeErrorCode.MIXIN_INHERITS_FROM_NOT_OBJECT]. | 4186 * See [CompileTimeErrorCode.MIXIN_INHERITS_FROM_NOT_OBJECT]. |
| 4173 */ | 4187 */ |
| 4174 bool _checkForMixinInheritsNotFromObject( | 4188 bool _checkForMixinInheritsNotFromObject( |
| 4175 TypeName mixinName, ClassElement mixinElement) { | 4189 TypeName mixinName, ClassElement mixinElement) { |
| 4176 InterfaceType mixinSupertype = mixinElement.supertype; | 4190 InterfaceType mixinSupertype = mixinElement.supertype; |
| 4177 if (mixinSupertype != null) { | 4191 if (mixinSupertype != null) { |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4283 * Check that if the given class [declaration] implicitly calls default | 4297 * Check that if the given class [declaration] implicitly calls default |
| 4284 * constructor of its superclass, there should be such default constructor - | 4298 * constructor of its superclass, there should be such default constructor - |
| 4285 * implicit or explicit. | 4299 * implicit or explicit. |
| 4286 * | 4300 * |
| 4287 * See [CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT]. | 4301 * See [CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT]. |
| 4288 */ | 4302 */ |
| 4289 bool _checkForNoDefaultSuperConstructorImplicit( | 4303 bool _checkForNoDefaultSuperConstructorImplicit( |
| 4290 ClassDeclaration declaration) { | 4304 ClassDeclaration declaration) { |
| 4291 // do nothing if mixin errors have already been reported for this class. | 4305 // do nothing if mixin errors have already been reported for this class. |
| 4292 ClassElementImpl enclosingClass = _enclosingClass; | 4306 ClassElementImpl enclosingClass = _enclosingClass; |
| 4293 if (enclosingClass.mixinErrorsReported) { | 4307 if (enclosingClass.doesMixinLackConstructors) { |
| 4294 return false; | 4308 return false; |
| 4295 } | 4309 } |
| 4296 // do nothing if there is explicit constructor | 4310 // do nothing if there is explicit constructor |
| 4297 List<ConstructorElement> constructors = _enclosingClass.constructors; | 4311 List<ConstructorElement> constructors = _enclosingClass.constructors; |
| 4298 if (!constructors[0].isSynthetic) { | 4312 if (!constructors[0].isSynthetic) { |
| 4299 return false; | 4313 return false; |
| 4300 } | 4314 } |
| 4301 // prepare super | 4315 // prepare super |
| 4302 InterfaceType superType = _enclosingClass.supertype; | 4316 InterfaceType superType = _enclosingClass.supertype; |
| 4303 if (superType == null) { | 4317 if (superType == null) { |
| (...skipping 872 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5176 * [CompileTimeErrorCode.NON_GENERATIVE_CONSTRUCTOR], and | 5190 * [CompileTimeErrorCode.NON_GENERATIVE_CONSTRUCTOR], and |
| 5177 * [StaticWarningCode.NO_DEFAULT_SUPER_CONSTRUCTOR_EXPLICIT]. | 5191 * [StaticWarningCode.NO_DEFAULT_SUPER_CONSTRUCTOR_EXPLICIT]. |
| 5178 */ | 5192 */ |
| 5179 bool _checkForUndefinedConstructorInInitializerImplicit( | 5193 bool _checkForUndefinedConstructorInInitializerImplicit( |
| 5180 ConstructorDeclaration constructor) { | 5194 ConstructorDeclaration constructor) { |
| 5181 if (_enclosingClass == null) { | 5195 if (_enclosingClass == null) { |
| 5182 return false; | 5196 return false; |
| 5183 } | 5197 } |
| 5184 // do nothing if mixin errors have already been reported for this class. | 5198 // do nothing if mixin errors have already been reported for this class. |
| 5185 ClassElementImpl enclosingClass = _enclosingClass; | 5199 ClassElementImpl enclosingClass = _enclosingClass; |
| 5186 if (enclosingClass.mixinErrorsReported) { | 5200 if (enclosingClass.doesMixinLackConstructors) { |
| 5187 return false; | 5201 return false; |
| 5188 } | 5202 } |
| 5189 // | 5203 // |
| 5190 // Ignore if the constructor is not generative. | 5204 // Ignore if the constructor is not generative. |
| 5191 // | 5205 // |
| 5192 if (constructor.factoryKeyword != null) { | 5206 if (constructor.factoryKeyword != null) { |
| 5193 return false; | 5207 return false; |
| 5194 } | 5208 } |
| 5195 // | 5209 // |
| 5196 // Ignore if the constructor has either an implicit super constructor | 5210 // Ignore if the constructor has either an implicit super constructor |
| (...skipping 774 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5971 toCheck.add(type.element); | 5985 toCheck.add(type.element); |
| 5972 // type arguments | 5986 // type arguments |
| 5973 if (type is InterfaceType) { | 5987 if (type is InterfaceType) { |
| 5974 InterfaceType interfaceType = type; | 5988 InterfaceType interfaceType = type; |
| 5975 for (DartType typeArgument in interfaceType.typeArguments) { | 5989 for (DartType typeArgument in interfaceType.typeArguments) { |
| 5976 _addTypeToCheck(typeArgument); | 5990 _addTypeToCheck(typeArgument); |
| 5977 } | 5991 } |
| 5978 } | 5992 } |
| 5979 } | 5993 } |
| 5980 } | 5994 } |
| OLD | NEW |