diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java index 0fceafd0c97..083ed2c8bfb 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java @@ -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") diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java index 3d24303506c..b8d6bc775e5 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java @@ -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") diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java index 2a1da1c36a9..c78bbd28dac 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java @@ -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") diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirCallCompletionResultsWriterTransformer.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirCallCompletionResultsWriterTransformer.kt index f30d761c6b7..eb81fbae56c 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirCallCompletionResultsWriterTransformer.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirCallCompletionResultsWriterTransformer.kt @@ -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()?.isSuspendFunctionType(session) == true + private fun transformImplicitTypeRefInAnonymousFunction( anonymousFunction: FirAnonymousFunction ): FirStatement { diff --git a/compiler/testData/codegen/boxInline/suspend/stateMachine/innerLambdaInsideLambda.kt b/compiler/testData/codegen/boxInline/suspend/stateMachine/innerLambdaInsideLambda.kt index dc06546ebf0..b136fff144d 100644 --- a/compiler/testData/codegen/boxInline/suspend/stateMachine/innerLambdaInsideLambda.kt +++ b/compiler/testData/codegen/boxInline/suspend/stateMachine/innerLambdaInsideLambda.kt @@ -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) { diff --git a/compiler/testData/codegen/boxInline/suspend/stateMachine/innerMadness.kt b/compiler/testData/codegen/boxInline/suspend/stateMachine/innerMadness.kt index db10d94fbc6..15d27a93695 100644 --- a/compiler/testData/codegen/boxInline/suspend/stateMachine/innerMadness.kt +++ b/compiler/testData/codegen/boxInline/suspend/stateMachine/innerMadness.kt @@ -2,7 +2,6 @@ // WITH_COROUTINES // NO_CHECK_LAMBDA_INLINING // WITH_RUNTIME -// IGNORE_BACKEND_FIR: JVM_IR // FILE: inlined.kt interface SuspendRunnable { diff --git a/compiler/testData/codegen/boxInline/suspend/stateMachine/innerMadnessCallSite.kt b/compiler/testData/codegen/boxInline/suspend/stateMachine/innerMadnessCallSite.kt index 70efa6faab8..e6dfefcc71d 100644 --- a/compiler/testData/codegen/boxInline/suspend/stateMachine/innerMadnessCallSite.kt +++ b/compiler/testData/codegen/boxInline/suspend/stateMachine/innerMadnessCallSite.kt @@ -2,7 +2,6 @@ // WITH_COROUTINES // NO_CHECK_LAMBDA_INLINING // WITH_RUNTIME -// IGNORE_BACKEND_FIR: JVM_IR // FILE: inlined.kt interface SuspendRunnable { diff --git a/compiler/testData/diagnostics/tests/coroutines/suspendLambdaFromExpectedType.kt b/compiler/testData/diagnostics/tests/coroutines/suspendLambdaFromExpectedType.kt new file mode 100644 index 00000000000..ee489d6f090 --- /dev/null +++ b/compiler/testData/diagnostics/tests/coroutines/suspendLambdaFromExpectedType.kt @@ -0,0 +1,10 @@ +// FIR_IDENTICAL +// SKIP_TXT + +fun runBlocking(block: suspend () -> T): T = TODO() + +fun foo() = runBlocking { + val foo: suspend (String) -> Int = { + it.length + } +} diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java index 847acf3fac6..3999e6818d6 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java @@ -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")