From 7bd7db839d3332521728efa8480b50bd6c1ce39b Mon Sep 17 00:00:00 2001 From: Mikhail Zarechenskiy Date: Mon, 20 Jan 2020 13:35:56 +0300 Subject: [PATCH] [NI] Fix adapting arguments for callable references with receivers #KT-35912 Fixed --- .../FirOldFrontendDiagnosticsTestGenerated.java | 5 +++++ .../components/CallableReferenceResolution.kt | 2 +- .../callableReferenceToVarargWithOverload.fir.kt | 16 ++++++++++++++++ .../callableReferenceToVarargWithOverload.kt | 16 ++++++++++++++++ .../callableReferenceToVarargWithOverload.txt | 13 +++++++++++++ .../checkers/DiagnosticsTestGenerated.java | 5 +++++ .../DiagnosticsUsingJavacTestGenerated.java | 5 +++++ 7 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 compiler/testData/diagnostics/tests/callableReference/resolve/callableReferenceToVarargWithOverload.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/resolve/callableReferenceToVarargWithOverload.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/resolve/callableReferenceToVarargWithOverload.txt 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 d03fb8bf726..d4a8a41650d 100644 --- a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java @@ -2573,6 +2573,11 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirOldFronte runTest("compiler/testData/diagnostics/tests/callableReference/resolve/byValType.kt"); } + @TestMetadata("callableReferenceToVarargWithOverload.kt") + public void testCallableReferenceToVarargWithOverload() throws Exception { + runTest("compiler/testData/diagnostics/tests/callableReference/resolve/callableReferenceToVarargWithOverload.kt"); + } + @TestMetadata("chooseCallableReferenceDependingOnInferredReceiver.kt") public void testChooseCallableReferenceDependingOnInferredReceiver() throws Exception { runTest("compiler/testData/diagnostics/tests/callableReference/resolve/chooseCallableReferenceDependingOnInferredReceiver.kt"); diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/CallableReferenceResolution.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/CallableReferenceResolution.kt index 961e425578f..c05651791b6 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/CallableReferenceResolution.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/CallableReferenceResolution.kt @@ -266,7 +266,7 @@ class CallableReferencesCandidateFactory( val mappedArgument: KotlinType? if (substitutedParameter.isVararg) { val (varargType, newVarargMappingState) = varargParameterTypeByExpectedParameter( - inputOutputTypes.inputTypes[index], + inputOutputTypes.inputTypes[index + unboundReceiverCount], substitutedParameter, varargMappingState, builtins diff --git a/compiler/testData/diagnostics/tests/callableReference/resolve/callableReferenceToVarargWithOverload.fir.kt b/compiler/testData/diagnostics/tests/callableReference/resolve/callableReferenceToVarargWithOverload.fir.kt new file mode 100644 index 00000000000..0047654e4b4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/resolve/callableReferenceToVarargWithOverload.fir.kt @@ -0,0 +1,16 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_PARAMETER + +import kotlin.reflect.KFunction2 + +class Foo + +fun test(fn: KFunction2, String>) = null + +fun Foo.bar(vararg x: String) = "" +fun Foo.bar(vararg x: Int) = "" + + +fun actualTest() { + test(Foo::bar) +} diff --git a/compiler/testData/diagnostics/tests/callableReference/resolve/callableReferenceToVarargWithOverload.kt b/compiler/testData/diagnostics/tests/callableReference/resolve/callableReferenceToVarargWithOverload.kt new file mode 100644 index 00000000000..eacdd3e44de --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/resolve/callableReferenceToVarargWithOverload.kt @@ -0,0 +1,16 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_PARAMETER + +import kotlin.reflect.KFunction2 + +class Foo + +fun test(fn: KFunction2, String>) = null + +fun Foo.bar(vararg x: String) = "" +fun Foo.bar(vararg x: Int) = "" + + +fun actualTest() { + test(Foo::bar) +} diff --git a/compiler/testData/diagnostics/tests/callableReference/resolve/callableReferenceToVarargWithOverload.txt b/compiler/testData/diagnostics/tests/callableReference/resolve/callableReferenceToVarargWithOverload.txt new file mode 100644 index 00000000000..c8a1f328ca0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/resolve/callableReferenceToVarargWithOverload.txt @@ -0,0 +1,13 @@ +package + +public fun actualTest(): kotlin.Unit +public fun test(/*0*/ fn: kotlin.reflect.KFunction2, kotlin.String>): kotlin.Nothing? +public fun Foo.bar(/*0*/ vararg x: kotlin.String /*kotlin.Array*/): kotlin.String +public fun Foo.bar(/*0*/ vararg x: kotlin.Int /*kotlin.IntArray*/): kotlin.String + +public final class Foo { + public constructor Foo() + 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/DiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java index cd5fb93e21b..4d2329900b5 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java @@ -2580,6 +2580,11 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest { runTest("compiler/testData/diagnostics/tests/callableReference/resolve/byValType.kt"); } + @TestMetadata("callableReferenceToVarargWithOverload.kt") + public void testCallableReferenceToVarargWithOverload() throws Exception { + runTest("compiler/testData/diagnostics/tests/callableReference/resolve/callableReferenceToVarargWithOverload.kt"); + } + @TestMetadata("chooseCallableReferenceDependingOnInferredReceiver.kt") public void testChooseCallableReferenceDependingOnInferredReceiver() throws Exception { runTest("compiler/testData/diagnostics/tests/callableReference/resolve/chooseCallableReferenceDependingOnInferredReceiver.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java index 4dff5eca7c5..5a478bb0f81 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java @@ -2575,6 +2575,11 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing runTest("compiler/testData/diagnostics/tests/callableReference/resolve/byValType.kt"); } + @TestMetadata("callableReferenceToVarargWithOverload.kt") + public void testCallableReferenceToVarargWithOverload() throws Exception { + runTest("compiler/testData/diagnostics/tests/callableReference/resolve/callableReferenceToVarargWithOverload.kt"); + } + @TestMetadata("chooseCallableReferenceDependingOnInferredReceiver.kt") public void testChooseCallableReferenceDependingOnInferredReceiver() throws Exception { runTest("compiler/testData/diagnostics/tests/callableReference/resolve/chooseCallableReferenceDependingOnInferredReceiver.kt");