diff --git a/core/descriptors/src/org/jetbrains/kotlin/resolve/calls/inference/ConstraintSystem.kt b/core/descriptors/src/org/jetbrains/kotlin/resolve/calls/inference/ConstraintSystem.kt index 3499c16000b..c0b917adf88 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/resolve/calls/inference/ConstraintSystem.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/resolve/calls/inference/ConstraintSystem.kt @@ -82,4 +82,9 @@ public interface ConstraintSystem { * If there is no information for type parameter, returns type projection for DONT_CARE type. */ public fun getCurrentSubstitutor(): TypeSubstitutor + + /** + * Returns a substitution only for type parameters that have result values, otherwise returns a type parameter itself. + */ + public fun getPartialSubstitutor(): TypeSubstitutor } diff --git a/core/descriptors/src/org/jetbrains/kotlin/resolve/calls/inference/ConstraintSystemImpl.kt b/core/descriptors/src/org/jetbrains/kotlin/resolve/calls/inference/ConstraintSystemImpl.kt index e86238b0d03..a1a6d0e5a7d 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/resolve/calls/inference/ConstraintSystemImpl.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/resolve/calls/inference/ConstraintSystemImpl.kt @@ -108,16 +108,17 @@ public class ConstraintSystemImpl : ConstraintSystem { substituteOriginal: Boolean ): Map { val substitutionContext = HashMap() - for ((typeParameter, typeBounds) in typeParameterBounds) { + for ((variable, typeBounds) in typeParameterBounds) { val typeProjection: TypeProjection val value = typeBounds.value + val typeParameter = if (substituteOriginal) variablesToOriginal[variable]!! else variable if (value != null && !TypeUtils.containsSpecialType(value, DONT_CARE)) { typeProjection = TypeProjectionImpl(value) } else { typeProjection = getDefaultTypeProjection(typeParameter) } - substitutionContext.put(if (substituteOriginal) variablesToOriginal[typeParameter]!! else typeParameter, typeProjection) + substitutionContext.put(typeParameter, typeProjection) } return substitutionContext } @@ -449,6 +450,9 @@ public class ConstraintSystemImpl : ConstraintSystem { override fun getCurrentSubstitutor() = getSubstitutor(substituteOriginal = true) { TypeProjectionImpl(TypeUtils.DONT_CARE) } + override fun getPartialSubstitutor() = + getSubstitutor(substituteOriginal = true) { TypeProjectionImpl(it.correspondingType) } + private fun getSubstitutor(substituteOriginal: Boolean, getDefaultValue: (TypeParameterDescriptor) -> TypeProjection) = replaceUninferredBy(getDefaultValue, substituteOriginal).setApproximateCapturedTypes()