| OLD | NEW |
| 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 929 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 940 constConstructors.add(member); | 940 constConstructors.add(member); |
| 941 } | 941 } |
| 942 } | 942 } |
| 943 if (member.isField()) { | 943 if (member.isField()) { |
| 944 if (!member.modifiers.isStatic() && | 944 if (!member.modifiers.isStatic() && |
| 945 !member.modifiers.isFinal()) { | 945 !member.modifiers.isFinal()) { |
| 946 nonFinalInstanceFields.add(member); | 946 nonFinalInstanceFields.add(member); |
| 947 } | 947 } |
| 948 } | 948 } |
| 949 checkAbstractField(member); | 949 checkAbstractField(member); |
| 950 checkValidOverride(member, cls.lookupSuperMember(member.name)); | |
| 951 checkUserDefinableOperator(member); | 950 checkUserDefinableOperator(member); |
| 952 }); | 951 }); |
| 953 }); | 952 }); |
| 954 if (!constConstructors.isEmpty && !nonFinalInstanceFields.isEmpty) { | 953 if (!constConstructors.isEmpty && !nonFinalInstanceFields.isEmpty) { |
| 955 Spannable span = constConstructors.length > 1 | 954 Spannable span = constConstructors.length > 1 |
| 956 ? cls : constConstructors[0]; | 955 ? cls : constConstructors[0]; |
| 957 compiler.reportError(span, | 956 compiler.reportError(span, |
| 958 MessageKind.CONST_CONSTRUCTOR_WITH_NONFINAL_FIELDS, | 957 MessageKind.CONST_CONSTRUCTOR_WITH_NONFINAL_FIELDS, |
| 959 {'className': cls.name}); | 958 {'className': cls.name}); |
| 960 if (constConstructors.length > 1) { | 959 if (constConstructors.length > 1) { |
| 961 for (Element constructor in constConstructors) { | 960 for (Element constructor in constConstructors) { |
| 962 compiler.reportInfo(constructor, | 961 compiler.reportInfo(constructor, |
| 963 MessageKind.CONST_CONSTRUCTOR_WITH_NONFINAL_FIELDS_CONSTRUCTOR); | 962 MessageKind.CONST_CONSTRUCTOR_WITH_NONFINAL_FIELDS_CONSTRUCTOR); |
| 964 } | 963 } |
| 965 } | 964 } |
| 966 for (Element field in nonFinalInstanceFields) { | 965 for (Element field in nonFinalInstanceFields) { |
| 967 compiler.reportInfo(field, | 966 compiler.reportInfo(field, |
| 968 MessageKind.CONST_CONSTRUCTOR_WITH_NONFINAL_FIELDS_FIELD); | 967 MessageKind.CONST_CONSTRUCTOR_WITH_NONFINAL_FIELDS_FIELD); |
| 969 } | 968 } |
| 970 } | 969 } |
| 971 | |
| 972 if (!cls.isAbstract) { | |
| 973 for (DartType supertype in cls.allSupertypes) { | |
| 974 // This must have been reported elsewhere. | |
| 975 if (!supertype.element.isClass()) continue; | |
| 976 ClassElement superclass = supertype.element; | |
| 977 superclass.forEachMember((ClassElement holder, Element member) { | |
| 978 if (member.isAbstract) { | |
| 979 Element mine = cls.lookupMember(member.name); | |
| 980 if (mine == null || mine.isAbstract) { | |
| 981 compiler.reportWarningCode( | |
| 982 cls, MessageKind.UNIMPLEMENTED_METHOD, | |
| 983 {'class_name': cls.name, 'member_name': member.name}); | |
| 984 compiler.reportHint(member, MessageKind.THIS_IS_THE_METHOD, {}); | |
| 985 } | |
| 986 } | |
| 987 }); | |
| 988 } | |
| 989 } | |
| 990 } | 970 } |
| 991 | 971 |
| 992 void checkAbstractField(Element member) { | 972 void checkAbstractField(Element member) { |
| 993 // Only check for getters. The test can only fail if there is both a setter | 973 // Only check for getters. The test can only fail if there is both a setter |
| 994 // and a getter with the same name, and we only need to check each abstract | 974 // and a getter with the same name, and we only need to check each abstract |
| 995 // field once, so we just ignore setters. | 975 // field once, so we just ignore setters. |
| 996 if (!member.isGetter()) return; | 976 if (!member.isGetter()) return; |
| 997 | 977 |
| 998 // Find the associated abstract field. | 978 // Find the associated abstract field. |
| 999 ClassElement classElement = member.getEnclosingClass(); | 979 ClassElement classElement = member.getEnclosingClass(); |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1132 Element contextElement, | 1112 Element contextElement, |
| 1133 MessageKind contextMessage) { | 1113 MessageKind contextMessage) { |
| 1134 compiler.reportError( | 1114 compiler.reportError( |
| 1135 errorneousElement, | 1115 errorneousElement, |
| 1136 errorMessage, | 1116 errorMessage, |
| 1137 {'memberName': contextElement.name, | 1117 {'memberName': contextElement.name, |
| 1138 'className': contextElement.getEnclosingClass().name}); | 1118 'className': contextElement.getEnclosingClass().name}); |
| 1139 compiler.reportInfo(contextElement, contextMessage); | 1119 compiler.reportInfo(contextElement, contextMessage); |
| 1140 } | 1120 } |
| 1141 | 1121 |
| 1142 void checkValidOverride(Element member, Element superMember) { | |
| 1143 if (superMember == null) return; | |
| 1144 if (member.modifiers.isStatic()) { | |
| 1145 reportErrorWithContext( | |
| 1146 member, MessageKind.NO_STATIC_OVERRIDE, | |
| 1147 superMember, MessageKind.NO_STATIC_OVERRIDE_CONT); | |
| 1148 } else { | |
| 1149 FunctionElement superFunction = superMember.asFunctionElement(); | |
| 1150 FunctionElement function = member.asFunctionElement(); | |
| 1151 if (superFunction == null || superFunction.isAccessor()) { | |
| 1152 // Field or accessor in super. | |
| 1153 if (function != null && !function.isAccessor()) { | |
| 1154 // But a plain method in this class. | |
| 1155 reportErrorWithContext( | |
| 1156 member, MessageKind.CANNOT_OVERRIDE_FIELD_WITH_METHOD, | |
| 1157 superMember, MessageKind.CANNOT_OVERRIDE_FIELD_WITH_METHOD_CONT); | |
| 1158 } | |
| 1159 } else { | |
| 1160 // Instance method in super. | |
| 1161 if (function == null || function.isAccessor()) { | |
| 1162 // But a field (or accessor) in this class. | |
| 1163 reportErrorWithContext( | |
| 1164 member, MessageKind.CANNOT_OVERRIDE_METHOD_WITH_FIELD, | |
| 1165 superMember, MessageKind.CANNOT_OVERRIDE_METHOD_WITH_FIELD_CONT); | |
| 1166 } else { | |
| 1167 // Both are plain instance methods. | |
| 1168 if (superFunction.requiredParameterCount(compiler) != | |
| 1169 function.requiredParameterCount(compiler)) { | |
| 1170 reportErrorWithContext( | |
| 1171 member, | |
| 1172 MessageKind.BAD_ARITY_OVERRIDE, | |
| 1173 superMember, | |
| 1174 MessageKind.BAD_ARITY_OVERRIDE_CONT); | |
| 1175 } | |
| 1176 // TODO(ahe): Check optional parameters. | |
| 1177 } | |
| 1178 } | |
| 1179 } | |
| 1180 } | |
| 1181 | 1122 |
| 1182 FunctionSignature resolveSignature(FunctionElement element) { | 1123 FunctionSignature resolveSignature(FunctionElement element) { |
| 1183 MessageKind defaultValuesError = null; | 1124 MessageKind defaultValuesError = null; |
| 1184 if (element.isFactoryConstructor()) { | 1125 if (element.isFactoryConstructor()) { |
| 1185 FunctionExpression body = element.parseNode(compiler); | 1126 FunctionExpression body = element.parseNode(compiler); |
| 1186 if (body.isRedirectingFactory) { | 1127 if (body.isRedirectingFactory) { |
| 1187 defaultValuesError = MessageKind.REDIRECTING_FACTORY_WITH_DEFAULT; | 1128 defaultValuesError = MessageKind.REDIRECTING_FACTORY_WITH_DEFAULT; |
| 1188 } | 1129 } |
| 1189 } | 1130 } |
| 1190 return compiler.withCurrentElement(element, () { | 1131 return compiler.withCurrentElement(element, () { |
| (...skipping 3373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4564 return finishConstructorReference(visit(expression), | 4505 return finishConstructorReference(visit(expression), |
| 4565 expression, expression); | 4506 expression, expression); |
| 4566 } | 4507 } |
| 4567 } | 4508 } |
| 4568 | 4509 |
| 4569 /// Looks up [name] in [scope] and unwraps the result. | 4510 /// Looks up [name] in [scope] and unwraps the result. |
| 4570 Element lookupInScope(Compiler compiler, Node node, | 4511 Element lookupInScope(Compiler compiler, Node node, |
| 4571 Scope scope, String name) { | 4512 Scope scope, String name) { |
| 4572 return Elements.unwrap(scope.lookup(name), compiler, node); | 4513 return Elements.unwrap(scope.lookup(name), compiler, node); |
| 4573 } | 4514 } |
| OLD | NEW |