From c83860187c6011daba7a21b03d41b26c74c645d3 Mon Sep 17 00:00:00 2001 From: Denis Zharkov Date: Tue, 7 Apr 2020 14:40:31 +0300 Subject: [PATCH] FIR: Add abstract equals/hashCode to ConeKotlinType Otherwise they are incosistent when being added to sets of constraints during type inference --- .../jetbrains/kotlin/fir/types/ConeTypes.kt | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/compiler/fir/cones/src/org/jetbrains/kotlin/fir/types/ConeTypes.kt b/compiler/fir/cones/src/org/jetbrains/kotlin/fir/types/ConeTypes.kt index 885b7f400c0..562565bf628 100644 --- a/compiler/fir/cones/src/org/jetbrains/kotlin/fir/types/ConeTypes.kt +++ b/compiler/fir/cones/src/org/jetbrains/kotlin/fir/types/ConeTypes.kt @@ -66,6 +66,9 @@ sealed class ConeKotlinType : ConeKotlinTypeProjection(), final override fun toString(): String { return render() } + + abstract override fun equals(other: Any?): Boolean + abstract override fun hashCode(): Int } sealed class ConeSimpleKotlinType : ConeKotlinType(), SimpleTypeMarker @@ -87,6 +90,9 @@ class ConeClassErrorType(val reason: String) : ConeClassLikeType() { override val nullability: ConeNullability get() = ConeNullability.UNKNOWN + + override fun equals(other: Any?) = this === other + override fun hashCode(): Int = System.identityHashCode(this) } abstract class ConeLookupTagBasedType : ConeSimpleKotlinType() { @@ -161,6 +167,29 @@ data class ConeCapturedType( override val typeArguments: Array get() = emptyArray() + + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (javaClass != other?.javaClass) return false + + other as ConeCapturedType + + if (lowerType != other.lowerType) return false + if (constructor != other.constructor) return false + if (captureStatus != other.captureStatus) return false + if (nullability != other.nullability) return false + + return true + } + + override fun hashCode(): Int { + var result = 0 + result = 31 * result + (lowerType?.hashCode() ?: 0) + result = 31 * result + constructor.hashCode() + result = 31 * result + captureStatus.hashCode() + result = 31 * result + nullability.hashCode() + return result + } } data class ConeTypeVariableType( @@ -223,6 +252,25 @@ fun ConeIntersectionType.mapTypes(func: (ConeKotlinType) -> ConeKotlinType): Con class ConeStubType(val variable: ConeTypeVariable, override val nullability: ConeNullability) : StubTypeMarker, ConeSimpleKotlinType() { override val typeArguments: Array get() = emptyArray() + + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (javaClass != other?.javaClass) return false + + other as ConeStubType + + if (variable != other.variable) return false + if (nullability != other.nullability) return false + + return true + } + + override fun hashCode(): Int { + var result = 0 + result = 31 * result + variable.hashCode() + result = 31 * result + nullability.hashCode() + return result + } } open class ConeTypeVariable(name: String) : TypeVariableMarker {