diff --git a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java index e71df75af78..3719cd80c34 100644 --- a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java @@ -2382,6 +2382,11 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirOldFronte runTest("compiler/testData/diagnostics/tests/callableReference/generic/kt12286.kt"); } + @TestMetadata("kt35896.kt") + public void testKt35896() throws Exception { + runTest("compiler/testData/diagnostics/tests/callableReference/generic/kt35896.kt"); + } + @TestMetadata("kt7470.kt") public void testKt7470() throws Exception { runTest("compiler/testData/diagnostics/tests/callableReference/generic/kt7470.kt"); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/ResolvedAtomCompleter.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/ResolvedAtomCompleter.kt index 7d10dfd76f2..18a56e90f77 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/ResolvedAtomCompleter.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/ResolvedAtomCompleter.kt @@ -23,6 +23,7 @@ import org.jetbrains.kotlin.resolve.calls.checkers.CallCheckerContext import org.jetbrains.kotlin.resolve.calls.context.BasicCallResolutionContext import org.jetbrains.kotlin.resolve.calls.context.ContextDependency import org.jetbrains.kotlin.resolve.calls.inference.components.NewTypeSubstitutor +import org.jetbrains.kotlin.resolve.calls.inference.components.NewTypeSubstitutorByConstructorMap import org.jetbrains.kotlin.resolve.calls.model.* import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowValueFactory @@ -255,6 +256,16 @@ class ResolvedAtomCompleter( } } + private fun NewTypeSubstitutor.toOldSubstitution(): TypeSubstitution = object : TypeSubstitution() { + override fun get(key: KotlinType): TypeProjection? { + return safeSubstitute(key.unwrap()).takeIf { it !== key }?.asTypeProjection() + } + + override fun isEmpty(): Boolean { + return isEmpty + } + } + private fun completeCallableReference( resolvedAtom: ResolvedCallableReferenceAtom ) { @@ -264,20 +275,14 @@ class ResolvedAtomCompleter( return } val resultTypeParameters = - callableCandidate.freshSubstitutor!!.freshVariables.map { resultSubstitutor.safeSubstitute(it.defaultType).asTypeProjection() } + callableCandidate.freshSubstitutor!!.freshVariables.map { resultSubstitutor.safeSubstitute(it.defaultType) } - val firstSubstitutor = IndexedParametersSubstitution(callableCandidate.candidate.typeParameters, resultTypeParameters) - val secondSubstitution = object : TypeSubstitution() { - override fun get(key: KotlinType): TypeProjection? { - return resultSubstitutor.safeSubstitute(key.unwrap()).takeIf { it !== key }?.asTypeProjection() - } + val typeParametersSubstitutor = NewTypeSubstitutorByConstructorMap((callableCandidate.candidate.typeParameters.map { it.typeConstructor } zip resultTypeParameters).toMap()) - override fun isEmpty(): Boolean { - return resultSubstitutor.isEmpty - } - } + val firstSubstitution = typeParametersSubstitutor.toOldSubstitution() + val secondSubstitution = resultSubstitutor.toOldSubstitution() val resultSubstitutor = TypeSubstitutor.createChainedSubstitutor( - firstSubstitutor, + firstSubstitution, secondSubstitution ) diff --git a/compiler/testData/diagnostics/tests/callableReference/generic/kt35896.fir.kt b/compiler/testData/diagnostics/tests/callableReference/generic/kt35896.fir.kt new file mode 100644 index 00000000000..d726da863a1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/generic/kt35896.fir.kt @@ -0,0 +1,15 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_PARAMETER +// ISSUE: KT-35896 + +interface B + +class Inv + +class Foo(x: Int): B> + +fun bar(list: T2, fn: (S) -> B) {} + +fun foo(list: Inv) { + bar(list, ::Foo) +} diff --git a/compiler/testData/diagnostics/tests/callableReference/generic/kt35896.kt b/compiler/testData/diagnostics/tests/callableReference/generic/kt35896.kt new file mode 100644 index 00000000000..d726da863a1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/generic/kt35896.kt @@ -0,0 +1,15 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_PARAMETER +// ISSUE: KT-35896 + +interface B + +class Inv + +class Foo(x: Int): B> + +fun bar(list: T2, fn: (S) -> B) {} + +fun foo(list: Inv) { + bar(list, ::Foo) +} diff --git a/compiler/testData/diagnostics/tests/callableReference/generic/kt35896.txt b/compiler/testData/diagnostics/tests/callableReference/generic/kt35896.txt new file mode 100644 index 00000000000..b6c31ef482d --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/generic/kt35896.txt @@ -0,0 +1,24 @@ +package + +public fun bar(/*0*/ list: T2, /*1*/ fn: (S) -> B): kotlin.Unit +public fun foo(/*0*/ list: Inv): kotlin.Unit + +public interface 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 final class Foo : B> { + public constructor Foo(/*0*/ x: kotlin.Int) + 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 Inv { + public constructor Inv() + 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/testData/diagnostics/tests/typealias/noApproximationInTypeAliasArgumentSubstitution.ni.txt b/compiler/testData/diagnostics/tests/typealias/noApproximationInTypeAliasArgumentSubstitution.ni.txt index 1765ae73d4d..9a8e2305c9a 100644 --- a/compiler/testData/diagnostics/tests/typealias/noApproximationInTypeAliasArgumentSubstitution.ni.txt +++ b/compiler/testData/diagnostics/tests/typealias/noApproximationInTypeAliasArgumentSubstitution.ni.txt @@ -1,7 +1,7 @@ package public fun bar1(/*0*/ a: Array2D /* = kotlin.Array> */): Array2D /* = kotlin.Array> */ -public fun bar2(/*0*/ m: TMap<*> /* = kotlin.collections.Map<*, *> */): kotlin.collections.Map +public fun bar2(/*0*/ m: TMap<*> /* = kotlin.collections.Map<*, *> */): kotlin.collections.Map<*, *> public fun foo1(/*0*/ a: Array2D /* = kotlin.Array> */): Array2D /* = kotlin.Array> */ public fun foo2(/*0*/ m: TMap /* = kotlin.collections.Map */): TMap /* = kotlin.collections.Map */ public typealias Array2D = kotlin.Array> diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java index 7cc557bd6a7..c34dcdf0e64 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java @@ -2389,6 +2389,11 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest { runTest("compiler/testData/diagnostics/tests/callableReference/generic/kt12286.kt"); } + @TestMetadata("kt35896.kt") + public void testKt35896() throws Exception { + runTest("compiler/testData/diagnostics/tests/callableReference/generic/kt35896.kt"); + } + @TestMetadata("kt7470.kt") public void testKt7470() throws Exception { runTest("compiler/testData/diagnostics/tests/callableReference/generic/kt7470.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java index 3fc3d8e6e4e..f4b571afb54 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java @@ -2384,6 +2384,11 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing runTest("compiler/testData/diagnostics/tests/callableReference/generic/kt12286.kt"); } + @TestMetadata("kt35896.kt") + public void testKt35896() throws Exception { + runTest("compiler/testData/diagnostics/tests/callableReference/generic/kt35896.kt"); + } + @TestMetadata("kt7470.kt") public void testKt7470() throws Exception { runTest("compiler/testData/diagnostics/tests/callableReference/generic/kt7470.kt");