FIR: Fix invalid INITIALIZER_TYPE_MISMATCH for suspend lambda
This commit is contained in:
+6
@@ -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")
|
||||
|
||||
+6
@@ -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")
|
||||
|
||||
+7
-1
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user