KT-9461: Inference failed: type parameter fixed early
#KT-9461 Fixed
(cherry picked from commit 77ce125)
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 949605e..432251d 100644
--- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/GenericCandidateResolver.kt
+++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/GenericCandidateResolver.kt
@@ -261,7 +261,7 @@
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 0000000..dc4eab6
--- /dev/null
+++ b/compiler/testData/diagnostics/tests/inference/regressions/kt9461.kt
@@ -0,0 +1,17 @@
+interface In<in I>
+
+interface B : In<B>
+
+interface C<I, T>
+
+fun <I, T> In<I>.foo(<!UNUSED_PARAMETER!>f<!>: () -> C<I, T>) {}
+fun <I, T, Self: In<I>> Self.foo2(<!UNUSED_PARAMETER!>f<!>: () -> C<I, T>) {}
+
+class E : B // e <: In<B> <: In<E>
+
+fun test(c: C<E, Int>, e: E) {
+ e.foo<E, Int> { c }
+ e.foo { c } // error here: expected C<B, ???> but must be C<??? : B, ???>
+ 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 0000000..e3cf1df
--- /dev/null
+++ b/compiler/testData/diagnostics/tests/inference/regressions/kt9461.txt
@@ -0,0 +1,30 @@
+package
+
+public fun test(/*0*/ c: C<E, kotlin.Int>, /*1*/ e: E): kotlin.Unit
+public fun </*0*/ I, /*1*/ T> In<I>.foo(/*0*/ f: () -> C<I, T>): kotlin.Unit
+public fun </*0*/ I, /*1*/ T, /*2*/ Self : In<I>> Self.foo2(/*0*/ f: () -> C<I, T>): kotlin.Unit
+
+public interface B : In<B> {
+ 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</*0*/ I, /*1*/ T> {
+ 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</*0*/ in I> {
+ 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 f876e68..67cfadd 100644
--- a/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java
+++ b/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java
@@ -7655,6 +7655,12 @@
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");