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

Unified Diff: dart/sdk/lib/_internal/compiler/implementation/dart_types.dart

Issue 17569004: Implement hashCode on objects stored in a set or used as map keys. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Rebased on CL 17588005. 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/dart_types.dart
diff --git a/dart/sdk/lib/_internal/compiler/implementation/dart_types.dart b/dart/sdk/lib/_internal/compiler/implementation/dart_types.dart
index d4fc525d28216003981ff210eb1e833b5572ca2e..fd9ed6332f635feec4f5ec9ea1e389ff90b904ab 100644
--- a/dart/sdk/lib/_internal/compiler/implementation/dart_types.dart
+++ b/dart/sdk/lib/_internal/compiler/implementation/dart_types.dart
@@ -94,6 +94,8 @@ abstract class DartType {
*/
bool forEachMalformedType(bool f(MalformedType type)) => true;
+ // TODO(ahe): This is implicitly inherited from Object. What is the purpose
+ // of duplicating it here?
ngeoffray 2013/06/24 19:43:10 Not my code, but I can understand why someone woul
ahe 2013/06/24 20:18:54 One of my concerns is that Dart is a dynamic langu
bool operator ==(other);
/**
@@ -319,6 +321,9 @@ class MalformedType extends DartType {
*/
final Link<DartType> typeArguments;
+ final int hashCode = (nextHash++) & 0x3fffffff;
+ static int nextHash = 43765;
+
MalformedType(this.element, this.userProvidedBadType,
[this.typeArguments = null]);
@@ -341,6 +346,8 @@ class MalformedType extends DartType {
return visitor.visitMalformedType(this, argument);
}
+ // TODO(ahe): This is the default implementation that would be inherited if
+ // DartType didn't declare an abstract method. What is the purpose?
bool operator ==(other) => identical(this, other);
String toString() {
@@ -547,10 +554,18 @@ class InterfaceType extends GenericType {
}
bool operator ==(other) {
+ // TODO(johnniwinther,karlklose): This is a bad implementation of
+ // operator==. This implementation is not compatible with the
+ // implementation in the superclass: another subclass of GenericType might
+ // compare equal to an instance of this class if the other subclass forgets
+ // to implement operator==. This is brittle and easy to avoid, ask ahe@
+ // for concrete suggestions.
if (other is !InterfaceType) return false;
return super == other;
}
+ int get hashCode => super.hashCode;
+
InterfaceType asRaw() => super.asRaw();
accept(DartTypeVisitor visitor, var argument) {
@@ -812,10 +827,13 @@ class TypedefType extends GenericType {
}
bool operator ==(other) {
+ // TODO(johnniwinther,karlklose): See InterfaceType.operator==.
if (other is !TypedefType) return false;
return super == other;
}
+ int get hashCode => super.hashCode;
+
TypedefType asRaw() => super.asRaw();
accept(DartTypeVisitor visitor, var argument) {

Powered by Google App Engine
This is Rietveld 408576698