[FIR] Check for lambda arguments that expected type is functional type
This commit is contained in:
@@ -9,6 +9,7 @@ import org.jetbrains.kotlin.fir.declarations.FirAnonymousFunction
|
|||||||
import org.jetbrains.kotlin.fir.expressions.FirCallableReferenceAccess
|
import org.jetbrains.kotlin.fir.expressions.FirCallableReferenceAccess
|
||||||
import org.jetbrains.kotlin.fir.resolve.DoubleColonLHS
|
import org.jetbrains.kotlin.fir.resolve.DoubleColonLHS
|
||||||
import org.jetbrains.kotlin.fir.resolve.constructType
|
import org.jetbrains.kotlin.fir.resolve.constructType
|
||||||
|
import org.jetbrains.kotlin.fir.resolve.createFunctionalType
|
||||||
import org.jetbrains.kotlin.fir.resolve.firSymbolProvider
|
import org.jetbrains.kotlin.fir.resolve.firSymbolProvider
|
||||||
import org.jetbrains.kotlin.fir.symbols.StandardClassIds
|
import org.jetbrains.kotlin.fir.symbols.StandardClassIds
|
||||||
import org.jetbrains.kotlin.fir.symbols.impl.ConeClassLikeLookupTagImpl
|
import org.jetbrains.kotlin.fir.symbols.impl.ConeClassLikeLookupTagImpl
|
||||||
@@ -16,6 +17,8 @@ import org.jetbrains.kotlin.fir.symbols.invoke
|
|||||||
import org.jetbrains.kotlin.fir.types.*
|
import org.jetbrains.kotlin.fir.types.*
|
||||||
import org.jetbrains.kotlin.fir.types.impl.ConeClassTypeImpl
|
import org.jetbrains.kotlin.fir.types.impl.ConeClassTypeImpl
|
||||||
import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemBuilder
|
import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemBuilder
|
||||||
|
import org.jetbrains.kotlin.resolve.calls.inference.model.ArgumentConstraintPosition
|
||||||
|
import org.jetbrains.kotlin.resolve.calls.inference.model.SimpleConstraintSystemConstraintPosition
|
||||||
import org.jetbrains.kotlin.resolve.calls.model.PostponedResolvedAtomMarker
|
import org.jetbrains.kotlin.resolve.calls.model.PostponedResolvedAtomMarker
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||||
|
|
||||||
@@ -35,6 +38,9 @@ fun Candidate.preprocessLambdaArgument(
|
|||||||
?: extraLambdaInfo(expectedType, expectedTypeRef, argument, csBuilder)
|
?: extraLambdaInfo(expectedType, expectedTypeRef, argument, csBuilder)
|
||||||
|
|
||||||
if (expectedType != null) {
|
if (expectedType != null) {
|
||||||
|
// TODO: add SAM conversion processing
|
||||||
|
val lambdaType = createFunctionalType(resolvedArgument.parameters, resolvedArgument.receiver, resolvedArgument.returnType)
|
||||||
|
csBuilder.addSubtypeConstraint(lambdaType, expectedType, SimpleConstraintSystemConstraintPosition)
|
||||||
// val lambdaType = createFunctionType(
|
// val lambdaType = createFunctionType(
|
||||||
// csBuilder.builtIns, Annotations.EMPTY, resolvedArgument.receiver,
|
// csBuilder.builtIns, Annotations.EMPTY, resolvedArgument.receiver,
|
||||||
// resolvedArgument.parameters, null, resolvedArgument.returnType, resolvedArgument.isSuspend
|
// resolvedArgument.parameters, null, resolvedArgument.returnType, resolvedArgument.isSuspend
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
interface A {
|
||||||
|
fun foo(b: Boolean = false): A
|
||||||
|
fun foo(block: () -> Boolean): A
|
||||||
|
}
|
||||||
|
|
||||||
|
fun test(a: A) {
|
||||||
|
a.foo { true }
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
FILE: overloadWithDefault.kt
|
||||||
|
public abstract interface A : R|kotlin/Any| {
|
||||||
|
public abstract fun foo(b: R|kotlin/Boolean| = Boolean(false)): R|A|
|
||||||
|
|
||||||
|
public abstract fun foo(block: R|kotlin/Function0<kotlin/Boolean>|): R|A|
|
||||||
|
|
||||||
|
}
|
||||||
|
public final fun test(a: R|A|): R|kotlin/Unit| {
|
||||||
|
R|<local>/a|.R|/A.foo|(<L> = foo@fun <anonymous>(): R|kotlin/Boolean| {
|
||||||
|
Boolean(true)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
+5
@@ -235,6 +235,11 @@ public class FirDiagnosticsTestGenerated extends AbstractFirDiagnosticsTest {
|
|||||||
runTest("compiler/fir/resolve/testData/resolve/arguments/lambda.kt");
|
runTest("compiler/fir/resolve/testData/resolve/arguments/lambda.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("overloadWithDefault.kt")
|
||||||
|
public void testOverloadWithDefault() throws Exception {
|
||||||
|
runTest("compiler/fir/resolve/testData/resolve/arguments/overloadWithDefault.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("simple.kt")
|
@TestMetadata("simple.kt")
|
||||||
public void testSimple() throws Exception {
|
public void testSimple() throws Exception {
|
||||||
runTest("compiler/fir/resolve/testData/resolve/arguments/simple.kt");
|
runTest("compiler/fir/resolve/testData/resolve/arguments/simple.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user