Fix SAM conversion when lambda is the last expression of another lambda
#KT-39691 Fixed
This commit is contained in:
+17
@@ -45,12 +45,29 @@ object SamTypeConversions : ParameterTypeConversion {
|
||||
|
||||
override fun conversionIsNeededBeforeSubtypingCheck(argument: KotlinCallArgument): Boolean {
|
||||
return when (argument) {
|
||||
is SubKotlinCallArgument -> {
|
||||
val stableType = argument.receiver.stableType
|
||||
hasNonAnalyzedLambdaAsReturnType(argument.callResult.subResolvedAtoms, stableType)
|
||||
}
|
||||
is SimpleKotlinCallArgument -> argument.receiver.stableType.isFunctionType
|
||||
is LambdaKotlinCallArgument, is CallableReferenceKotlinCallArgument -> true
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
|
||||
private fun hasNonAnalyzedLambdaAsReturnType(subResolvedAtoms: List<ResolvedAtom>?, type: UnwrappedType): Boolean {
|
||||
subResolvedAtoms?.forEach {
|
||||
if (it is LambdaWithTypeVariableAsExpectedTypeAtom) {
|
||||
if (it.expectedType.constructor == type.constructor) return true
|
||||
}
|
||||
|
||||
val hasNonAnalyzedLambda = hasNonAnalyzedLambdaAsReturnType(it.subResolvedAtoms, type)
|
||||
if (hasNonAnalyzedLambda) return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
override fun conversionIsNeededAfterSubtypingCheck(argument: KotlinCallArgument): Boolean {
|
||||
return argument is SimpleKotlinCallArgument && argument.receiver.stableType.isFunctionTypeOrSubtype
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user