K2 Inference: Remove overloading of FirBuilderInferenceSession.substitute

There are two overloads of substitute function
in the FirBuilderInferenceSession.
In fact, it has very different usage and semantics.

Relates to KT-64028
This commit is contained in:
Simon Ogorodnik
2023-12-04 12:08:53 +01:00
committed by Space Team
parent 1f989dce64
commit 8bf7c30407
@@ -280,7 +280,7 @@ class FirBuilderInferenceSession(
fixedTypeVariables: Map<TypeConstructorMarker, KotlinTypeMarker>, fixedTypeVariables: Map<TypeConstructorMarker, KotlinTypeMarker>,
): Boolean { ): Boolean {
val substitutedConstraintWith = val substitutedConstraintWith =
initialConstraint.substitute(callSubstitutor).substitute(nonFixedToVariablesSubstitutor, fixedTypeVariables) initialConstraint.substitute(callSubstitutor).substituteNonFixedToVariables(nonFixedToVariablesSubstitutor, fixedTypeVariables)
// TODO(KT-64031): Invalid naming, it doesn't make sense in case of equality constraints // TODO(KT-64031): Invalid naming, it doesn't make sense in case of equality constraints
val lower = substitutedConstraintWith.a val lower = substitutedConstraintWith.a
@@ -320,8 +320,8 @@ class FirBuilderInferenceSession(
) )
} }
private fun InitialConstraint.substitute( private fun InitialConstraint.substituteNonFixedToVariables(
substitutor: ConeSubstitutor, nonFixedToVariablesSubstitutor: ConeSubstitutor,
fixedTypeVariables: Map<TypeConstructorMarker, KotlinTypeMarker> fixedTypeVariables: Map<TypeConstructorMarker, KotlinTypeMarker>
): InitialConstraint { ): InitialConstraint {
require(constraintKind != ConstraintKind.LOWER) require(constraintKind != ConstraintKind.LOWER)
@@ -339,7 +339,7 @@ class FirBuilderInferenceSession(
// substitutedLowerType = C<CapturedType(out W)_1> // substitutedLowerType = C<CapturedType(out W)_1>
// substitutedUpperType = D<CapturedType(out W)_1> // substitutedUpperType = D<CapturedType(out W)_1>
val substitutedCommonCapType = commonCapTypes.associate { val substitutedCommonCapType = commonCapTypes.associate {
it.constructor to substitutor.substituteOrSelf(it) it.constructor to nonFixedToVariablesSubstitutor.substituteOrSelf(it)
} }
val capTypesSubstitutor = object : AbstractConeSubstitutor(resolutionContext.typeContext) { val capTypesSubstitutor = object : AbstractConeSubstitutor(resolutionContext.typeContext) {
@@ -350,11 +350,11 @@ class FirBuilderInferenceSession(
} }
// TODO(KT-64031): invalid naming. It doesn't make sense in case of equality constraints // TODO(KT-64031): invalid naming. It doesn't make sense in case of equality constraints
val substitutedLowerType = substitutor.safeSubstitute( val substitutedLowerType = nonFixedToVariablesSubstitutor.safeSubstitute(
resolutionContext.typeContext, resolutionContext.typeContext,
capTypesSubstitutor.safeSubstitute(resolutionContext.typeContext, this.a) capTypesSubstitutor.safeSubstitute(resolutionContext.typeContext, this.a)
) )
val substitutedUpperType = substitutor.safeSubstitute( val substitutedUpperType = nonFixedToVariablesSubstitutor.safeSubstitute(
resolutionContext.typeContext, resolutionContext.typeContext,
capTypesSubstitutor.safeSubstitute(resolutionContext.typeContext, this.b) capTypesSubstitutor.safeSubstitute(resolutionContext.typeContext, this.b)
) )