From b2275ae4240bf2167b90c2af44d6d0f3fdec9c86 Mon Sep 17 00:00:00 2001 From: Valentin Kipyatkov Date: Thu, 29 Jan 2015 16:36:32 +0300 Subject: [PATCH] Better equals in FuzzyType + do not need to treat not used parameters as free --- .../jetbrains/kotlin/idea/util/FuzzyType.kt | 25 +++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/idea/ide-common/src/org/jetbrains/kotlin/idea/util/FuzzyType.kt b/idea/ide-common/src/org/jetbrains/kotlin/idea/util/FuzzyType.kt index 76cd85c7e2a..686cbd9260c 100644 --- a/idea/ide-common/src/org/jetbrains/kotlin/idea/util/FuzzyType.kt +++ b/idea/ide-common/src/org/jetbrains/kotlin/idea/util/FuzzyType.kt @@ -43,16 +43,29 @@ fun FuzzyType.makeNotNullable() = FuzzyType(type.makeNotNullable(), freeParamete fun FuzzyType.makeNullable() = FuzzyType(type.makeNullable(), freeParameters) fun FuzzyType.nullability() = type.nullability() -data class FuzzyType( +class FuzzyType( val type: JetType, - val freeParameters: Collection + freeParameters: Collection ) { - private val usedTypeParameters: HashSet? = if (freeParameters.isNotEmpty()) HashSet() else null + private val usedTypeParameters: HashSet? + public val freeParameters: Set ;{ - usedTypeParameters?.addUsedTypeParameters(type) + if (freeParameters.isNotEmpty()) { + usedTypeParameters = HashSet() + usedTypeParameters!!.addUsedTypeParameters(type) + this.freeParameters = freeParameters.filter { it in usedTypeParameters }.toSet() + } + else { + usedTypeParameters = null + this.freeParameters = setOf() + } } + override fun equals(other: Any?) = other is FuzzyType && other.type == type && other.freeParameters == freeParameters + + override fun hashCode() = type.hashCode() + private fun MutableSet.addUsedTypeParameters(type: JetType) { addIfNotNull(type.getConstructor().getDeclarationDescriptor() as? TypeParameterDescriptor) @@ -90,9 +103,7 @@ data class FuzzyType( val constraintSystem = ConstraintSystemImpl() val typeVariables = LinkedHashMap() for (typeParameter in freeParameters) { - if (typeParameter in usedTypeParameters) { - typeVariables[typeParameter] = Variance.INVARIANT - } + typeVariables[typeParameter] = Variance.INVARIANT } constraintSystem.registerTypeVariables(typeVariables)