From 861ea6a30fb3b00940a59083001df015372a050d Mon Sep 17 00:00:00 2001 From: Simon Ogorodnik Date: Tue, 23 Apr 2019 04:20:01 +0300 Subject: [PATCH] Provide hashCode and equals for lookup tag based types --- .../kotlin/fir/symbols/ConeLookupTags.kt | 17 ++++++++++++++- .../jetbrains/kotlin/fir/types/impl/Impl.kt | 21 +++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/compiler/fir/cones/src/org/jetbrains/kotlin/fir/symbols/ConeLookupTags.kt b/compiler/fir/cones/src/org/jetbrains/kotlin/fir/symbols/ConeLookupTags.kt index 2329c88390a..855097c730a 100644 --- a/compiler/fir/cones/src/org/jetbrains/kotlin/fir/symbols/ConeLookupTags.kt +++ b/compiler/fir/cones/src/org/jetbrains/kotlin/fir/symbols/ConeLookupTags.kt @@ -31,4 +31,19 @@ interface ConeTypeAliasLookupTag : ConeClassLikeLookupTag interface ConeClassLookupTag : ConeClassLikeLookupTag -class ConeClassLikeLookupTagImpl(override val classId: ClassId) : ConeClassLikeLookupTag +class ConeClassLikeLookupTagImpl(override val classId: ClassId) : ConeClassLikeLookupTag { + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (javaClass != other?.javaClass) return false + + other as ConeClassLikeLookupTagImpl + + if (classId != other.classId) return false + + return true + } + + override fun hashCode(): Int { + return classId.hashCode() + } +} diff --git a/compiler/fir/cones/src/org/jetbrains/kotlin/fir/types/impl/Impl.kt b/compiler/fir/cones/src/org/jetbrains/kotlin/fir/types/impl/Impl.kt index 6c83588ca8e..9601c98a8b7 100644 --- a/compiler/fir/cones/src/org/jetbrains/kotlin/fir/types/impl/Impl.kt +++ b/compiler/fir/cones/src/org/jetbrains/kotlin/fir/types/impl/Impl.kt @@ -15,6 +15,27 @@ open class ConeClassTypeImpl( isNullable: Boolean ) : ConeClassType() { override val nullability: ConeNullability = ConeNullability.create(isNullable) + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (javaClass != other?.javaClass) return false + + other as ConeClassTypeImpl + + if (lookupTag != other.lookupTag) return false + if (!typeArguments.contentEquals(other.typeArguments)) return false + if (nullability != other.nullability) return false + + return true + } + + override fun hashCode(): Int { + var result = lookupTag.hashCode() + result = 31 * result + typeArguments.contentHashCode() + result = 31 * result + nullability.hashCode() + return result + } + + } class ConeAbbreviatedTypeImpl(