[FIR] Don't set lambda parameter type to Nothing by default
... when the expected type is not a function type. Instead set it to a new type variable. This fixes a bunch of false negative CANNOT_INFER_PARAMETER_TYPE. #KT-59882 Fixed
This commit is contained in:
committed by
Space Team
parent
9857bdc891
commit
c3c2f6f90a
+1
-2
@@ -108,8 +108,7 @@ object ConeConstraintSystemUtilContext : ConstraintSystemUtilContext {
|
||||
index: Int
|
||||
): TypeVariableMarker {
|
||||
return ConeTypeVariableForLambdaParameterType(
|
||||
PostponedArgumentInputTypesResolver.TYPE_VARIABLE_NAME_PREFIX_FOR_LAMBDA_PARAMETER_TYPE + index,
|
||||
index
|
||||
PostponedArgumentInputTypesResolver.TYPE_VARIABLE_NAME_PREFIX_FOR_LAMBDA_PARAMETER_TYPE + index
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
+11
-9
@@ -23,6 +23,7 @@ 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,
|
||||
@@ -120,17 +121,18 @@ private fun extractLambdaInfo(
|
||||
argument.returnType
|
||||
?: typeVariable.defaultType
|
||||
|
||||
val defaultType = when (candidate?.symbol?.origin) {
|
||||
FirDeclarationOrigin.DynamicScope -> ConeDynamicType.create(session)
|
||||
else -> session.builtinTypes.nothingType.type
|
||||
val defaultType = runIf(candidate?.symbol?.origin == FirDeclarationOrigin.DynamicScope) { ConeDynamicType.create(session) }
|
||||
|
||||
val parameters = argument.valueParameters.mapIndexed { i, it ->
|
||||
it.returnTypeRef.coneTypeSafe<ConeKotlinType>()
|
||||
?: defaultType
|
||||
?: ConeTypeVariableForLambdaParameterType("_P$i").apply { csBuilder.registerVariable(this) }.defaultType
|
||||
}
|
||||
|
||||
val parameters = argument.valueParameters.map {
|
||||
it.returnTypeRef.coneTypeSafe<ConeKotlinType>() ?: defaultType
|
||||
}
|
||||
|
||||
val contextReceivers = argument.contextReceivers.map {
|
||||
it.typeRef.coneTypeSafe<ConeKotlinType>() ?: defaultType
|
||||
val contextReceivers = argument.contextReceivers.mapIndexed { i, it ->
|
||||
it.typeRef.coneTypeSafe<ConeKotlinType>()
|
||||
?: defaultType
|
||||
?: ConeTypeVariableForLambdaParameterType("_C$i").apply { csBuilder.registerVariable(this) }.defaultType
|
||||
}
|
||||
|
||||
val newTypeVariableUsed = returnType == typeVariable.defaultType
|
||||
|
||||
Reference in New Issue
Block a user