diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/GenericCandidateResolver.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/GenericCandidateResolver.kt index 29e6c107bc0..c477c1a5ae1 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/GenericCandidateResolver.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/GenericCandidateResolver.kt @@ -260,7 +260,7 @@ class GenericCandidateResolver( return } } - val expectedTypeWithoutReturnType = if (hasExpectedReturnType) replaceReturnTypeByUnknown(expectedType) else expectedType + val expectedTypeWithoutReturnType = replaceReturnTypeByUnknown(expectedType) val newContext = context.replaceExpectedType(expectedTypeWithoutReturnType).replaceDataFlowInfo(dataFlowInfoForArgument) .replaceContextDependency(INDEPENDENT) val type = argumentTypeResolver.getFunctionLiteralTypeInfo(argumentExpression, functionLiteral, newContext, RESOLVE_FUNCTION_ARGUMENTS).type diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt9461.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt9461.kt new file mode 100644 index 00000000000..dc4eab6618f --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt9461.kt @@ -0,0 +1,17 @@ +interface In + +interface B : In + +interface C + +fun In.foo(f: () -> C) {} +fun > Self.foo2(f: () -> C) {} + +class E : B // e <: In <: In + +fun test(c: C, e: E) { + e.foo { c } + e.foo { c } // error here: expected C but must be C + e.foo2 { c } + e.foo2 ({ c }) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt9461.txt b/compiler/testData/diagnostics/tests/inference/regressions/kt9461.txt new file mode 100644 index 00000000000..e3cf1df0b6d --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt9461.txt @@ -0,0 +1,30 @@ +package + +public fun test(/*0*/ c: C, /*1*/ e: E): kotlin.Unit +public fun In.foo(/*0*/ f: () -> C): kotlin.Unit +public fun > Self.foo2(/*0*/ f: () -> C): kotlin.Unit + +public interface B : In { + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public interface C { + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final class E : B { + public constructor E() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public interface In { + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java index 79e753a5593..c809b13629b 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java @@ -7796,6 +7796,12 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest { doTest(fileName); } + @TestMetadata("kt9461.kt") + public void testKt9461() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/inference/regressions/kt9461.kt"); + doTest(fileName); + } + @TestMetadata("kt948.kt") public void testKt948() throws Exception { String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/inference/regressions/kt948.kt");