| Index: lib/compiler/implementation/typechecker.dart
|
| diff --git a/lib/compiler/implementation/typechecker.dart b/lib/compiler/implementation/typechecker.dart
|
| index 1ac592b557d0c985ad4d34f88fe7e73a30751c5a..58954f01ea29eca67ffb2c321ff21cf772544d83 100644
|
| --- a/lib/compiler/implementation/typechecker.dart
|
| +++ b/lib/compiler/implementation/typechecker.dart
|
| @@ -24,9 +24,9 @@ class TypeCheckerTask extends CompilerTask {
|
| }
|
| }
|
|
|
| -interface Type {
|
| - SourceString get name();
|
| - Element get element();
|
| +abstract class Type implements Hashable {
|
| + abstract SourceString get name();
|
| + abstract Element get element();
|
|
|
| /**
|
| * Returns the unaliased type of this type.
|
| @@ -38,7 +38,9 @@ interface Type {
|
| * function type [: (B) -> A :] and the unaliased type of
|
| * [: Func<int,String> :] is the function type [: (String) -> int :].
|
| */
|
| - Type unalias(Compiler compiler);
|
| + abstract Type unalias(Compiler compiler);
|
| +
|
| + abstract bool equals(other);
|
| }
|
|
|
| class TypeVariableType implements Type {
|
| @@ -50,6 +52,13 @@ class TypeVariableType implements Type {
|
|
|
| Type unalias(Compiler compiler) => this;
|
|
|
| + int hashCode() => 17 * element.hashCode();
|
| +
|
| + bool equals(other) {
|
| + if (other is !TypeVariableType) return false;
|
| + return other.element == element;
|
| + }
|
| +
|
| String toString() => name.slowToString();
|
| }
|
|
|
| @@ -75,6 +84,13 @@ class StatementType implements Type {
|
|
|
| Type unalias(Compiler compiler) => this;
|
|
|
| + int hashCode() => 17 * stringName.hashCode();
|
| +
|
| + bool equals(other) {
|
| + if (other is !StatementType) return false;
|
| + return other.stringName == stringName;
|
| + }
|
| +
|
| String toString() => stringName;
|
| }
|
|
|
| @@ -85,6 +101,10 @@ class VoidType implements Type {
|
|
|
| Type unalias(Compiler compiler) => this;
|
|
|
| + int hashCode() => 1729;
|
| +
|
| + bool equals(other) => other is VoidType;
|
| +
|
| String toString() => name.slowToString();
|
| }
|
|
|
| @@ -109,6 +129,21 @@ class InterfaceType implements Type {
|
| }
|
| return sb.toString();
|
| }
|
| +
|
| + int hashCode() {
|
| + int hash = element.hashCode();
|
| + for (Link<Type> arguments = this.arguments;
|
| + !arguments.isEmpty();
|
| + arguments = arguments.tail) {
|
| + hash = 17 * hash + 3 * arguments.head.hashCode();
|
| + }
|
| + return hash;
|
| + }
|
| +
|
| + bool equals(other) {
|
| + if (other is !InterfaceType) return false;
|
| + return arguments == other.arguments;
|
| + }
|
| }
|
|
|
| class FunctionType implements Type {
|
| @@ -144,6 +179,22 @@ class FunctionType implements Type {
|
| returnType = other.returnType;
|
| parameterTypes = other.parameterTypes;
|
| }
|
| +
|
| + int hashCode() {
|
| + int hash = 17 * element.hashCode() + 3 * returnType.hashCode();
|
| + for (Link<Type> parameters = parameterTypes;
|
| + !parameters.isEmpty();
|
| + parameters = parameters.tail) {
|
| + hash = 17 * hash + 3 * parameters.head.hashCode();
|
| + }
|
| + return hash;
|
| + }
|
| +
|
| + bool equals(other) {
|
| + if (other is !FunctionType) return false;
|
| + return returnType == other.returnType
|
| + && parameterTypes == other.parameterTypes;
|
| + }
|
| }
|
|
|
| class TypedefType implements Type {
|
| @@ -171,6 +222,13 @@ class TypedefType implements Type {
|
| }
|
| return sb.toString();
|
| }
|
| +
|
| + int hashCode() => 17 * element.hashCode();
|
| +
|
| + bool equals(other) {
|
| + if (other is !TypedefType) return false;
|
| + return other.element == element;
|
| + }
|
| }
|
|
|
| class Types {
|
|
|