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

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

Issue 17588005: Warn about overriding operator== but not hashCode. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: "Hint", not "lint", also change symbol warning to be hints. Created 7 years, 6 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 Set<Node> get superUses; 9 Set<Node> get superUses;
10 10
(...skipping 760 matching lines...) Expand 10 before | Expand all | Expand 10 after
771 } else if (isMinusOperator(value)) { 771 } else if (isMinusOperator(value)) {
772 isMinus = true; 772 isMinus = true;
773 messageKind = MessageKind.MINUS_OPERATOR_BAD_ARITY; 773 messageKind = MessageKind.MINUS_OPERATOR_BAD_ARITY;
774 requiredParameterCount = 1; 774 requiredParameterCount = 1;
775 } else if (isUnaryOperator(value)) { 775 } else if (isUnaryOperator(value)) {
776 messageKind = MessageKind.UNARY_OPERATOR_BAD_ARITY; 776 messageKind = MessageKind.UNARY_OPERATOR_BAD_ARITY;
777 requiredParameterCount = 0; 777 requiredParameterCount = 0;
778 } else if (isBinaryOperator(value)) { 778 } else if (isBinaryOperator(value)) {
779 messageKind = MessageKind.BINARY_OPERATOR_BAD_ARITY; 779 messageKind = MessageKind.BINARY_OPERATOR_BAD_ARITY;
780 requiredParameterCount = 1; 780 requiredParameterCount = 1;
781 if (identical(value, '==')) checkOverrideHashCode(member);
781 } else if (isTernaryOperator(value)) { 782 } else if (isTernaryOperator(value)) {
782 messageKind = MessageKind.TERNARY_OPERATOR_BAD_ARITY; 783 messageKind = MessageKind.TERNARY_OPERATOR_BAD_ARITY;
783 requiredParameterCount = 2; 784 requiredParameterCount = 2;
784 } else { 785 } else {
785 compiler.internalErrorOnElement(function, 786 compiler.internalErrorOnElement(function,
786 'Unexpected user defined operator $value'); 787 'Unexpected user defined operator $value');
787 } 788 }
788 checkArity(function, requiredParameterCount, messageKind, isMinus); 789 checkArity(function, requiredParameterCount, messageKind, isMinus);
789 } 790 }
790 791
792 void checkOverrideHashCode(FunctionElement operatorEquals) {
793 if (operatorEquals.isAbstract(compiler)) return;
794 ClassElement cls = operatorEquals.getEnclosingClass();
795 Element hashCodeImplementation =
796 cls.lookupLocalMember(const SourceString('hashCode'));
797 if (hashCodeImplementation != null) return;
798 compiler.reportHint(
799 operatorEquals, MessageKind.OVERRIDE_EQUALS_NOT_HASH_CODE,
800 {'class': cls.name.slowToString()});
801 }
802
791 void checkArity(FunctionElement function, 803 void checkArity(FunctionElement function,
792 int requiredParameterCount, MessageKind messageKind, 804 int requiredParameterCount, MessageKind messageKind,
793 bool isMinus) { 805 bool isMinus) {
794 FunctionExpression node = function.parseNode(compiler); 806 FunctionExpression node = function.parseNode(compiler);
795 FunctionSignature signature = function.computeSignature(compiler); 807 FunctionSignature signature = function.computeSignature(compiler);
796 if (signature.requiredParameterCount != requiredParameterCount) { 808 if (signature.requiredParameterCount != requiredParameterCount) {
797 Node errorNode = node; 809 Node errorNode = node;
798 if (node.parameters != null) { 810 if (node.parameters != null) {
799 if (isMinus || 811 if (isMinus ||
800 signature.requiredParameterCount < requiredParameterCount) { 812 signature.requiredParameterCount < requiredParameterCount) {
(...skipping 1428 matching lines...) Expand 10 before | Expand all | Expand 10 after
2229 } 2241 }
2230 } 2242 }
2231 2243
2232 visitSend(Send node) { 2244 visitSend(Send node) {
2233 bool oldSendIsMemberAccess = sendIsMemberAccess; 2245 bool oldSendIsMemberAccess = sendIsMemberAccess;
2234 sendIsMemberAccess = node.isPropertyAccess || node.isCall; 2246 sendIsMemberAccess = node.isPropertyAccess || node.isCall;
2235 Element target = resolveSend(node); 2247 Element target = resolveSend(node);
2236 sendIsMemberAccess = oldSendIsMemberAccess; 2248 sendIsMemberAccess = oldSendIsMemberAccess;
2237 2249
2238 if (target != null && target == compiler.mirrorSystemGetNameFunction) { 2250 if (target != null && target == compiler.mirrorSystemGetNameFunction) {
2239 compiler.reportWarningCode( 2251 compiler.reportHint(
2240 node.selector, MessageKind.STATIC_FUNCTION_BLOAT, 2252 node.selector, MessageKind.STATIC_FUNCTION_BLOAT,
2241 {'class': compiler.mirrorSystemClass.name, 2253 {'class': compiler.mirrorSystemClass.name,
2242 'name': compiler.mirrorSystemGetNameFunction.name}); 2254 'name': compiler.mirrorSystemGetNameFunction.name});
2243 } 2255 }
2244 2256
2245 if (!Elements.isUnresolved(target)) { 2257 if (!Elements.isUnresolved(target)) {
2246 if (target.isAbstractField()) { 2258 if (target.isAbstractField()) {
2247 AbstractFieldElement field = target; 2259 AbstractFieldElement field = target;
2248 target = field.getter; 2260 target = field.getter;
2249 if (target == null && !inInstanceContext) { 2261 if (target == null && !inInstanceContext) {
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after
2649 compiler.reportErrorCode(argumentNode, MessageKind.STRING_EXPECTED, 2661 compiler.reportErrorCode(argumentNode, MessageKind.STRING_EXPECTED,
2650 {'type': type}); 2662 {'type': type});
2651 } else { 2663 } else {
2652 StringConstant stringConstant = name; 2664 StringConstant stringConstant = name;
2653 String nameString = stringConstant.toDartString().slowToString(); 2665 String nameString = stringConstant.toDartString().slowToString();
2654 if (validateSymbol(argumentNode, nameString)) { 2666 if (validateSymbol(argumentNode, nameString)) {
2655 world.registerConstSymbol(nameString, mapping); 2667 world.registerConstSymbol(nameString, mapping);
2656 } 2668 }
2657 } 2669 }
2658 } else { 2670 } else {
2659 compiler.reportWarningCode( 2671 compiler.reportHint(
2660 node.newToken, MessageKind.NON_CONST_BLOAT, 2672 node.newToken, MessageKind.NON_CONST_BLOAT,
2661 {'name': compiler.symbolClass.name}); 2673 {'name': compiler.symbolClass.name});
2662 world.registerNewSymbol(mapping); 2674 world.registerNewSymbol(mapping);
2663 } 2675 }
2664 } 2676 }
2665 2677
2666 return null; 2678 return null;
2667 } 2679 }
2668 2680
2669 bool validateSymbol(Node node, String name) { 2681 bool validateSymbol(Node node, String name) {
(...skipping 1384 matching lines...) Expand 10 before | Expand all | Expand 10 after
4054 return e; 4066 return e;
4055 } 4067 }
4056 4068
4057 /// Assumed to be called by [resolveRedirectingFactory]. 4069 /// Assumed to be called by [resolveRedirectingFactory].
4058 Element visitReturn(Return node) { 4070 Element visitReturn(Return node) {
4059 Node expression = node.expression; 4071 Node expression = node.expression;
4060 return finishConstructorReference(visit(expression), 4072 return finishConstructorReference(visit(expression),
4061 expression, expression); 4073 expression, expression);
4062 } 4074 }
4063 } 4075 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698