From 0056ac5f5a78f3f7151775ed622dbcf3f5a53ac2 Mon Sep 17 00:00:00 2001 From: "Denis.Zharkov" Date: Tue, 28 Mar 2023 13:32:50 +0200 Subject: [PATCH] K2: Clarify extractLambdaInfo contracts from its single usage Currently, it's only been called once extractLambdaInfoFromFunctionType returned null --- .../kotlin/fir/resolve/inference/InferenceUtils.kt | 3 +++ .../kotlin/fir/resolve/inference/PostponedArguments.kt | 10 ++++------ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/InferenceUtils.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/InferenceUtils.kt index 425725e9ff7..3bd8ab07166 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/InferenceUtils.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/InferenceUtils.kt @@ -13,6 +13,9 @@ import org.jetbrains.kotlin.fir.resolve.BodyResolveComponents import org.jetbrains.kotlin.fir.resolve.calls.Candidate import org.jetbrains.kotlin.fir.types.* +/** + * @return null if and only if expectedType is not function type (or flexible type with function type as bound) + */ fun extractLambdaInfoFromFunctionType( expectedType: ConeKotlinType?, expectedTypeRef: FirTypeRef?, diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/PostponedArguments.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/PostponedArguments.kt index c874b7f0e24..cbb85f689ab 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/PostponedArguments.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/PostponedArguments.kt @@ -22,7 +22,6 @@ import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemBuilder import org.jetbrains.kotlin.resolve.calls.inference.addSubtypeConstraintIfCompatible import org.jetbrains.kotlin.resolve.calls.inference.model.ConstraintKind import org.jetbrains.kotlin.types.model.typeConstructor -import org.jetbrains.kotlin.utils.addToStdlib.runIf fun Candidate.preprocessLambdaArgument( csBuilder: ConstraintSystemBuilder, @@ -110,15 +109,14 @@ private fun extractLambdaInfo( session: FirSession, candidate: Candidate? ): ResolvedLambdaAtom { - val expectedFunctionKind = expectedType?.lowerBoundIfFlexible()?.functionTypeKind(session) - val isFunctionSupertype = expectedFunctionKind != null - + require(expectedType?.lowerBoundIfFlexible()?.functionTypeKind(session) == null) { + "Currently, we only extract lambda info from its shape when expected type is not function, but $expectedType" + } val typeVariable = ConeTypeVariableForLambdaReturnType(argument, "_L") val receiverType = argument.receiverType val returnType = argument.returnType - ?: runIf(isFunctionSupertype) { (expectedType?.typeArguments?.singleOrNull() as? ConeKotlinTypeProjection)?.type } ?: typeVariable.defaultType val nothingType = session.builtinTypes.nothingType.type @@ -136,7 +134,7 @@ private fun extractLambdaInfo( return ResolvedLambdaAtom( argument, expectedType, - expectedFunctionKind, + expectedFunctionTypeKind = null, receiverType, contextReceivers, parameters,