[NI] Add common supertype for PSI lambda arguments
Also move initial dataFlowInfo to lambda arguments. As result, we can not store outer call for postpone call arguments
This commit is contained in:
-1
@@ -156,7 +156,6 @@ class CallableReferencesCandidateFactory(
|
||||
val compatibilityChecker: ((ConstraintSystemOperation) -> Unit) -> Unit,
|
||||
val expectedType: UnwrappedType?
|
||||
) : CandidateFactory<CallableReferenceCandidate> {
|
||||
private val position = ArgumentConstraintPosition(argument)
|
||||
|
||||
fun createCallableProcessor(explicitReceiver: DetailedReceiver?) =
|
||||
createCallableReferenceProcessor(outerCallContext.scopeTower, argument.rhsName, this, explicitReceiver)
|
||||
|
||||
-1
@@ -34,7 +34,6 @@ interface KotlinResolutionExternalPredicates {
|
||||
// This components hold state (trace). Work with this carefully.
|
||||
interface KotlinResolutionCallbacks {
|
||||
fun analyzeAndGetLambdaResultArguments(
|
||||
outerCall: KotlinCall,
|
||||
lambdaArgument: LambdaKotlinCallArgument,
|
||||
isSuspend: Boolean,
|
||||
receiverType: UnwrappedType?,
|
||||
|
||||
+1
-1
@@ -199,7 +199,7 @@ class KotlinCallCompleter(
|
||||
val parameters = lambda.parameters.map(::substitute)
|
||||
val expectedType = lambda.returnType.takeIf { c.canBeProper(it) }?.let(::substitute)
|
||||
lambda.analyzed = true
|
||||
lambda.resultArguments = resolutionCallbacks.analyzeAndGetLambdaResultArguments(lambda.outerCall, lambda.argument, lambda.isSuspend, receiver, parameters, expectedType)
|
||||
lambda.resultArguments = resolutionCallbacks.analyzeAndGetLambdaResultArguments(lambda.argument, lambda.isSuspend, receiver, parameters, expectedType)
|
||||
|
||||
for (resultLambdaArgument in lambda.resultArguments) {
|
||||
checkSimpleArgument(c.getBuilder(), resultLambdaArgument, lambda.returnType.let(::substitute))
|
||||
|
||||
+3
-7
@@ -17,7 +17,6 @@
|
||||
package org.jetbrains.kotlin.resolve.calls.components
|
||||
|
||||
import org.jetbrains.kotlin.builtins.*
|
||||
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemBuilder
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.model.ArgumentConstraintPosition
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.model.TypeVariableForLambdaReturnType
|
||||
@@ -26,14 +25,12 @@ import org.jetbrains.kotlin.types.UnwrappedType
|
||||
import org.jetbrains.kotlin.types.typeUtil.builtIns
|
||||
|
||||
fun createPostponedArgumentAndPerformInitialChecks(
|
||||
kotlinCall: KotlinCall,
|
||||
csBuilder: ConstraintSystemBuilder,
|
||||
argument: PostponableKotlinCallArgument,
|
||||
parameterDescriptor: ValueParameterDescriptor
|
||||
expectedType: UnwrappedType
|
||||
): KotlinCallDiagnostic? {
|
||||
val expectedType = argument.getExpectedType(parameterDescriptor)
|
||||
val (postponedArgument, diagnostic) = when (argument) {
|
||||
is LambdaKotlinCallArgument -> preprocessLambdaArgument(kotlinCall, csBuilder, argument, expectedType)
|
||||
is LambdaKotlinCallArgument -> preprocessLambdaArgument(csBuilder, argument, expectedType)
|
||||
is CallableReferenceKotlinCallArgument -> preprocessCallableReference(csBuilder, argument, expectedType)
|
||||
is CollectionLiteralKotlinCallArgument -> preprocessCollectionLiteralArgument(csBuilder, argument, expectedType)
|
||||
else -> unexpectedArgument(argument)
|
||||
@@ -45,7 +42,6 @@ fun createPostponedArgumentAndPerformInitialChecks(
|
||||
|
||||
// if expected type isn't function type, then may be it is Function<R>, Any or just `T`
|
||||
private fun preprocessLambdaArgument(
|
||||
kotlinCall: KotlinCall,
|
||||
csBuilder: ConstraintSystemBuilder,
|
||||
argument: LambdaKotlinCallArgument,
|
||||
expectedType: UnwrappedType
|
||||
@@ -84,7 +80,7 @@ private fun preprocessLambdaArgument(
|
||||
// what about case where expected type is type variable? In old TY such cases was not supported. => do nothing for now. todo design
|
||||
}
|
||||
|
||||
val resolvedArgument = PostponedLambdaArgument(kotlinCall, argument, isSuspend, receiverType, parameters, returnType)
|
||||
val resolvedArgument = PostponedLambdaArgument(argument, isSuspend, receiverType, parameters, returnType)
|
||||
|
||||
csBuilder.addSubtypeConstraint(resolvedArgument.type, expectedType, ArgumentConstraintPosition(argument))
|
||||
|
||||
|
||||
+3
-2
@@ -234,11 +234,12 @@ internal object CheckArguments : ResolutionPart {
|
||||
val resolvedCallArgument = argumentMappingByOriginal[parameterDescriptor.original] ?: continue
|
||||
for (argument in resolvedCallArgument.arguments) {
|
||||
|
||||
val expectedType = argument.getExpectedType(parameterDescriptor)
|
||||
val diagnostic = when (argument) {
|
||||
is SimpleKotlinCallArgument ->
|
||||
checkSimpleArgument(csBuilder, argument, argument.getExpectedType(parameterDescriptor))
|
||||
checkSimpleArgument(csBuilder, argument, expectedType)
|
||||
is PostponableKotlinCallArgument ->
|
||||
createPostponedArgumentAndPerformInitialChecks(kotlinCall, csBuilder, argument, parameterDescriptor)
|
||||
createPostponedArgumentAndPerformInitialChecks(csBuilder, argument, expectedType)
|
||||
else -> unexpectedArgument(argument)
|
||||
}
|
||||
diagnostics.addIfNotNull(diagnostic)
|
||||
|
||||
-1
@@ -30,7 +30,6 @@ sealed class PostponedKotlinCallArgument {
|
||||
}
|
||||
|
||||
class PostponedLambdaArgument(
|
||||
val outerCall: KotlinCall,
|
||||
override val argument: LambdaKotlinCallArgument,
|
||||
val isSuspend: Boolean,
|
||||
val receiver: UnwrappedType?,
|
||||
|
||||
Reference in New Issue
Block a user