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

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

Issue 724133003: Improve error reporting when a mixin application is invalid. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library engine.resolver; 5 library engine.resolver;
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 'java_core.dart'; 10 import 'java_core.dart';
(...skipping 5674 matching lines...) Expand 10 before | Expand all | Expand 10 after
5685 /** 5685 /**
5686 * Initialize a newly created visitor to finish resolution in the nodes in a c ompilation unit. 5686 * Initialize a newly created visitor to finish resolution in the nodes in a c ompilation unit.
5687 * 5687 *
5688 * @param library the library containing the compilation unit being resolved 5688 * @param library the library containing the compilation unit being resolved
5689 * @param source the source representing the compilation unit being visited 5689 * @param source the source representing the compilation unit being visited
5690 * @param typeProvider the object used to access the types from the core libra ry 5690 * @param typeProvider the object used to access the types from the core libra ry
5691 */ 5691 */
5692 ImplicitConstructorBuilder.con2(ResolvableLibrary library, Source source, Type Provider typeProvider) : super.con4(library, source, typeProvider); 5692 ImplicitConstructorBuilder.con2(ResolvableLibrary library, Source source, Type Provider typeProvider) : super.con4(library, source, typeProvider);
5693 5693
5694 @override 5694 @override
5695 Object visitClassDeclaration(ClassDeclaration node) => null; 5695 Object visitClassDeclaration(ClassDeclaration node) {
5696 ClassElementImpl classElement = node.element;
5697 classElement.mixinErrorsReported = false;
5698 if (node.extendsClause != null && node.withClause != null) {
5699 // We don't need to build any implicitly constructors for the mixin
5700 // application (since there isn't an explicit element for it), but we
5701 // need to verify that they _could_ be built.
5702 InterfaceType superclassType = null;
5703 TypeName superclassName = node.extendsClause.superclass;
5704 DartType type = superclassName.type;
5705 if (type is InterfaceType) {
5706 superclassType = type;
5707 } else {
5708 superclassType = typeProvider.objectType;
5709 }
5710 ClassElement superclassElement = classElement.supertype.element;
5711 if (superclassElement != null) {
5712 bool constructorFound = false;
5713 void callback(ConstructorElement explicitConstructor,
5714 List<DartType> parameterTypes,
5715 List<DartType> argumentTypes) {
5716 constructorFound = true;
5717 }
5718 if (_findForwardedConstructors(
5719 classElement, superclassName, superclassType, callback) &&
5720 !constructorFound) {
5721 reportErrorForNode(CompileTimeErrorCode.MIXIN_HAS_NO_CONSTRUCTORS,
5722 node.withClause, [superclassType.element.name]);
5723 classElement.mixinErrorsReported = true;
5724 }
5725 }
5726 }
5727 return null;
5728 }
5696 5729
5697 @override 5730 @override
5698 Object visitClassTypeAlias(ClassTypeAlias node) { 5731 Object visitClassTypeAlias(ClassTypeAlias node) {
5699 super.visitClassTypeAlias(node); 5732 super.visitClassTypeAlias(node);
5700 InterfaceType superclassType = null; 5733 InterfaceType superclassType = null;
5701 DartType type = node.superclass.type; 5734 TypeName superclassName = node.superclass;
5735 DartType type = superclassName.type;
5702 if (type is InterfaceType) { 5736 if (type is InterfaceType) {
5703 superclassType = type; 5737 superclassType = type;
5704 } else { 5738 } else {
5705 superclassType = typeProvider.objectType; 5739 superclassType = typeProvider.objectType;
5706 } 5740 }
5707 ClassElementImpl classElement = node.element as ClassElementImpl; 5741 ClassElementImpl classElement = node.element as ClassElementImpl;
5708 if (classElement != null) { 5742 if (classElement != null) {
5709 ClassElement superclassElement = superclassType.element; 5743 if (superclassType.element != null) {
5710 if (superclassElement != null) { 5744 List<ConstructorElement> implicitConstructors =
5711 List<ConstructorElement> constructors = superclassElement.constructors; 5745 new List<ConstructorElement>();
5712 int count = constructors.length; 5746 void callback(ConstructorElement explicitConstructor,
5713 if (count > 0) { 5747 List<DartType> parameterTypes,
5714 List<DartType> parameterTypes = TypeParameterTypeImpl.getTypes(supercl assType.typeParameters); 5748 List<DartType> argumentTypes) {
5715 List<DartType> argumentTypes = _getArgumentTypes(node.superclass.typeA rguments, parameterTypes); 5749 implicitConstructors.add(_createImplicitContructor(
5716 InterfaceType classType = classElement.type; 5750 classElement.type,
5717 List<ConstructorElement> implicitConstructors = new List<ConstructorEl ement>(); 5751 explicitConstructor,
5718 for (int i = 0; i < count; i++) { 5752 parameterTypes,
5719 ConstructorElement explicitConstructor = constructors[i]; 5753 argumentTypes));
5720 if (!explicitConstructor.isFactory && 5754 }
5721 classElement.isSuperConstructorAccessible(explicitConstructor)) { 5755 if (_findForwardedConstructors(
5722 implicitConstructors.add(_createImplicitContructor(classType, expl icitConstructor, parameterTypes, argumentTypes)); 5756 classElement, superclassName, superclassType, callback)) {
5723 }
5724 }
5725 if (implicitConstructors.isEmpty) { 5757 if (implicitConstructors.isEmpty) {
5726 reportErrorForNode(CompileTimeErrorCode.MIXIN_HAS_NO_CONSTRUCTORS, 5758 reportErrorForNode(CompileTimeErrorCode.MIXIN_HAS_NO_CONSTRUCTORS,
5727 node, [superclassElement.name]); 5759 node, [superclassType.element.name]);
5760 } else {
5761 classElement.constructors = implicitConstructors;
5728 } 5762 }
5729 classElement.constructors = implicitConstructors;
5730 } 5763 }
5731 } 5764 }
5732 } 5765 }
5733 return null; 5766 return null;
5734 } 5767 }
5735 5768
5769 /**
5770 * Find all the constructors that should be forwarded from the superclass
5771 * named [superclassName], having type [superclassType], to the class or
5772 * mixin application [classElement], and pass information about them to
5773 * [callback].
5774 *
5775 * Return true if some constructors were considered. (A false return value
5776 * can only happen if the supeclass is a built-in type, in which case it
5777 * can't be used as a mixin anyway).
5778 */
5779 bool _findForwardedConstructors(
5780 ClassElementImpl classElement,
5781 TypeName superclassName,
5782 InterfaceType superclassType,
5783 void callback(ConstructorElement explicitConstructor,
5784 List<DartType> parameterTypes,
5785 List<DartType> argumentTypes)) {
5786 ClassElement superclassElement = superclassType.element;
5787 List<ConstructorElement> constructors = superclassElement.constructors;
5788 int count = constructors.length;
5789 if (count == 0) {
5790 return false;
5791 }
5792 List<DartType> parameterTypes = TypeParameterTypeImpl.getTypes(superclassTyp e.typeParameters);
5793 List<DartType> argumentTypes = _getArgumentTypes(superclassName.typeArgument s, parameterTypes);
5794 for (int i = 0; i < count; i++) {
5795 ConstructorElement explicitConstructor = constructors[i];
5796 if (!explicitConstructor.isFactory &&
5797 classElement.isSuperConstructorAccessible(explicitConstructor)) {
5798 callback(explicitConstructor, parameterTypes, argumentTypes);
5799 }
5800 }
5801 return true;
5802 }
5803
5736 @override 5804 @override
5737 Object visitEnumDeclaration(EnumDeclaration node) => null; 5805 Object visitEnumDeclaration(EnumDeclaration node) => null;
5738 5806
5739 @override 5807 @override
5740 Object visitFunctionDeclaration(FunctionDeclaration node) => null; 5808 Object visitFunctionDeclaration(FunctionDeclaration node) => null;
5741 5809
5742 @override 5810 @override
5743 Object visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) => n ull; 5811 Object visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) => n ull;
5744 5812
5745 /** 5813 /**
(...skipping 10021 matching lines...) Expand 10 before | Expand all | Expand 10 after
15767 _errorListener.onError( 15835 _errorListener.onError(
15768 new AnalysisError.con2( 15836 new AnalysisError.con2(
15769 element.source, 15837 element.source,
15770 element.nameOffset, 15838 element.nameOffset,
15771 element.displayName.length, 15839 element.displayName.length,
15772 errorCode, 15840 errorCode,
15773 arguments)); 15841 arguments));
15774 } 15842 }
15775 } 15843 }
15776 } 15844 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698