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

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: Update comments (according to my dictionary whitelist is a word). 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 4f619ce409d95af65fd427461bbbb1af53082e63..b741eb9e38b562ddecfa5c4a813be9e6c0b0fcbd 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.reportHint(
+ operatorEquals, MessageKind.OVERRIDE_EQUALS_NOT_HASH_CODE,
+ {'class': cls.name.slowToString()});
+ }
+
void checkArity(FunctionElement function,
int requiredParameterCount, MessageKind messageKind,
bool isMinus) {
@@ -2236,7 +2248,7 @@ class ResolverVisitor extends MappingVisitor<Element> {
sendIsMemberAccess = oldSendIsMemberAccess;
if (target != null && target == compiler.mirrorSystemGetNameFunction) {
- compiler.reportWarningCode(
+ compiler.reportHint(
node.selector, MessageKind.STATIC_FUNCTION_BLOAT,
{'class': compiler.mirrorSystemClass.name,
'name': compiler.mirrorSystemGetNameFunction.name});
@@ -2656,7 +2668,7 @@ class ResolverVisitor extends MappingVisitor<Element> {
}
}
} else {
- compiler.reportWarningCode(
+ compiler.reportHint(
node.newToken, MessageKind.NON_CONST_BLOAT,
{'name': compiler.symbolClass.name});
world.registerNewSymbol(mapping);

Powered by Google App Engine
This is Rietveld 408576698