FIR: Fix internal error on SAM with not-computed return type
^KT-52691 Fixed
This commit is contained in:
+6
@@ -26714,6 +26714,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag
|
||||
runTest("compiler/testData/diagnostics/tests/samConversions/GenericSubstitutionKT.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("implicitReturnType.kt")
|
||||
public void testImplicitReturnType() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/samConversions/implicitReturnType.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("javaMemberAgainstExtension.kt")
|
||||
public void testJavaMemberAgainstExtension() throws Exception {
|
||||
|
||||
+6
@@ -26714,6 +26714,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
|
||||
runTest("compiler/testData/diagnostics/tests/samConversions/GenericSubstitutionKT.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("implicitReturnType.kt")
|
||||
public void testImplicitReturnType() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/samConversions/implicitReturnType.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("javaMemberAgainstExtension.kt")
|
||||
public void testJavaMemberAgainstExtension() throws Exception {
|
||||
|
||||
+6
@@ -26714,6 +26714,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac
|
||||
runTest("compiler/testData/diagnostics/tests/samConversions/GenericSubstitutionKT.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("implicitReturnType.kt")
|
||||
public void testImplicitReturnType() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/samConversions/implicitReturnType.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("javaMemberAgainstExtension.kt")
|
||||
public void testJavaMemberAgainstExtension() throws Exception {
|
||||
|
||||
+2
-1
@@ -25,6 +25,7 @@ import org.jetbrains.kotlin.fir.resolve.calls.isFunctional
|
||||
import org.jetbrains.kotlin.fir.resolve.substitution.AbstractConeSubstitutor
|
||||
import org.jetbrains.kotlin.fir.resolve.substitution.ConeSubstitutor
|
||||
import org.jetbrains.kotlin.fir.resolve.toSymbol
|
||||
import org.jetbrains.kotlin.fir.resolve.transformers.ReturnTypeCalculatorForFullBodyResolve
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirFunctionSymbol
|
||||
import org.jetbrains.kotlin.fir.types.*
|
||||
import org.jetbrains.kotlin.ir.builders.declarations.UNDEFINED_PARAMETER_INDEX
|
||||
@@ -481,7 +482,7 @@ internal class AdapterGenerator(
|
||||
}
|
||||
// On the other hand, the actual type should be either a functional type or a subtype of a class that has a contributed `invoke`.
|
||||
val expectedFunctionType = getFunctionTypeForPossibleSamType(parameter.returnTypeRef.coneType)
|
||||
return argument.isFunctional(session, scopeSession, expectedFunctionType)
|
||||
return argument.isFunctional(session, scopeSession, expectedFunctionType, ReturnTypeCalculatorForFullBodyResolve)
|
||||
}
|
||||
|
||||
internal fun getFunctionTypeForPossibleSamType(parameterType: ConeKotlinType): ConeKotlinType? {
|
||||
|
||||
@@ -17,6 +17,7 @@ import org.jetbrains.kotlin.fir.resolve.createFunctionalType
|
||||
import org.jetbrains.kotlin.fir.resolve.fullyExpandedType
|
||||
import org.jetbrains.kotlin.fir.resolve.inference.preprocessCallableReference
|
||||
import org.jetbrains.kotlin.fir.resolve.inference.preprocessLambdaArgument
|
||||
import org.jetbrains.kotlin.fir.resolve.transformers.ReturnTypeCalculator
|
||||
import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.resultType
|
||||
import org.jetbrains.kotlin.fir.resolve.transformers.ensureResolvedTypeDeclaration
|
||||
import org.jetbrains.kotlin.fir.returnExpressions
|
||||
@@ -508,7 +509,7 @@ private fun Candidate.getExpectedTypeWithSAMConversion(
|
||||
|
||||
val (_, expectedFunctionType) = context.bodyResolveComponents.samResolver.getSamInfoForPossibleSamType(candidateExpectedType)
|
||||
?: return null
|
||||
return runIf(argument.isFunctional(session, scopeSession, expectedFunctionType)) {
|
||||
return runIf(argument.isFunctional(session, scopeSession, expectedFunctionType, context.returnTypeCalculator)) {
|
||||
usesSAM = true
|
||||
expectedFunctionType
|
||||
}
|
||||
@@ -518,6 +519,7 @@ fun FirExpression.isFunctional(
|
||||
session: FirSession,
|
||||
scopeSession: ScopeSession,
|
||||
expectedFunctionType: ConeKotlinType?,
|
||||
returnTypeCalculator: ReturnTypeCalculator,
|
||||
): Boolean {
|
||||
when (unwrapArgument()) {
|
||||
is FirAnonymousFunctionExpression, is FirCallableReferenceAccess -> return true
|
||||
@@ -544,7 +546,7 @@ fun FirExpression.isFunctional(
|
||||
errorTypesEqualToAnything = false,
|
||||
stubTypesEqualToAnything = true
|
||||
),
|
||||
invokeSymbol.fir.returnTypeRef.coneType,
|
||||
returnTypeCalculator.tryCalculateReturnType(invokeSymbol.fir).type,
|
||||
expectedReturnType,
|
||||
isFromNullabilityConstraint = false
|
||||
)
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
// FIR_IDENTICAL
|
||||
// SKIP_TXT
|
||||
// ISSUE: KT-52691
|
||||
|
||||
fun test() = compose(C1())
|
||||
|
||||
class C1 : FunInterface {
|
||||
override fun invoke() = C2()()
|
||||
}
|
||||
|
||||
class C2 : FunInterface {
|
||||
override fun invoke() {}
|
||||
}
|
||||
|
||||
fun interface FunInterface : () -> Unit
|
||||
|
||||
fun compose(funInterfaces: FunInterface) = funInterfaces
|
||||
Generated
+6
@@ -26726,6 +26726,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
||||
runTest("compiler/testData/diagnostics/tests/samConversions/GenericSubstitutionKT.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("implicitReturnType.kt")
|
||||
public void testImplicitReturnType() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/samConversions/implicitReturnType.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("javaMemberAgainstExtension.kt")
|
||||
public void testJavaMemberAgainstExtension() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user