Reuse revised variables during lambda analysis against type variables
#KT-41400 Fixed
This commit is contained in:
+7
-4
@@ -8,10 +8,7 @@ package org.jetbrains.kotlin.resolve.calls.inference
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.model.ConstraintKind
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.model.ConstraintPosition
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.model.ConstraintStorage
|
||||
import org.jetbrains.kotlin.types.model.KotlinTypeMarker
|
||||
import org.jetbrains.kotlin.types.model.TypeConstructorMarker
|
||||
import org.jetbrains.kotlin.types.model.TypeSubstitutorMarker
|
||||
import org.jetbrains.kotlin.types.model.TypeVariableMarker
|
||||
import org.jetbrains.kotlin.types.model.*
|
||||
|
||||
interface ConstraintSystemOperation {
|
||||
val hasContradiction: Boolean
|
||||
@@ -20,6 +17,12 @@ interface ConstraintSystemOperation {
|
||||
fun unmarkPostponedVariable(variable: TypeVariableMarker)
|
||||
fun removePostponedVariables()
|
||||
|
||||
fun getRevisedVariableForParameter(expectedType: TypeVariableMarker, index: Int): TypeVariableMarker?
|
||||
fun getRevisedVariableForReturnType(expectedType: TypeVariableMarker): TypeVariableMarker?
|
||||
|
||||
fun putRevisedVariableForParameter(expectedType: TypeVariableMarker, index: Int, newVariable: TypeVariableMarker)
|
||||
fun putRevisedVariableForReturnType(expectedType: TypeVariableMarker, newVariable: TypeVariableMarker)
|
||||
|
||||
fun addSubtypeConstraint(lowerType: KotlinTypeMarker, upperType: KotlinTypeMarker, position: ConstraintPosition)
|
||||
fun addEqualityConstraint(a: KotlinTypeMarker, b: KotlinTypeMarker, position: ConstraintPosition)
|
||||
|
||||
|
||||
+5
-4
@@ -6,10 +6,7 @@
|
||||
package org.jetbrains.kotlin.resolve.calls.inference.model
|
||||
|
||||
import org.jetbrains.kotlin.types.AbstractTypeChecker
|
||||
import org.jetbrains.kotlin.types.model.KotlinTypeMarker
|
||||
import org.jetbrains.kotlin.types.model.TypeCheckerProviderContext
|
||||
import org.jetbrains.kotlin.types.model.TypeConstructorMarker
|
||||
import org.jetbrains.kotlin.types.model.TypeVariableMarker
|
||||
import org.jetbrains.kotlin.types.model.*
|
||||
|
||||
/**
|
||||
* Every type variable can be in the following states:
|
||||
@@ -42,6 +39,8 @@ interface ConstraintStorage {
|
||||
val hasContradiction: Boolean
|
||||
val fixedTypeVariables: Map<TypeConstructorMarker, KotlinTypeMarker>
|
||||
val postponedTypeVariables: List<TypeVariableMarker>
|
||||
val revisedVariablesForParameters: Map<Pair<TypeVariableMarker, Int>, TypeVariableMarker>
|
||||
val revisedReturnTypes: Map<TypeVariableMarker, TypeVariableMarker>
|
||||
|
||||
object Empty : ConstraintStorage {
|
||||
override val allTypeVariables: Map<TypeConstructorMarker, TypeVariableMarker> get() = emptyMap()
|
||||
@@ -52,6 +51,8 @@ interface ConstraintStorage {
|
||||
override val hasContradiction: Boolean get() = false
|
||||
override val fixedTypeVariables: Map<TypeConstructorMarker, KotlinTypeMarker> get() = emptyMap()
|
||||
override val postponedTypeVariables: List<TypeVariableMarker> get() = emptyList()
|
||||
override val revisedVariablesForParameters: Map<Pair<TypeVariableMarker, Int>, TypeVariableMarker> = emptyMap()
|
||||
override val revisedReturnTypes: Map<TypeVariableMarker, TypeVariableMarker> = emptyMap()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
@@ -202,4 +202,6 @@ internal class MutableConstraintStorage : ConstraintStorage {
|
||||
override val hasContradiction: Boolean get() = errors.any { !it.applicability.isSuccess }
|
||||
override val fixedTypeVariables: MutableMap<TypeConstructorMarker, KotlinTypeMarker> = LinkedHashMap()
|
||||
override val postponedTypeVariables: MutableList<TypeVariableMarker> = SmartList()
|
||||
override val revisedVariablesForParameters: MutableMap<Pair<TypeVariableMarker, Int>, TypeVariableMarker> = LinkedHashMap()
|
||||
override val revisedReturnTypes: MutableMap<TypeVariableMarker, TypeVariableMarker> = LinkedHashMap()
|
||||
}
|
||||
|
||||
+16
@@ -107,6 +107,22 @@ class NewConstraintSystemImpl(
|
||||
storage.postponedTypeVariables.clear()
|
||||
}
|
||||
|
||||
override fun getRevisedVariableForParameter(expectedType: TypeVariableMarker, index: Int): TypeVariableMarker? {
|
||||
return storage.revisedVariablesForParameters[expectedType to index]
|
||||
}
|
||||
|
||||
override fun getRevisedVariableForReturnType(expectedType: TypeVariableMarker): TypeVariableMarker? {
|
||||
return storage.revisedReturnTypes[expectedType]
|
||||
}
|
||||
|
||||
override fun putRevisedVariableForParameter(expectedType: TypeVariableMarker, index: Int, newVariable: TypeVariableMarker) {
|
||||
storage.revisedVariablesForParameters[expectedType to index] = newVariable
|
||||
}
|
||||
|
||||
override fun putRevisedVariableForReturnType(expectedType: TypeVariableMarker, newVariable: TypeVariableMarker) {
|
||||
storage.revisedReturnTypes[expectedType] = newVariable
|
||||
}
|
||||
|
||||
override fun addSubtypeConstraint(lowerType: KotlinTypeMarker, upperType: KotlinTypeMarker, position: ConstraintPosition) =
|
||||
constraintInjector.addInitialSubtypeConstraint(
|
||||
apply { checkState(State.BUILDING, State.COMPLETION, State.TRANSACTION) },
|
||||
|
||||
Reference in New Issue
Block a user