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

Side by Side Diff: sdk/lib/_internal/compiler/implementation/resolution/members.dart

Issue 140803002: Perform override and inheritance checks. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 11 months 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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 part of resolution; 5 part of resolution;
6 6
7 abstract class TreeElements { 7 abstract class TreeElements {
8 Element get currentElement; 8 Element get currentElement;
9 Setlet<Node> get superUses; 9 Setlet<Node> get superUses;
10 10
(...skipping 905 matching lines...) Expand 10 before | Expand all | Expand 10 after
916 constConstructors.add(member); 916 constConstructors.add(member);
917 } 917 }
918 } 918 }
919 if (member.isField()) { 919 if (member.isField()) {
920 if (!member.modifiers.isStatic() && 920 if (!member.modifiers.isStatic() &&
921 !member.modifiers.isFinal()) { 921 !member.modifiers.isFinal()) {
922 nonFinalInstanceFields.add(member); 922 nonFinalInstanceFields.add(member);
923 } 923 }
924 } 924 }
925 checkAbstractField(member); 925 checkAbstractField(member);
926 checkValidOverride(member, cls.lookupSuperMember(member.name));
927 checkUserDefinableOperator(member); 926 checkUserDefinableOperator(member);
928 }); 927 });
929 }); 928 });
930 if (!constConstructors.isEmpty && !nonFinalInstanceFields.isEmpty) { 929 if (!constConstructors.isEmpty && !nonFinalInstanceFields.isEmpty) {
931 Spannable span = constConstructors.length > 1 930 Spannable span = constConstructors.length > 1
932 ? cls : constConstructors[0]; 931 ? cls : constConstructors[0];
933 compiler.reportError(span, 932 compiler.reportError(span,
934 MessageKind.CONST_CONSTRUCTOR_WITH_NONFINAL_FIELDS, 933 MessageKind.CONST_CONSTRUCTOR_WITH_NONFINAL_FIELDS,
935 {'className': cls.name}); 934 {'className': cls.name});
936 if (constConstructors.length > 1) { 935 if (constConstructors.length > 1) {
937 for (Element constructor in constConstructors) { 936 for (Element constructor in constConstructors) {
938 compiler.reportInfo(constructor, 937 compiler.reportInfo(constructor,
939 MessageKind.CONST_CONSTRUCTOR_WITH_NONFINAL_FIELDS_CONSTRUCTOR); 938 MessageKind.CONST_CONSTRUCTOR_WITH_NONFINAL_FIELDS_CONSTRUCTOR);
940 } 939 }
941 } 940 }
942 for (Element field in nonFinalInstanceFields) { 941 for (Element field in nonFinalInstanceFields) {
943 compiler.reportInfo(field, 942 compiler.reportInfo(field,
944 MessageKind.CONST_CONSTRUCTOR_WITH_NONFINAL_FIELDS_FIELD); 943 MessageKind.CONST_CONSTRUCTOR_WITH_NONFINAL_FIELDS_FIELD);
945 } 944 }
946 } 945 }
947
948 if (!cls.isAbstract) {
949 for (DartType supertype in cls.allSupertypes) {
950 // This must have been reported elsewhere.
951 if (!supertype.element.isClass()) continue;
952 ClassElement superclass = supertype.element;
953 superclass.forEachMember((ClassElement holder, Element member) {
954 if (member.isAbstract) {
955 Element mine = cls.lookupMember(member.name);
956 if (mine == null || mine.isAbstract) {
957 compiler.reportWarningCode(
958 cls, MessageKind.UNIMPLEMENTED_METHOD,
959 {'class_name': cls.name, 'member_name': member.name});
960 compiler.reportHint(member, MessageKind.THIS_IS_THE_METHOD, {});
961 }
962 }
963 });
964 }
965 }
966 } 946 }
967 947
968 void checkAbstractField(Element member) { 948 void checkAbstractField(Element member) {
969 // Only check for getters. The test can only fail if there is both a setter 949 // Only check for getters. The test can only fail if there is both a setter
970 // and a getter with the same name, and we only need to check each abstract 950 // and a getter with the same name, and we only need to check each abstract
971 // field once, so we just ignore setters. 951 // field once, so we just ignore setters.
972 if (!member.isGetter()) return; 952 if (!member.isGetter()) return;
973 953
974 // Find the associated abstract field. 954 // Find the associated abstract field.
975 ClassElement classElement = member.getEnclosingClass(); 955 ClassElement classElement = member.getEnclosingClass();
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
1108 Element contextElement, 1088 Element contextElement,
1109 MessageKind contextMessage) { 1089 MessageKind contextMessage) {
1110 compiler.reportError( 1090 compiler.reportError(
1111 errorneousElement, 1091 errorneousElement,
1112 errorMessage, 1092 errorMessage,
1113 {'memberName': contextElement.name, 1093 {'memberName': contextElement.name,
1114 'className': contextElement.getEnclosingClass().name}); 1094 'className': contextElement.getEnclosingClass().name});
1115 compiler.reportInfo(contextElement, contextMessage); 1095 compiler.reportInfo(contextElement, contextMessage);
1116 } 1096 }
1117 1097
1118 void checkValidOverride(Element member, Element superMember) {
1119 if (superMember == null) return;
1120 if (member.modifiers.isStatic()) {
1121 reportErrorWithContext(
1122 member, MessageKind.NO_STATIC_OVERRIDE,
1123 superMember, MessageKind.NO_STATIC_OVERRIDE_CONT);
1124 } else {
1125 FunctionElement superFunction = superMember.asFunctionElement();
1126 FunctionElement function = member.asFunctionElement();
1127 if (superFunction == null || superFunction.isAccessor()) {
1128 // Field or accessor in super.
1129 if (function != null && !function.isAccessor()) {
1130 // But a plain method in this class.
1131 reportErrorWithContext(
1132 member, MessageKind.CANNOT_OVERRIDE_FIELD_WITH_METHOD,
1133 superMember, MessageKind.CANNOT_OVERRIDE_FIELD_WITH_METHOD_CONT);
1134 }
1135 } else {
1136 // Instance method in super.
1137 if (function == null || function.isAccessor()) {
1138 // But a field (or accessor) in this class.
1139 reportErrorWithContext(
1140 member, MessageKind.CANNOT_OVERRIDE_METHOD_WITH_FIELD,
1141 superMember, MessageKind.CANNOT_OVERRIDE_METHOD_WITH_FIELD_CONT);
1142 } else {
1143 // Both are plain instance methods.
1144 if (superFunction.requiredParameterCount(compiler) !=
1145 function.requiredParameterCount(compiler)) {
1146 reportErrorWithContext(
1147 member,
1148 MessageKind.BAD_ARITY_OVERRIDE,
1149 superMember,
1150 MessageKind.BAD_ARITY_OVERRIDE_CONT);
1151 }
1152 // TODO(ahe): Check optional parameters.
1153 }
1154 }
1155 }
1156 }
1157 1098
1158 FunctionSignature resolveSignature(FunctionElement element) { 1099 FunctionSignature resolveSignature(FunctionElement element) {
1159 MessageKind defaultValuesError = null; 1100 MessageKind defaultValuesError = null;
1160 if (element.isFactoryConstructor()) { 1101 if (element.isFactoryConstructor()) {
1161 FunctionExpression body = element.parseNode(compiler); 1102 FunctionExpression body = element.parseNode(compiler);
1162 if (body.isRedirectingFactory) { 1103 if (body.isRedirectingFactory) {
1163 defaultValuesError = MessageKind.REDIRECTING_FACTORY_WITH_DEFAULT; 1104 defaultValuesError = MessageKind.REDIRECTING_FACTORY_WITH_DEFAULT;
1164 } 1105 }
1165 } 1106 }
1166 return compiler.withCurrentElement(element, () { 1107 return compiler.withCurrentElement(element, () {
(...skipping 3634 matching lines...) Expand 10 before | Expand all | Expand 10 after
4801 return finishConstructorReference(visit(expression), 4742 return finishConstructorReference(visit(expression),
4802 expression, expression); 4743 expression, expression);
4803 } 4744 }
4804 } 4745 }
4805 4746
4806 /// Looks up [name] in [scope] and unwraps the result. 4747 /// Looks up [name] in [scope] and unwraps the result.
4807 Element lookupInScope(Compiler compiler, Node node, 4748 Element lookupInScope(Compiler compiler, Node node,
4808 Scope scope, String name) { 4749 Scope scope, String name) {
4809 return Elements.unwrap(scope.lookup(name), compiler, node); 4750 return Elements.unwrap(scope.lookup(name), compiler, node);
4810 } 4751 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698