[FIR] fix internal error on suspend conversion with not-computed return type
^KT-62836 Fixed
This commit is contained in:
committed by
Space Team
parent
f4096ae8e9
commit
928fb94052
+6
@@ -38358,6 +38358,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia
|
||||
runTest("compiler/testData/diagnostics/tests/suspendConversion/chainedFunSuspendConversionForSimpleExpression.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("implicitInvoke.kt")
|
||||
public void testImplicitInvoke() {
|
||||
runTest("compiler/testData/diagnostics/tests/suspendConversion/implicitInvoke.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("implicitInvokeFromChildClass.kt")
|
||||
public void testImplicitInvokeFromChildClass() {
|
||||
|
||||
+6
@@ -38358,6 +38358,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated
|
||||
runTest("compiler/testData/diagnostics/tests/suspendConversion/chainedFunSuspendConversionForSimpleExpression.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("implicitInvoke.kt")
|
||||
public void testImplicitInvoke() {
|
||||
runTest("compiler/testData/diagnostics/tests/suspendConversion/implicitInvoke.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("implicitInvokeFromChildClass.kt")
|
||||
public void testImplicitInvokeFromChildClass() {
|
||||
|
||||
+6
@@ -35930,6 +35930,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir
|
||||
runTest("compiler/testData/diagnostics/tests/suspendConversion/chainedFunSuspendConversionForSimpleExpression.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("implicitInvoke.kt")
|
||||
public void testImplicitInvoke() {
|
||||
runTest("compiler/testData/diagnostics/tests/suspendConversion/implicitInvoke.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("implicitInvokeFromChildClass.kt")
|
||||
public void testImplicitInvokeFromChildClass() {
|
||||
|
||||
+6
@@ -36068,6 +36068,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia
|
||||
runTest("compiler/testData/diagnostics/tests/suspendConversion/chainedFunSuspendConversionForSimpleExpression.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("implicitInvoke.kt")
|
||||
public void testImplicitInvoke() {
|
||||
runTest("compiler/testData/diagnostics/tests/suspendConversion/implicitInvoke.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("implicitInvokeFromChildClass.kt")
|
||||
public void testImplicitInvokeFromChildClass() {
|
||||
|
||||
@@ -24,7 +24,9 @@ import org.jetbrains.kotlin.fir.resolve.transformers.ensureResolvedTypeDeclarati
|
||||
import org.jetbrains.kotlin.fir.symbols.ConeClassLikeLookupTag
|
||||
import org.jetbrains.kotlin.fir.symbols.ConeTypeParameterLookupTag
|
||||
import org.jetbrains.kotlin.fir.types.*
|
||||
import org.jetbrains.kotlin.fir.types.ConeKotlinType
|
||||
import org.jetbrains.kotlin.fir.types.impl.ConeTypeParameterTypeImpl
|
||||
import org.jetbrains.kotlin.fir.types.unwrapLowerBound
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.name.StandardClassIds
|
||||
@@ -287,8 +289,10 @@ fun Candidate.resolvePlainArgumentType(
|
||||
|
||||
// If the argument is of functional type and the expected type is a suspend function type, we need to do "suspend conversion."
|
||||
if (expectedType != null) {
|
||||
argumentTypeWithCustomConversion(
|
||||
session, context.bodyResolveComponents.scopeSession, expectedType, argumentTypeForApplicabilityCheck
|
||||
context.typeContext.argumentTypeWithCustomConversion(
|
||||
session = session,
|
||||
expectedType = expectedType,
|
||||
argumentType = argumentTypeForApplicabilityCheck,
|
||||
)?.let {
|
||||
argumentTypeForApplicabilityCheck = it
|
||||
substitutor.substituteOrSelf(argumentTypeForApplicabilityCheck)
|
||||
@@ -301,11 +305,10 @@ fun Candidate.resolvePlainArgumentType(
|
||||
)
|
||||
}
|
||||
|
||||
private fun argumentTypeWithCustomConversion(
|
||||
private fun ConeInferenceContext.argumentTypeWithCustomConversion(
|
||||
session: FirSession,
|
||||
scopeSession: ScopeSession,
|
||||
expectedType: ConeKotlinType,
|
||||
argumentType: ConeKotlinType
|
||||
argumentType: ConeKotlinType,
|
||||
): ConeKotlinType? {
|
||||
// Expect the expected type to be a not regular functional type (e.g. suspend or custom)
|
||||
val expectedTypeKind = expectedType.functionTypeKind(session) ?: return null
|
||||
@@ -314,21 +317,18 @@ private fun argumentTypeWithCustomConversion(
|
||||
// We want to check the argument type against non-suspend functional type.
|
||||
val expectedFunctionType = expectedType.customFunctionTypeToSimpleFunctionType(session)
|
||||
|
||||
val argumentTypeWithInvoke = argumentType.findSubtypeOfBasicFunctionType(session, expectedFunctionType)
|
||||
val argumentTypeWithInvoke = argumentType.findSubtypeOfBasicFunctionType(session, expectedFunctionType) ?: return null
|
||||
val functionType = argumentTypeWithInvoke.unwrapLowerBound()
|
||||
.fastCorrespondingSupertypes(expectedFunctionType.typeConstructor())
|
||||
?.firstOrNull() as? ConeKotlinType ?: return null
|
||||
|
||||
return argumentTypeWithInvoke?.findContributedInvokeSymbol(
|
||||
session,
|
||||
scopeSession,
|
||||
expectedFunctionType,
|
||||
shouldCalculateReturnTypesOfFakeOverrides = false
|
||||
)?.let { invokeSymbol ->
|
||||
createFunctionType(
|
||||
expectedTypeKind,
|
||||
invokeSymbol.fir.valueParameters.map { it.returnTypeRef.coneType },
|
||||
null,
|
||||
invokeSymbol.fir.returnTypeRef.coneType,
|
||||
)
|
||||
}
|
||||
val typeArguments = functionType.typeArguments.map { it.type ?: session.builtinTypes.nullableAnyType.type }.ifEmpty { return null }
|
||||
return createFunctionType(
|
||||
kind = expectedTypeKind,
|
||||
parameters = typeArguments.subList(0, typeArguments.lastIndex),
|
||||
receiverType = null,
|
||||
rawReturnType = typeArguments.last(),
|
||||
)
|
||||
}
|
||||
|
||||
internal fun prepareCapturedType(argumentType: ConeKotlinType, context: ResolutionContext): ConeKotlinType {
|
||||
|
||||
-2
@@ -3,8 +3,6 @@
|
||||
// WITH_COROUTINES
|
||||
// IGNORE_BACKEND: JVM, JS, JS_IR
|
||||
// IGNORE_BACKEND: JS_IR_ES6
|
||||
// IGNORE_REVERSED_RESOLVE
|
||||
// KT-62836
|
||||
|
||||
import helpers.*
|
||||
import kotlin.coroutines.*
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
// FIR_IDENTICAL
|
||||
fun box() = useSuspendFunInt(Test())
|
||||
|
||||
fun useSuspendFunInt(fn: suspend () -> String): String = ""
|
||||
|
||||
open class Test : () -> String {
|
||||
override fun invoke() = "OK"
|
||||
}
|
||||
-1
@@ -1,5 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
// IGNORE_DIAGNOSTIC_API
|
||||
// ISSUE: KT-62836
|
||||
fun box() {
|
||||
useSuspendFunInt(Child())
|
||||
|
||||
Vendored
+1
-2
@@ -1,7 +1,6 @@
|
||||
// IGNORE_DIAGNOSTIC_API
|
||||
// ISSUE: KT-62836
|
||||
fun box() {
|
||||
useSuspendFunInt(Test())
|
||||
useSuspendFunInt(<!ARGUMENT_TYPE_MISMATCH!>Test()<!>)
|
||||
}
|
||||
|
||||
fun useSuspendFunInt(fn: suspend () -> String): String = ""
|
||||
|
||||
-1
@@ -1,4 +1,3 @@
|
||||
// IGNORE_DIAGNOSTIC_API
|
||||
// ISSUE: KT-62836
|
||||
fun box() {
|
||||
useSuspendFunInt(<!TYPE_MISMATCH!>Test()<!>)
|
||||
|
||||
Generated
+6
@@ -38358,6 +38358,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
||||
runTest("compiler/testData/diagnostics/tests/suspendConversion/chainedFunSuspendConversionForSimpleExpression.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("implicitInvoke.kt")
|
||||
public void testImplicitInvoke() {
|
||||
runTest("compiler/testData/diagnostics/tests/suspendConversion/implicitInvoke.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("implicitInvokeFromChildClass.kt")
|
||||
public void testImplicitInvokeFromChildClass() {
|
||||
|
||||
Reference in New Issue
Block a user