K2: Clarify extractLambdaInfo contracts from its single usage
Currently, it's only been called once extractLambdaInfoFromFunctionType returned null
This commit is contained in:
committed by
Space Team
parent
65d781758c
commit
0056ac5f5a
@@ -13,6 +13,9 @@ import org.jetbrains.kotlin.fir.resolve.BodyResolveComponents
|
|||||||
import org.jetbrains.kotlin.fir.resolve.calls.Candidate
|
import org.jetbrains.kotlin.fir.resolve.calls.Candidate
|
||||||
import org.jetbrains.kotlin.fir.types.*
|
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(
|
fun extractLambdaInfoFromFunctionType(
|
||||||
expectedType: ConeKotlinType?,
|
expectedType: ConeKotlinType?,
|
||||||
expectedTypeRef: FirTypeRef?,
|
expectedTypeRef: FirTypeRef?,
|
||||||
|
|||||||
+4
-6
@@ -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.addSubtypeConstraintIfCompatible
|
||||||
import org.jetbrains.kotlin.resolve.calls.inference.model.ConstraintKind
|
import org.jetbrains.kotlin.resolve.calls.inference.model.ConstraintKind
|
||||||
import org.jetbrains.kotlin.types.model.typeConstructor
|
import org.jetbrains.kotlin.types.model.typeConstructor
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.runIf
|
|
||||||
|
|
||||||
fun Candidate.preprocessLambdaArgument(
|
fun Candidate.preprocessLambdaArgument(
|
||||||
csBuilder: ConstraintSystemBuilder,
|
csBuilder: ConstraintSystemBuilder,
|
||||||
@@ -110,15 +109,14 @@ private fun extractLambdaInfo(
|
|||||||
session: FirSession,
|
session: FirSession,
|
||||||
candidate: Candidate?
|
candidate: Candidate?
|
||||||
): ResolvedLambdaAtom {
|
): ResolvedLambdaAtom {
|
||||||
val expectedFunctionKind = expectedType?.lowerBoundIfFlexible()?.functionTypeKind(session)
|
require(expectedType?.lowerBoundIfFlexible()?.functionTypeKind(session) == null) {
|
||||||
val isFunctionSupertype = expectedFunctionKind != null
|
"Currently, we only extract lambda info from its shape when expected type is not function, but $expectedType"
|
||||||
|
}
|
||||||
val typeVariable = ConeTypeVariableForLambdaReturnType(argument, "_L")
|
val typeVariable = ConeTypeVariableForLambdaReturnType(argument, "_L")
|
||||||
|
|
||||||
val receiverType = argument.receiverType
|
val receiverType = argument.receiverType
|
||||||
val returnType =
|
val returnType =
|
||||||
argument.returnType
|
argument.returnType
|
||||||
?: runIf(isFunctionSupertype) { (expectedType?.typeArguments?.singleOrNull() as? ConeKotlinTypeProjection)?.type }
|
|
||||||
?: typeVariable.defaultType
|
?: typeVariable.defaultType
|
||||||
|
|
||||||
val nothingType = session.builtinTypes.nothingType.type
|
val nothingType = session.builtinTypes.nothingType.type
|
||||||
@@ -136,7 +134,7 @@ private fun extractLambdaInfo(
|
|||||||
return ResolvedLambdaAtom(
|
return ResolvedLambdaAtom(
|
||||||
argument,
|
argument,
|
||||||
expectedType,
|
expectedType,
|
||||||
expectedFunctionKind,
|
expectedFunctionTypeKind = null,
|
||||||
receiverType,
|
receiverType,
|
||||||
contextReceivers,
|
contextReceivers,
|
||||||
parameters,
|
parameters,
|
||||||
|
|||||||
Reference in New Issue
Block a user