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

Unified 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: 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 side-by-side diff with in-line comments
Download patch
Index: dart/sdk/lib/_internal/compiler/implementation/resolution/members.dart
diff --git a/dart/sdk/lib/_internal/compiler/implementation/resolution/members.dart b/dart/sdk/lib/_internal/compiler/implementation/resolution/members.dart
index 04aa685fade9e6543db7053012bafd03d4c899a6..dca98d4f965f7f245633f07ecf74089d8d649503 100644
--- a/dart/sdk/lib/_internal/compiler/implementation/resolution/members.dart
+++ b/dart/sdk/lib/_internal/compiler/implementation/resolution/members.dart
@@ -778,6 +778,7 @@ class ResolverTask extends CompilerTask {
} else if (isBinaryOperator(value)) {
messageKind = MessageKind.BINARY_OPERATOR_BAD_ARITY;
requiredParameterCount = 1;
+ if (identical(value, '==')) checkOverrideHashCode(member);
} else if (isTernaryOperator(value)) {
messageKind = MessageKind.TERNARY_OPERATOR_BAD_ARITY;
requiredParameterCount = 2;
@@ -788,6 +789,17 @@ class ResolverTask extends CompilerTask {
checkArity(function, requiredParameterCount, messageKind, isMinus);
}
+ void checkOverrideHashCode(FunctionElement operatorEquals) {
+ if (operatorEquals.isAbstract(compiler)) return;
+ ClassElement cls = operatorEquals.getEnclosingClass();
+ Element hashCodeImplementation =
+ cls.lookupLocalMember(const SourceString('hashCode'));
+ if (hashCodeImplementation != null) return;
+ compiler.reportLint(
+ operatorEquals, MessageKind.OVERRIDE_EQUALS_NOT_HASH_CODE,
+ {'class': cls.name.slowToString()});
+ }
+
void checkArity(FunctionElement function,
int requiredParameterCount, MessageKind messageKind,
bool isMinus) {

Powered by Google App Engine
This is Rietveld 408576698