| 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 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 HashSet<String> _namesForReferenceToDeclaredVariableInInitializer = | 248 HashSet<String> _namesForReferenceToDeclaredVariableInInitializer = |
| 249 new HashSet<String>(); | 249 new HashSet<String>(); |
| 250 | 250 |
| 251 /** | 251 /** |
| 252 * A list of types used by the [CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS] | 252 * A list of types used by the [CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS] |
| 253 * and [CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS] error codes. | 253 * and [CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS] error codes. |
| 254 */ | 254 */ |
| 255 List<InterfaceType> _DISALLOWED_TYPES_TO_EXTEND_OR_IMPLEMENT; | 255 List<InterfaceType> _DISALLOWED_TYPES_TO_EXTEND_OR_IMPLEMENT; |
| 256 | 256 |
| 257 /** | 257 /** |
| 258 * If `true`, mixins are allowed to inherit from types other than Object, and |
| 259 * are allowed to reference `super`. |
| 260 */ |
| 261 final bool enableSuperMixins; |
| 262 |
| 263 /** |
| 258 * Initialize a newly created error verifier. | 264 * Initialize a newly created error verifier. |
| 259 */ | 265 */ |
| 260 ErrorVerifier(this._errorReporter, this._currentLibrary, this._typeProvider, | 266 ErrorVerifier(this._errorReporter, this._currentLibrary, this._typeProvider, |
| 261 this._inheritanceManager) { | 267 this._inheritanceManager, this.enableSuperMixins) { |
| 262 this._isInSystemLibrary = _currentLibrary.source.isInSystemLibrary; | 268 this._isInSystemLibrary = _currentLibrary.source.isInSystemLibrary; |
| 263 this._hasExtUri = _currentLibrary.hasExtUri; | 269 this._hasExtUri = _currentLibrary.hasExtUri; |
| 264 _isEnclosingConstructorConst = false; | 270 _isEnclosingConstructorConst = false; |
| 265 _isInCatchClause = false; | 271 _isInCatchClause = false; |
| 266 _isInStaticVariableDeclaration = false; | 272 _isInStaticVariableDeclaration = false; |
| 267 _isInInstanceVariableDeclaration = false; | 273 _isInInstanceVariableDeclaration = false; |
| 268 _isInInstanceVariableInitializer = false; | 274 _isInInstanceVariableInitializer = false; |
| 269 _isInConstructorInitializer = false; | 275 _isInConstructorInitializer = false; |
| 270 _isInStaticMethod = false; | 276 _isInStaticMethod = false; |
| 271 _boolType = _typeProvider.boolType; | 277 _boolType = _typeProvider.boolType; |
| (...skipping 1372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1644 problemReported = true; | 1650 problemReported = true; |
| 1645 } else { | 1651 } else { |
| 1646 ClassElement mixinElement = (mixinType as InterfaceType).element; | 1652 ClassElement mixinElement = (mixinType as InterfaceType).element; |
| 1647 if (_checkForExtendsOrImplementsDeferredClass( | 1653 if (_checkForExtendsOrImplementsDeferredClass( |
| 1648 mixinName, CompileTimeErrorCode.MIXIN_DEFERRED_CLASS)) { | 1654 mixinName, CompileTimeErrorCode.MIXIN_DEFERRED_CLASS)) { |
| 1649 problemReported = true; | 1655 problemReported = true; |
| 1650 } | 1656 } |
| 1651 if (_checkForMixinDeclaresConstructor(mixinName, mixinElement)) { | 1657 if (_checkForMixinDeclaresConstructor(mixinName, mixinElement)) { |
| 1652 problemReported = true; | 1658 problemReported = true; |
| 1653 } | 1659 } |
| 1654 if (_checkForMixinInheritsNotFromObject(mixinName, mixinElement)) { | 1660 if (!enableSuperMixins && |
| 1661 _checkForMixinInheritsNotFromObject(mixinName, mixinElement)) { |
| 1655 problemReported = true; | 1662 problemReported = true; |
| 1656 } | 1663 } |
| 1657 if (_checkForMixinReferencesSuper(mixinName, mixinElement)) { | 1664 if (_checkForMixinReferencesSuper(mixinName, mixinElement)) { |
| 1658 problemReported = true; | 1665 problemReported = true; |
| 1659 } | 1666 } |
| 1660 } | 1667 } |
| 1661 } | 1668 } |
| 1662 return problemReported; | 1669 return problemReported; |
| 1663 } | 1670 } |
| 1664 | 1671 |
| (...skipping 2537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4202 | 4209 |
| 4203 /** | 4210 /** |
| 4204 * Verify that the given mixin does not reference 'super'. The [mixinName] is | 4211 * 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 | 4212 * the node to report problem on. The [mixinElement] is the mixing to |
| 4206 * evaluate. | 4213 * evaluate. |
| 4207 * | 4214 * |
| 4208 * See [CompileTimeErrorCode.MIXIN_REFERENCES_SUPER]. | 4215 * See [CompileTimeErrorCode.MIXIN_REFERENCES_SUPER]. |
| 4209 */ | 4216 */ |
| 4210 bool _checkForMixinReferencesSuper( | 4217 bool _checkForMixinReferencesSuper( |
| 4211 TypeName mixinName, ClassElement mixinElement) { | 4218 TypeName mixinName, ClassElement mixinElement) { |
| 4212 if (mixinElement.hasReferenceToSuper) { | 4219 if (!enableSuperMixins && mixinElement.hasReferenceToSuper) { |
| 4213 _errorReporter.reportErrorForNode( | 4220 _errorReporter.reportErrorForNode( |
| 4214 CompileTimeErrorCode.MIXIN_REFERENCES_SUPER, mixinName, | 4221 CompileTimeErrorCode.MIXIN_REFERENCES_SUPER, mixinName, |
| 4215 [mixinElement.name]); | 4222 [mixinElement.name]); |
| 4216 } | 4223 } |
| 4217 return false; | 4224 return false; |
| 4218 } | 4225 } |
| 4219 | 4226 |
| 4220 /** | 4227 /** |
| 4221 * Verify that the given [constructor] has at most one 'super' initializer. | 4228 * Verify that the given [constructor] has at most one 'super' initializer. |
| 4222 * | 4229 * |
| (...skipping 1762 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5985 toCheck.add(type.element); | 5992 toCheck.add(type.element); |
| 5986 // type arguments | 5993 // type arguments |
| 5987 if (type is InterfaceType) { | 5994 if (type is InterfaceType) { |
| 5988 InterfaceType interfaceType = type; | 5995 InterfaceType interfaceType = type; |
| 5989 for (DartType typeArgument in interfaceType.typeArguments) { | 5996 for (DartType typeArgument in interfaceType.typeArguments) { |
| 5990 _addTypeToCheck(typeArgument); | 5997 _addTypeToCheck(typeArgument); |
| 5991 } | 5998 } |
| 5992 } | 5999 } |
| 5993 } | 6000 } |
| 5994 } | 6001 } |
| OLD | NEW |