diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ResolutionParts.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ResolutionParts.kt index 84d6a19fbec..fcf4cbd7f82 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ResolutionParts.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ResolutionParts.kt @@ -195,22 +195,16 @@ internal object CreateFreshVariablesSubstitutor : ResolutionPart() { internal object PostponedVariablesInitializerResolutionPart : ResolutionPart() { override fun KotlinResolutionCandidate.process(workIndex: Int) { - // smartset! - val typesForCoroutineCall = resolvedCall.argumentToCandidateParameter - .filter { (argument, parameter) -> callComponents.statelessCallbacks.isCoroutineCall(argument, parameter) } - .mapNotNull { it.value.type.getReceiverTypeFromFunctionType() } + for ((argument, parameter) in resolvedCall.argumentToCandidateParameter) { + if (!callComponents.statelessCallbacks.isCoroutineCall(argument, parameter)) continue + val receiverType = parameter.type.getReceiverTypeFromFunctionType() ?: continue - if (typesForCoroutineCall.isEmpty()) return - - for (freshVariable in resolvedCall.substitutor.freshVariables) { - val isPostponedVariable = typesForCoroutineCall.any { typeForCoroutineCall -> - typeForCoroutineCall.contains { it.constructor == freshVariable.originalTypeParameter.typeConstructor } + for (freshVariable in resolvedCall.substitutor.freshVariables) { + if (csBuilder.isPostponedTypeVariable(freshVariable)) continue + if (receiverType.contains { it.constructor == freshVariable.originalTypeParameter.typeConstructor }) { + csBuilder.markPostponedVariable(freshVariable) + } } - - if (isPostponedVariable) { - csBuilder.markPostponedVariable(freshVariable) - } - } } } diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/ConstraintSystemBuilder.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/ConstraintSystemBuilder.kt index 5a0d7612f81..545a240ded8 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/ConstraintSystemBuilder.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/ConstraintSystemBuilder.kt @@ -38,6 +38,7 @@ interface ConstraintSystemOperation { fun isProperType(type: UnwrappedType): Boolean fun isTypeVariable(type: UnwrappedType): Boolean + fun isPostponedTypeVariable(typeVariable: NewTypeVariable): Boolean fun getProperSuperTypeConstructors(type: UnwrappedType): List } diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/model/NewConstraintSystemImpl.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/model/NewConstraintSystemImpl.kt index 1619c3bc146..6ca035b69ed 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/model/NewConstraintSystemImpl.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/model/NewConstraintSystemImpl.kt @@ -188,6 +188,11 @@ class NewConstraintSystemImpl( return notFixedTypeVariables.containsKey(type.constructor) } + override fun isPostponedTypeVariable(typeVariable: NewTypeVariable): Boolean { + checkState(State.BUILDING, State.COMPLETION, State.TRANSACTION) + return typeVariable in postponedTypeVariables + } + // ConstraintInjector.Context override val allTypeVariables: Map get() {