[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");
|
runTest("compiler/testData/diagnostics/tests/suspendConversion/chainedFunSuspendConversionForSimpleExpression.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("implicitInvoke.kt")
|
||||||
|
public void testImplicitInvoke() {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/suspendConversion/implicitInvoke.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("implicitInvokeFromChildClass.kt")
|
@TestMetadata("implicitInvokeFromChildClass.kt")
|
||||||
public void testImplicitInvokeFromChildClass() {
|
public void testImplicitInvokeFromChildClass() {
|
||||||
|
|||||||
+6
@@ -38358,6 +38358,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated
|
|||||||
runTest("compiler/testData/diagnostics/tests/suspendConversion/chainedFunSuspendConversionForSimpleExpression.kt");
|
runTest("compiler/testData/diagnostics/tests/suspendConversion/chainedFunSuspendConversionForSimpleExpression.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("implicitInvoke.kt")
|
||||||
|
public void testImplicitInvoke() {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/suspendConversion/implicitInvoke.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("implicitInvokeFromChildClass.kt")
|
@TestMetadata("implicitInvokeFromChildClass.kt")
|
||||||
public void testImplicitInvokeFromChildClass() {
|
public void testImplicitInvokeFromChildClass() {
|
||||||
|
|||||||
+6
@@ -35930,6 +35930,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir
|
|||||||
runTest("compiler/testData/diagnostics/tests/suspendConversion/chainedFunSuspendConversionForSimpleExpression.kt");
|
runTest("compiler/testData/diagnostics/tests/suspendConversion/chainedFunSuspendConversionForSimpleExpression.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("implicitInvoke.kt")
|
||||||
|
public void testImplicitInvoke() {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/suspendConversion/implicitInvoke.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("implicitInvokeFromChildClass.kt")
|
@TestMetadata("implicitInvokeFromChildClass.kt")
|
||||||
public void testImplicitInvokeFromChildClass() {
|
public void testImplicitInvokeFromChildClass() {
|
||||||
|
|||||||
+6
@@ -36068,6 +36068,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia
|
|||||||
runTest("compiler/testData/diagnostics/tests/suspendConversion/chainedFunSuspendConversionForSimpleExpression.kt");
|
runTest("compiler/testData/diagnostics/tests/suspendConversion/chainedFunSuspendConversionForSimpleExpression.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("implicitInvoke.kt")
|
||||||
|
public void testImplicitInvoke() {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/suspendConversion/implicitInvoke.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("implicitInvokeFromChildClass.kt")
|
@TestMetadata("implicitInvokeFromChildClass.kt")
|
||||||
public void testImplicitInvokeFromChildClass() {
|
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.ConeClassLikeLookupTag
|
||||||
import org.jetbrains.kotlin.fir.symbols.ConeTypeParameterLookupTag
|
import org.jetbrains.kotlin.fir.symbols.ConeTypeParameterLookupTag
|
||||||
import org.jetbrains.kotlin.fir.types.*
|
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.impl.ConeTypeParameterTypeImpl
|
||||||
|
import org.jetbrains.kotlin.fir.types.unwrapLowerBound
|
||||||
import org.jetbrains.kotlin.name.ClassId
|
import org.jetbrains.kotlin.name.ClassId
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.name.StandardClassIds
|
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 the argument is of functional type and the expected type is a suspend function type, we need to do "suspend conversion."
|
||||||
if (expectedType != null) {
|
if (expectedType != null) {
|
||||||
argumentTypeWithCustomConversion(
|
context.typeContext.argumentTypeWithCustomConversion(
|
||||||
session, context.bodyResolveComponents.scopeSession, expectedType, argumentTypeForApplicabilityCheck
|
session = session,
|
||||||
|
expectedType = expectedType,
|
||||||
|
argumentType = argumentTypeForApplicabilityCheck,
|
||||||
)?.let {
|
)?.let {
|
||||||
argumentTypeForApplicabilityCheck = it
|
argumentTypeForApplicabilityCheck = it
|
||||||
substitutor.substituteOrSelf(argumentTypeForApplicabilityCheck)
|
substitutor.substituteOrSelf(argumentTypeForApplicabilityCheck)
|
||||||
@@ -301,11 +305,10 @@ fun Candidate.resolvePlainArgumentType(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun argumentTypeWithCustomConversion(
|
private fun ConeInferenceContext.argumentTypeWithCustomConversion(
|
||||||
session: FirSession,
|
session: FirSession,
|
||||||
scopeSession: ScopeSession,
|
|
||||||
expectedType: ConeKotlinType,
|
expectedType: ConeKotlinType,
|
||||||
argumentType: ConeKotlinType
|
argumentType: ConeKotlinType,
|
||||||
): ConeKotlinType? {
|
): ConeKotlinType? {
|
||||||
// Expect the expected type to be a not regular functional type (e.g. suspend or custom)
|
// Expect the expected type to be a not regular functional type (e.g. suspend or custom)
|
||||||
val expectedTypeKind = expectedType.functionTypeKind(session) ?: return null
|
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.
|
// We want to check the argument type against non-suspend functional type.
|
||||||
val expectedFunctionType = expectedType.customFunctionTypeToSimpleFunctionType(session)
|
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(
|
val typeArguments = functionType.typeArguments.map { it.type ?: session.builtinTypes.nullableAnyType.type }.ifEmpty { return null }
|
||||||
session,
|
return createFunctionType(
|
||||||
scopeSession,
|
kind = expectedTypeKind,
|
||||||
expectedFunctionType,
|
parameters = typeArguments.subList(0, typeArguments.lastIndex),
|
||||||
shouldCalculateReturnTypesOfFakeOverrides = false
|
receiverType = null,
|
||||||
)?.let { invokeSymbol ->
|
rawReturnType = typeArguments.last(),
|
||||||
createFunctionType(
|
)
|
||||||
expectedTypeKind,
|
|
||||||
invokeSymbol.fir.valueParameters.map { it.returnTypeRef.coneType },
|
|
||||||
null,
|
|
||||||
invokeSymbol.fir.returnTypeRef.coneType,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun prepareCapturedType(argumentType: ConeKotlinType, context: ResolutionContext): ConeKotlinType {
|
internal fun prepareCapturedType(argumentType: ConeKotlinType, context: ResolutionContext): ConeKotlinType {
|
||||||
|
|||||||
-2
@@ -3,8 +3,6 @@
|
|||||||
// WITH_COROUTINES
|
// WITH_COROUTINES
|
||||||
// IGNORE_BACKEND: JVM, JS, JS_IR
|
// IGNORE_BACKEND: JVM, JS, JS_IR
|
||||||
// IGNORE_BACKEND: JS_IR_ES6
|
// IGNORE_BACKEND: JS_IR_ES6
|
||||||
// IGNORE_REVERSED_RESOLVE
|
|
||||||
// KT-62836
|
|
||||||
|
|
||||||
import helpers.*
|
import helpers.*
|
||||||
import kotlin.coroutines.*
|
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
|
// FIR_IDENTICAL
|
||||||
// IGNORE_DIAGNOSTIC_API
|
|
||||||
// ISSUE: KT-62836
|
// ISSUE: KT-62836
|
||||||
fun box() {
|
fun box() {
|
||||||
useSuspendFunInt(Child())
|
useSuspendFunInt(Child())
|
||||||
|
|||||||
Vendored
+1
-2
@@ -1,7 +1,6 @@
|
|||||||
// IGNORE_DIAGNOSTIC_API
|
|
||||||
// ISSUE: KT-62836
|
// ISSUE: KT-62836
|
||||||
fun box() {
|
fun box() {
|
||||||
useSuspendFunInt(Test())
|
useSuspendFunInt(<!ARGUMENT_TYPE_MISMATCH!>Test()<!>)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun useSuspendFunInt(fn: suspend () -> String): String = ""
|
fun useSuspendFunInt(fn: suspend () -> String): String = ""
|
||||||
|
|||||||
-1
@@ -1,4 +1,3 @@
|
|||||||
// IGNORE_DIAGNOSTIC_API
|
|
||||||
// ISSUE: KT-62836
|
// ISSUE: KT-62836
|
||||||
fun box() {
|
fun box() {
|
||||||
useSuspendFunInt(<!TYPE_MISMATCH!>Test()<!>)
|
useSuspendFunInt(<!TYPE_MISMATCH!>Test()<!>)
|
||||||
|
|||||||
Generated
+6
@@ -38358,6 +38358,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
|||||||
runTest("compiler/testData/diagnostics/tests/suspendConversion/chainedFunSuspendConversionForSimpleExpression.kt");
|
runTest("compiler/testData/diagnostics/tests/suspendConversion/chainedFunSuspendConversionForSimpleExpression.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("implicitInvoke.kt")
|
||||||
|
public void testImplicitInvoke() {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/suspendConversion/implicitInvoke.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("implicitInvokeFromChildClass.kt")
|
@TestMetadata("implicitInvokeFromChildClass.kt")
|
||||||
public void testImplicitInvokeFromChildClass() {
|
public void testImplicitInvokeFromChildClass() {
|
||||||
|
|||||||
Reference in New Issue
Block a user