FIR: Fix invalid INITIALIZER_TYPE_MISMATCH for suspend lambda
This commit is contained in:
+6
@@ -6425,6 +6425,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag
|
|||||||
runTest("compiler/testData/diagnostics/tests/coroutines/suspendInvokeWithReceiver.kt");
|
runTest("compiler/testData/diagnostics/tests/coroutines/suspendInvokeWithReceiver.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("suspendLambdaFromExpectedType.kt")
|
||||||
|
public void testSuspendLambdaFromExpectedType() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/coroutines/suspendLambdaFromExpectedType.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Nested
|
@Nested
|
||||||
@TestMetadata("compiler/testData/diagnostics/tests/coroutines/callableReference")
|
@TestMetadata("compiler/testData/diagnostics/tests/coroutines/callableReference")
|
||||||
@TestDataPath("$PROJECT_ROOT")
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
|
|||||||
+6
@@ -6425,6 +6425,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
|
|||||||
runTest("compiler/testData/diagnostics/tests/coroutines/suspendInvokeWithReceiver.kt");
|
runTest("compiler/testData/diagnostics/tests/coroutines/suspendInvokeWithReceiver.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("suspendLambdaFromExpectedType.kt")
|
||||||
|
public void testSuspendLambdaFromExpectedType() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/coroutines/suspendLambdaFromExpectedType.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Nested
|
@Nested
|
||||||
@TestMetadata("compiler/testData/diagnostics/tests/coroutines/callableReference")
|
@TestMetadata("compiler/testData/diagnostics/tests/coroutines/callableReference")
|
||||||
@TestDataPath("$PROJECT_ROOT")
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
|
|||||||
+6
@@ -6425,6 +6425,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac
|
|||||||
runTest("compiler/testData/diagnostics/tests/coroutines/suspendInvokeWithReceiver.kt");
|
runTest("compiler/testData/diagnostics/tests/coroutines/suspendInvokeWithReceiver.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("suspendLambdaFromExpectedType.kt")
|
||||||
|
public void testSuspendLambdaFromExpectedType() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/coroutines/suspendLambdaFromExpectedType.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Nested
|
@Nested
|
||||||
@TestMetadata("compiler/testData/diagnostics/tests/coroutines/callableReference")
|
@TestMetadata("compiler/testData/diagnostics/tests/coroutines/callableReference")
|
||||||
@TestDataPath("$PROJECT_ROOT")
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
|
|||||||
+7
-1
@@ -607,7 +607,10 @@ class FirCallCompletionResultsWriterTransformer(
|
|||||||
|
|
||||||
if (needUpdateLambdaType) {
|
if (needUpdateLambdaType) {
|
||||||
val resolvedTypeRef =
|
val resolvedTypeRef =
|
||||||
anonymousFunction.constructFunctionalTypeRef(isSuspend = expectedType?.isSuspendFunctionType(session) == true)
|
anonymousFunction.constructFunctionalTypeRef(
|
||||||
|
isSuspend = expectedType?.isSuspendFunctionType(session) == true ||
|
||||||
|
(expectedType == null && anonymousFunction.isSuspendFunctionType())
|
||||||
|
)
|
||||||
anonymousFunction.replaceTypeRef(resolvedTypeRef)
|
anonymousFunction.replaceTypeRef(resolvedTypeRef)
|
||||||
session.lookupTracker?.recordTypeResolveAsLookup(resolvedTypeRef, anonymousFunction.source, null)
|
session.lookupTracker?.recordTypeResolveAsLookup(resolvedTypeRef, anonymousFunction.source, null)
|
||||||
}
|
}
|
||||||
@@ -640,6 +643,9 @@ class FirCallCompletionResultsWriterTransformer(
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun FirAnonymousFunction.isSuspendFunctionType() =
|
||||||
|
typeRef.coneTypeSafe<ConeKotlinType>()?.isSuspendFunctionType(session) == true
|
||||||
|
|
||||||
private fun transformImplicitTypeRefInAnonymousFunction(
|
private fun transformImplicitTypeRefInAnonymousFunction(
|
||||||
anonymousFunction: FirAnonymousFunction
|
anonymousFunction: FirAnonymousFunction
|
||||||
): FirStatement {
|
): FirStatement {
|
||||||
|
|||||||
-1
@@ -2,7 +2,6 @@
|
|||||||
// WITH_COROUTINES
|
// WITH_COROUTINES
|
||||||
// NO_CHECK_LAMBDA_INLINING
|
// NO_CHECK_LAMBDA_INLINING
|
||||||
// WITH_RUNTIME
|
// WITH_RUNTIME
|
||||||
// IGNORE_BACKEND_FIR: JVM_IR
|
|
||||||
// FILE: inlined.kt
|
// FILE: inlined.kt
|
||||||
|
|
||||||
suspend inline fun crossinlineMe(crossinline c: suspend () -> Unit) {
|
suspend inline fun crossinlineMe(crossinline c: suspend () -> Unit) {
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
// WITH_COROUTINES
|
// WITH_COROUTINES
|
||||||
// NO_CHECK_LAMBDA_INLINING
|
// NO_CHECK_LAMBDA_INLINING
|
||||||
// WITH_RUNTIME
|
// WITH_RUNTIME
|
||||||
// IGNORE_BACKEND_FIR: JVM_IR
|
|
||||||
// FILE: inlined.kt
|
// FILE: inlined.kt
|
||||||
|
|
||||||
interface SuspendRunnable {
|
interface SuspendRunnable {
|
||||||
|
|||||||
-1
@@ -2,7 +2,6 @@
|
|||||||
// WITH_COROUTINES
|
// WITH_COROUTINES
|
||||||
// NO_CHECK_LAMBDA_INLINING
|
// NO_CHECK_LAMBDA_INLINING
|
||||||
// WITH_RUNTIME
|
// WITH_RUNTIME
|
||||||
// IGNORE_BACKEND_FIR: JVM_IR
|
|
||||||
// FILE: inlined.kt
|
// FILE: inlined.kt
|
||||||
|
|
||||||
interface SuspendRunnable {
|
interface SuspendRunnable {
|
||||||
|
|||||||
+10
@@ -0,0 +1,10 @@
|
|||||||
|
// FIR_IDENTICAL
|
||||||
|
// SKIP_TXT
|
||||||
|
|
||||||
|
fun <T> runBlocking(block: suspend () -> T): T = TODO()
|
||||||
|
|
||||||
|
fun foo() = runBlocking<Unit> {
|
||||||
|
val foo: suspend (String) -> Int = {
|
||||||
|
it.length
|
||||||
|
}
|
||||||
|
}
|
||||||
Generated
+6
@@ -6431,6 +6431,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
|||||||
runTest("compiler/testData/diagnostics/tests/coroutines/suspendInvokeWithReceiver.kt");
|
runTest("compiler/testData/diagnostics/tests/coroutines/suspendInvokeWithReceiver.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("suspendLambdaFromExpectedType.kt")
|
||||||
|
public void testSuspendLambdaFromExpectedType() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/coroutines/suspendLambdaFromExpectedType.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Nested
|
@Nested
|
||||||
@TestMetadata("compiler/testData/diagnostics/tests/coroutines/callableReference")
|
@TestMetadata("compiler/testData/diagnostics/tests/coroutines/callableReference")
|
||||||
@TestDataPath("$PROJECT_ROOT")
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
|
|||||||
Reference in New Issue
Block a user