Inference. Remove chain inference stubs from fixed variables constraints

This commit is contained in:
Simon Ogorodnik
2022-01-15 12:24:12 +03:00
parent d754c60c32
commit 83ff0946fe
2 changed files with 6 additions and 6 deletions
@@ -12,7 +12,6 @@ import org.jetbrains.kotlin.types.TypeApproximatorConfiguration
import org.jetbrains.kotlin.types.model.*
import org.jetbrains.kotlin.utils.SmartList
import org.jetbrains.kotlin.utils.SmartSet
import org.jetbrains.kotlin.utils.addIfNotNull
import java.util.*
// todo problem: intersection types in constrains: A <: Number, B <: Inv<A & Any> =>? B <: Inv<out Number & Any>
@@ -53,7 +52,7 @@ class ConstraintIncorporator(
}
private fun Context.areThereRecursiveConstraints(typeVariable: TypeVariableMarker, constraint: Constraint) =
constraint.type.contains { it.typeConstructor() == typeVariable.freshTypeConstructor() }
constraint.type.contains { it.typeConstructor().unwrapStubTypeVariableConstructor() == typeVariable.freshTypeConstructor() }
// A <:(=) \alpha <:(=) B => A <: B
private fun Context.directWithVariable(
@@ -259,8 +258,9 @@ class ConstraintIncorporator(
}
private fun Context.getNestedTypeVariables(type: KotlinTypeMarker): List<TypeVariableMarker> =
getNestedArguments(type).mapNotNullTo(SmartList()) { getTypeVariable(it.getType().typeConstructor()) }
getNestedArguments(type).mapNotNullTo(SmartList()) {
getTypeVariable(it.getType().typeConstructor().unwrapStubTypeVariableConstructor())
}
private fun KotlinTypeMarker.substitute(c: Context, typeVariable: TypeVariableMarker, value: KotlinTypeMarker): KotlinTypeMarker {
val substitutor = c.typeSubstitutorByTypeConstructor(mapOf(typeVariable.freshTypeConstructor(c) to value))
@@ -207,11 +207,11 @@ fun TypeSystemInferenceExtensionContext.extractProjectionsForAllCapturedTypes(ba
}
fun TypeSystemInferenceExtensionContext.containsTypeVariable(type: KotlinTypeMarker, typeVariable: TypeConstructorMarker): Boolean {
if (type.contains { it.typeConstructor() == typeVariable }) return true
if (type.contains { it.typeConstructor().unwrapStubTypeVariableConstructor() == typeVariable }) return true
val typeProjections = extractProjectionsForAllCapturedTypes(type)
return typeProjections.any { typeProjectionsType ->
typeProjectionsType.contains { it.typeConstructor() == typeVariable }
typeProjectionsType.contains { it.typeConstructor().unwrapStubTypeVariableConstructor() == typeVariable }
}
}