[FIR] Don't perform suspend conversion for anonymous functions
^KT-58329 Fixed
This commit is contained in:
committed by
Space Team
parent
f6f85eeb88
commit
cc6c378b68
@@ -5,13 +5,16 @@
|
||||
|
||||
package org.jetbrains.kotlin.fir.resolve.inference
|
||||
|
||||
import org.jetbrains.kotlin.builtins.functions.FunctionTypeKind
|
||||
import org.jetbrains.kotlin.fir.declarations.FirAnonymousFunction
|
||||
import org.jetbrains.kotlin.fir.declarations.utils.isSuspend
|
||||
import org.jetbrains.kotlin.fir.diagnostics.ConeCannotInferValueParameterType
|
||||
import org.jetbrains.kotlin.fir.expressions.FirReturnExpression
|
||||
import org.jetbrains.kotlin.fir.expressions.impl.FirUnitExpression
|
||||
import org.jetbrains.kotlin.fir.resolve.BodyResolveComponents
|
||||
import org.jetbrains.kotlin.fir.resolve.calls.Candidate
|
||||
import org.jetbrains.kotlin.fir.types.*
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.runIf
|
||||
|
||||
/**
|
||||
* @return null if and only if expectedType is not function type (or flexible type with function type as bound)
|
||||
@@ -39,7 +42,13 @@ fun extractLambdaInfoFromFunctionType(
|
||||
)
|
||||
}
|
||||
val expectedFunctionKind = expectedType.functionTypeKind(session) ?: return null
|
||||
|
||||
val actualFunctionKind = session.functionTypeService.extractSingleSpecialKindForFunction(argument.symbol)
|
||||
?: runIf(!argument.isLambda) {
|
||||
// There is no function -> suspend function conversions for non-lambda anonymous functions
|
||||
// If function is suspend then functionTypeService will return SuspendFunction kind
|
||||
FunctionTypeKind.Function
|
||||
}
|
||||
|
||||
val singleStatement = argument.body?.statements?.singleOrNull() as? FirReturnExpression
|
||||
if (argument.returnType == null && singleStatement != null &&
|
||||
|
||||
+3
-3
@@ -7,7 +7,7 @@ fun fail2(c: () -> Unit) {}
|
||||
fun success1(c: suspend () -> Unit) {}
|
||||
|
||||
fun test1() {
|
||||
fail1(fun () {})
|
||||
fail1(<!ARGUMENT_TYPE_MISMATCH!>fun () {}<!>)
|
||||
fun fail2(c: suspend () -> Unit) {}
|
||||
fail2(fun () {})
|
||||
fun success1(c: () -> Unit) {}
|
||||
@@ -21,9 +21,9 @@ suspend fun fail4(c: () -> Unit) {}
|
||||
suspend fun success2(c: suspend () -> Unit) {}
|
||||
|
||||
suspend fun test2() {
|
||||
fail3(fun () {})
|
||||
fail3(<!ARGUMENT_TYPE_MISMATCH!>fun () {}<!>)
|
||||
fun fail4(c: suspend () -> Unit) {}
|
||||
fail4(fun () {})
|
||||
fun success2(c: () -> Unit) {}
|
||||
success2(fun() {})
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
+2
-2
@@ -1,7 +1,7 @@
|
||||
typealias SuspendFn = suspend () -> Unit
|
||||
|
||||
val test1f: suspend () -> Unit = fun () {}
|
||||
val test2f: suspend Any.() -> Unit = fun Any.() {}
|
||||
val test1f: suspend () -> Unit = <!INITIALIZER_TYPE_MISMATCH!>fun () {}<!>
|
||||
val test2f: suspend Any.() -> Unit = <!INITIALIZER_TYPE_MISMATCH!>fun Any.() {}<!>
|
||||
|
||||
// This is a bug in the old inference and should be fixed in new inference
|
||||
// see "Fix anonymous function literals handling in type checker" for more details
|
||||
|
||||
Reference in New Issue
Block a user