diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/PostponedArguments.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/PostponedArguments.kt index da188c4b08d..09d34742e90 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/PostponedArguments.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/PostponedArguments.kt @@ -9,6 +9,7 @@ import org.jetbrains.kotlin.fir.declarations.FirAnonymousFunction import org.jetbrains.kotlin.fir.expressions.FirCallableReferenceAccess import org.jetbrains.kotlin.fir.resolve.DoubleColonLHS 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.symbols.StandardClassIds 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.impl.ConeClassTypeImpl 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.utils.addToStdlib.safeAs @@ -35,6 +38,9 @@ fun Candidate.preprocessLambdaArgument( ?: extraLambdaInfo(expectedType, expectedTypeRef, argument, csBuilder) 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( // csBuilder.builtIns, Annotations.EMPTY, resolvedArgument.receiver, // resolvedArgument.parameters, null, resolvedArgument.returnType, resolvedArgument.isSuspend diff --git a/compiler/fir/resolve/testData/resolve/arguments/overloadWithDefault.kt b/compiler/fir/resolve/testData/resolve/arguments/overloadWithDefault.kt new file mode 100644 index 00000000000..bbe5dd311eb --- /dev/null +++ b/compiler/fir/resolve/testData/resolve/arguments/overloadWithDefault.kt @@ -0,0 +1,8 @@ +interface A { + fun foo(b: Boolean = false): A + fun foo(block: () -> Boolean): A +} + +fun test(a: A) { + a.foo { true } +} \ No newline at end of file diff --git a/compiler/fir/resolve/testData/resolve/arguments/overloadWithDefault.txt b/compiler/fir/resolve/testData/resolve/arguments/overloadWithDefault.txt new file mode 100644 index 00000000000..81308b0c0c9 --- /dev/null +++ b/compiler/fir/resolve/testData/resolve/arguments/overloadWithDefault.txt @@ -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|): R|A| + + } + public final fun test(a: R|A|): R|kotlin/Unit| { + R|/a|.R|/A.foo|( = foo@fun (): R|kotlin/Boolean| { + Boolean(true) + } + ) + } diff --git a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java index a3920736444..d8f3828d70c 100644 --- a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java +++ b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java @@ -235,6 +235,11 @@ public class FirDiagnosticsTestGenerated extends AbstractFirDiagnosticsTest { 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") public void testSimple() throws Exception { runTest("compiler/fir/resolve/testData/resolve/arguments/simple.kt");