FIR: Fix invalid INITIALIZER_TYPE_MISMATCH for suspend lambda

This commit is contained in:
Denis.Zharkov
2021-11-03 18:52:37 +03:00
committed by teamcity
parent 994040c91c
commit 65d7da122f
9 changed files with 41 additions and 4 deletions
@@ -6425,6 +6425,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag
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
@TestMetadata("compiler/testData/diagnostics/tests/coroutines/callableReference")
@TestDataPath("$PROJECT_ROOT")
@@ -6425,6 +6425,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
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
@TestMetadata("compiler/testData/diagnostics/tests/coroutines/callableReference")
@TestDataPath("$PROJECT_ROOT")
@@ -6425,6 +6425,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac
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
@TestMetadata("compiler/testData/diagnostics/tests/coroutines/callableReference")
@TestDataPath("$PROJECT_ROOT")
@@ -607,7 +607,10 @@ class FirCallCompletionResultsWriterTransformer(
if (needUpdateLambdaType) {
val resolvedTypeRef =
anonymousFunction.constructFunctionalTypeRef(isSuspend = expectedType?.isSuspendFunctionType(session) == true)
anonymousFunction.constructFunctionalTypeRef(
isSuspend = expectedType?.isSuspendFunctionType(session) == true ||
(expectedType == null && anonymousFunction.isSuspendFunctionType())
)
anonymousFunction.replaceTypeRef(resolvedTypeRef)
session.lookupTracker?.recordTypeResolveAsLookup(resolvedTypeRef, anonymousFunction.source, null)
}
@@ -640,6 +643,9 @@ class FirCallCompletionResultsWriterTransformer(
return result
}
private fun FirAnonymousFunction.isSuspendFunctionType() =
typeRef.coneTypeSafe<ConeKotlinType>()?.isSuspendFunctionType(session) == true
private fun transformImplicitTypeRefInAnonymousFunction(
anonymousFunction: FirAnonymousFunction
): FirStatement {
@@ -2,7 +2,6 @@
// WITH_COROUTINES
// NO_CHECK_LAMBDA_INLINING
// WITH_RUNTIME
// IGNORE_BACKEND_FIR: JVM_IR
// FILE: inlined.kt
suspend inline fun crossinlineMe(crossinline c: suspend () -> Unit) {
@@ -2,7 +2,6 @@
// WITH_COROUTINES
// NO_CHECK_LAMBDA_INLINING
// WITH_RUNTIME
// IGNORE_BACKEND_FIR: JVM_IR
// FILE: inlined.kt
interface SuspendRunnable {
@@ -2,7 +2,6 @@
// WITH_COROUTINES
// NO_CHECK_LAMBDA_INLINING
// WITH_RUNTIME
// IGNORE_BACKEND_FIR: JVM_IR
// FILE: inlined.kt
interface SuspendRunnable {
@@ -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
}
}
@@ -6431,6 +6431,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
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
@TestMetadata("compiler/testData/diagnostics/tests/coroutines/callableReference")
@TestDataPath("$PROJECT_ROOT")