[Invariant Fix] Fix equality for NewCapturedTypeConstructor after refinement

This commit is contained in:
Denis Zharkov
2019-05-23 12:44:10 +03:00
committed by Dmitry Savvinov
parent 471134d31e
commit c49791f8bb
@@ -152,7 +152,11 @@ class NewCapturedType(
)
}
class NewCapturedTypeConstructor(override val projection: TypeProjection, private var supertypes: List<UnwrappedType>? = null) :
class NewCapturedTypeConstructor(
override val projection: TypeProjection,
private var supertypes: List<UnwrappedType>? = null,
private val original: NewCapturedTypeConstructor? = null
) :
CapturedTypeConstructor {
fun initializeSupertypes(supertypes: List<UnwrappedType>) {
assert(this.supertypes == null) {
@@ -171,7 +175,21 @@ class NewCapturedTypeConstructor(override val projection: TypeProjection, privat
@TypeRefinement
override fun refine(kotlinTypeRefiner: KotlinTypeRefiner) =
NewCapturedTypeConstructor(projection.refine(kotlinTypeRefiner), supertypes?.map { it.refine(kotlinTypeRefiner) })
NewCapturedTypeConstructor(
projection.refine(kotlinTypeRefiner),
supertypes?.map { it.refine(kotlinTypeRefiner) },
original ?: this
)
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false
other as NewCapturedTypeConstructor
return (original ?: this) === (other.original ?: other)
}
override fun hashCode(): Int = original?.hashCode() ?: super.hashCode()
override fun toString() = "CapturedType($projection)"
}