[NI] Don't forget to update receivers for builder-inference

This commit is contained in:
Mikhail Zarechenskiy
2020-01-28 10:26:14 +03:00
committed by Georgy Bronnikov
parent 97abc872b2
commit 678c74b17f
@@ -39,6 +39,7 @@ import org.jetbrains.kotlin.resolve.calls.util.CallMaker
import org.jetbrains.kotlin.resolve.checkers.MissingDependencySupertypeChecker import org.jetbrains.kotlin.resolve.checkers.MissingDependencySupertypeChecker
import org.jetbrains.kotlin.resolve.deprecation.DeprecationResolver import org.jetbrains.kotlin.resolve.deprecation.DeprecationResolver
import org.jetbrains.kotlin.resolve.scopes.receivers.TransientReceiver import org.jetbrains.kotlin.resolve.scopes.receivers.TransientReceiver
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
import org.jetbrains.kotlin.types.* import org.jetbrains.kotlin.types.*
import org.jetbrains.kotlin.types.expressions.DoubleColonExpressionResolver import org.jetbrains.kotlin.types.expressions.DoubleColonExpressionResolver
import org.jetbrains.kotlin.types.expressions.ExpressionTypingServices import org.jetbrains.kotlin.types.expressions.ExpressionTypingServices
@@ -314,15 +315,18 @@ class ResolvedAtomCompleter(
else -> null else -> null
} }
val explicitReceiver = explicitCallableReceiver?.receiver val explicitReceiver = explicitCallableReceiver?.receiver?.receiverValue?.updateReceiverValue(resultSubstitutor)
val psiCall = CallMaker.makeCall(reference, explicitReceiver?.receiverValue, null, reference, emptyList()) val psiCall = CallMaker.makeCall(reference, explicitReceiver, null, reference, emptyList())
val tracing = TracingStrategyImpl.create(reference, psiCall) val tracing = TracingStrategyImpl.create(reference, psiCall)
val temporaryTrace = TemporaryBindingTrace.create(topLevelTrace, "callable reference fake call") val temporaryTrace = TemporaryBindingTrace.create(topLevelTrace, "callable reference fake call")
val dispatchReceiver = callableCandidate.dispatchReceiver?.receiver?.receiverValue?.updateReceiverValue(resultSubstitutor)
val extensionReceiver = callableCandidate.extensionReceiver?.receiver?.receiverValue?.updateReceiverValue(resultSubstitutor)
val resolvedCall = ResolvedCallImpl( val resolvedCall = ResolvedCallImpl(
psiCall, callableCandidate.candidate, callableCandidate.dispatchReceiver?.receiver?.receiverValue, psiCall, callableCandidate.candidate, dispatchReceiver,
callableCandidate.extensionReceiver?.receiver?.receiverValue, callableCandidate.explicitReceiverKind, extensionReceiver, callableCandidate.explicitReceiverKind,
null, temporaryTrace, tracing, MutableDataFlowInfoForArguments.WithoutArgumentsCheck(DataFlowInfo.EMPTY) null, temporaryTrace, tracing, MutableDataFlowInfoForArguments.WithoutArgumentsCheck(DataFlowInfo.EMPTY)
) )
resolvedCall.setResultingSubstitutor(resultSubstitutor) resolvedCall.setResultingSubstitutor(resultSubstitutor)
@@ -364,6 +368,11 @@ class ResolvedAtomCompleter(
kotlinToResolvedCallTransformer.runCallCheckers(resolvedCall, topLevelCallCheckerContext) kotlinToResolvedCallTransformer.runCallCheckers(resolvedCall, topLevelCallCheckerContext)
} }
private fun ReceiverValue.updateReceiverValue(substitutor: TypeSubstitutor): ReceiverValue {
val newType = substitutor.safeSubstitute(type, Variance.INVARIANT)
return if (type != newType) replaceType(newType) else this
}
private fun recordArgumentAdaptationForCallableReference( private fun recordArgumentAdaptationForCallableReference(
resolvedCall: ResolvedCallImpl<CallableDescriptor>, resolvedCall: ResolvedCallImpl<CallableDescriptor>,
callableReferenceAdaptation: CallableReferenceAdaptation? callableReferenceAdaptation: CallableReferenceAdaptation?