From abd250710744121eee6c587aa50632d132f65be8 Mon Sep 17 00:00:00 2001 From: Victor Petukhov Date: Fri, 1 Oct 2021 15:19:57 +0300 Subject: [PATCH] Don't discriminate generics during callable references resolution ^KT-49038 Fixed --- ...CompilerTestFE10TestdataTestGenerated.java | 6 ++++++ ...irOldFrontendDiagnosticsTestGenerated.java | 6 ++++++ ...DiagnosticsWithLightTreeTestGenerated.java | 6 ++++++ .../resolve/calls/KotlinCallResolver.kt | 2 +- .../tests/callableReference/kt49038.fir.kt | 13 ++++++++++++ .../tests/callableReference/kt49038.kt | 13 ++++++++++++ .../tests/callableReference/kt49038.txt | 21 +++++++++++++++++++ .../test/runners/DiagnosticTestGenerated.java | 6 ++++++ 8 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 compiler/testData/diagnostics/tests/callableReference/kt49038.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/kt49038.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/kt49038.txt diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java index b4768bb1bbb..ca3250a6414 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java @@ -2747,6 +2747,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag runTest("compiler/testData/diagnostics/tests/callableReference/kt37530.kt"); } + @Test + @TestMetadata("kt49038.kt") + public void testKt49038() throws Exception { + runTest("compiler/testData/diagnostics/tests/callableReference/kt49038.kt"); + } + @Test @TestMetadata("kt7430_wrongClassOnLHS.kt") public void testKt7430_wrongClassOnLHS() throws Exception { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java index 32eacdd61b0..1a3aa6621a8 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java @@ -2747,6 +2747,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti runTest("compiler/testData/diagnostics/tests/callableReference/kt37530.kt"); } + @Test + @TestMetadata("kt49038.kt") + public void testKt49038() throws Exception { + runTest("compiler/testData/diagnostics/tests/callableReference/kt49038.kt"); + } + @Test @TestMetadata("kt7430_wrongClassOnLHS.kt") public void testKt7430_wrongClassOnLHS() throws Exception { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java index 168a70b61f0..9e5c1cc9ece 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java @@ -2747,6 +2747,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac runTest("compiler/testData/diagnostics/tests/callableReference/kt37530.kt"); } + @Test + @TestMetadata("kt49038.kt") + public void testKt49038() throws Exception { + runTest("compiler/testData/diagnostics/tests/callableReference/kt49038.kt"); + } + @Test @TestMetadata("kt7430_wrongClassOnLHS.kt") public void testKt7430_wrongClassOnLHS() throws Exception { diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/KotlinCallResolver.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/KotlinCallResolver.kt index 8d8aa931b5f..477159fe3fb 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/KotlinCallResolver.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/KotlinCallResolver.kt @@ -197,7 +197,7 @@ class KotlinCallResolver( callableReferenceArgumentResolver.callableReferenceOverloadConflictResolver.chooseMaximallySpecificCandidates( refinedCandidates as Collection, CheckArgumentTypesMode.CHECK_VALUE_ARGUMENTS, - discriminateGenerics = true + discriminateGenerics = false ) } else { overloadingConflictResolver.chooseMaximallySpecificCandidates( diff --git a/compiler/testData/diagnostics/tests/callableReference/kt49038.fir.kt b/compiler/testData/diagnostics/tests/callableReference/kt49038.fir.kt new file mode 100644 index 00000000000..86f7f10ca61 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/kt49038.fir.kt @@ -0,0 +1,13 @@ +fun take(arg: Any) {} + +fun foo(a: A, t: T) {} // 1 +fun foo(b: B, t : T) {} // 2 +fun foo(i: Int) {} // 3 + +class A +class B + +fun box(): String { + val ref1 = take(::foo) // error before 1.6.20; ok, resolved to (3) since 1.6.20 + return "OK" +} diff --git a/compiler/testData/diagnostics/tests/callableReference/kt49038.kt b/compiler/testData/diagnostics/tests/callableReference/kt49038.kt new file mode 100644 index 00000000000..16f54be5b0a --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/kt49038.kt @@ -0,0 +1,13 @@ +fun take(arg: Any) {} + +fun foo(a: A, t: T) {} // 1 +fun foo(b: B, t : T) {} // 2 +fun foo(i: Int) {} // 3 + +class A +class B + +fun box(): String { + val ref1 = take(::foo) // error before 1.6.20; ok, resolved to (3) since 1.6.20 + return "OK" +} diff --git a/compiler/testData/diagnostics/tests/callableReference/kt49038.txt b/compiler/testData/diagnostics/tests/callableReference/kt49038.txt new file mode 100644 index 00000000000..7f8d0dc8c94 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/kt49038.txt @@ -0,0 +1,21 @@ +package + +public fun box(): kotlin.String +public fun foo(/*0*/ a: A, /*1*/ t: T): kotlin.Unit +public fun foo(/*0*/ b: B, /*1*/ t: T): kotlin.Unit +public fun foo(/*0*/ i: kotlin.Int): kotlin.Unit +public fun take(/*0*/ arg: kotlin.Any): kotlin.Unit + +public final class A { + public constructor A() + 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 B { + public constructor 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 +} diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java index afe33434f94..248ab0f93f6 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java @@ -2753,6 +2753,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/tests/callableReference/kt37530.kt"); } + @Test + @TestMetadata("kt49038.kt") + public void testKt49038() throws Exception { + runTest("compiler/testData/diagnostics/tests/callableReference/kt49038.kt"); + } + @Test @TestMetadata("kt7430_wrongClassOnLHS.kt") public void testKt7430_wrongClassOnLHS() throws Exception {