[NI] Use only receiver from coroutine call to mark postponed variable

This commit is contained in:
Mikhail Zarechenskiy
2018-04-25 12:26:48 +03:00
parent 59c4b9ad2f
commit e0ca3421ca
4 changed files with 21 additions and 10 deletions
@@ -16,6 +16,7 @@
package org.jetbrains.kotlin.resolve.calls.tower
import org.jetbrains.kotlin.builtins.getReceiverTypeFromFunctionType
import org.jetbrains.kotlin.descriptors.CallableDescriptor
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
@@ -31,6 +32,7 @@ import org.jetbrains.kotlin.resolve.calls.model.CallableReferenceKotlinCallArgum
import org.jetbrains.kotlin.resolve.calls.model.KotlinCall
import org.jetbrains.kotlin.resolve.calls.model.KotlinCallArgument
import org.jetbrains.kotlin.resolve.calls.model.SimpleKotlinCallArgument
import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
class KotlinResolutionStatelessCallbacksImpl(
@@ -12,6 +12,7 @@ import org.jetbrains.kotlin.resolve.calls.inference.model.NewTypeVariable
import org.jetbrains.kotlin.resolve.calls.model.*
import org.jetbrains.kotlin.resolve.calls.tower.ImplicitScopeTower
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValueWithSmartCastInfo
import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.types.NonFixedType
import org.jetbrains.kotlin.types.UnwrappedType
@@ -5,6 +5,7 @@
package org.jetbrains.kotlin.resolve.calls.components
import org.jetbrains.kotlin.builtins.getReceiverTypeFromFunctionType
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.resolve.calls.components.TypeArgumentsToParametersMapper.TypeArgumentsMapping.NoExplicitArguments
import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemOperation
@@ -192,17 +193,24 @@ internal object CreateFreshVariablesSubstitutor : ResolutionPart() {
}
}
internal object InferLaterInitializerResolutionPart : ResolutionPart() {
internal object PostponedVariablesInitializerResolutionPart : ResolutionPart() {
override fun KotlinResolutionCandidate.process(workIndex: Int) {
resolvedCall.argumentToCandidateParameter
val typesForCoroutineCall = resolvedCall.argumentToCandidateParameter
.filter { (argument, parameter) -> callComponents.statelessCallbacks.isCoroutineCall(argument, parameter) }
.flatMap { (_, parameter) ->
resolvedCall.substitutor.freshVariables.filter { variable ->
parameter.type.contains { it.constructor == variable.originalTypeParameter.typeConstructor }
}
.mapNotNull { it.value.type.getReceiverTypeFromFunctionType() }
if (typesForCoroutineCall.isEmpty()) return
for (freshVariable in resolvedCall.substitutor.freshVariables) {
val isPostponedVariable = typesForCoroutineCall.any { typeForCoroutineCall ->
typeForCoroutineCall.contains { it.constructor == freshVariable.originalTypeParameter.typeConstructor }
}
.distinct()
.forEach { csBuilder.markPostponedVariable(it) }
if (isPostponedVariable) {
csBuilder.markPostponedVariable(freshVariable)
}
}
}
}
@@ -192,7 +192,7 @@ enum class KotlinCallKind(vararg resolutionPart: ResolutionPart) {
CreateFreshVariablesSubstitutor,
CheckExplicitReceiverKindConsistency,
CheckReceivers,
InferLaterInitializerResolutionPart
PostponedVariablesInitializerResolutionPart
),
FUNCTION(
CheckInstantiationOfAbstractClass,
@@ -207,7 +207,7 @@ enum class KotlinCallKind(vararg resolutionPart: ResolutionPart) {
CheckReceivers,
CheckArguments,
CheckExternalArgument,
InferLaterInitializerResolutionPart
PostponedVariablesInitializerResolutionPart
),
INVOKE(*FUNCTION.resolutionSequence.toTypedArray()),
UNSUPPORTED();