diff --git a/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java index ab376f9089c..a0eac050faf 100644 --- a/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java @@ -1949,6 +1949,11 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirOldFronte runTest("compiler/testData/diagnostics/tests/callableReference/referenceAdaptationCompatibility.kt"); } + @TestMetadata("referenceAdaptationHasDependencyOnApi14.kt") + public void testReferenceAdaptationHasDependencyOnApi14() throws Exception { + runTest("compiler/testData/diagnostics/tests/callableReference/referenceAdaptationHasDependencyOnApi14.kt"); + } + @TestMetadata("referenceToCompanionObjectMemberViaClassName.kt") public void testReferenceToCompanionObjectMemberViaClassName() throws Exception { runTest("compiler/testData/diagnostics/tests/callableReference/referenceToCompanionObjectMemberViaClassName.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 598c5b99304..caf4dab89d5 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 @@ -6,6 +6,7 @@ package org.jetbrains.kotlin.resolve.calls.components import org.jetbrains.kotlin.builtins.* +import org.jetbrains.kotlin.config.ApiVersion import org.jetbrains.kotlin.config.LanguageFeature import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.descriptors.annotations.Annotations @@ -284,6 +285,8 @@ class CallableReferencesCandidateFactory( unboundReceiverCount: Int, builtins: KotlinBuiltIns ): CallableReferenceAdaptation? { + if (callComponents.languageVersionSettings.apiVersion < ApiVersion.KOTLIN_1_4) return null + val inputOutputTypes = extractInputOutputTypesFromCallableReferenceExpectedType(expectedType) ?: return null val expectedArgumentCount = inputOutputTypes.inputTypes.size - unboundReceiverCount diff --git a/compiler/testData/diagnostics/tests/callableReference/referenceAdaptationHasDependencyOnApi14.fir.kt b/compiler/testData/diagnostics/tests/callableReference/referenceAdaptationHasDependencyOnApi14.fir.kt new file mode 100644 index 00000000000..30c0351fb91 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/referenceAdaptationHasDependencyOnApi14.fir.kt @@ -0,0 +1,18 @@ +// !API_VERSION: 1.3 +// !DIAGNOSTICS: -UNUSED_PARAMETER + +class A { + fun foo(s: String = "", vararg xs: Long): String = "foo" +} + +fun coercionToUnit(f: (A, String, LongArray) -> Unit): Any = f +fun varargToElement(f: (A, String, Long, Long) -> String): Any = f +fun defaultAndVararg(f: (A) -> String): Any = f +fun allOfTheAbove(f: (A) -> Unit): Any = f + +fun test() { + coercionToUnit(A::foo) + varargToElement(A::foo) + defaultAndVararg(A::foo) + allOfTheAbove(A::foo) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/callableReference/referenceAdaptationHasDependencyOnApi14.kt b/compiler/testData/diagnostics/tests/callableReference/referenceAdaptationHasDependencyOnApi14.kt new file mode 100644 index 00000000000..0d9359b2f3a --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/referenceAdaptationHasDependencyOnApi14.kt @@ -0,0 +1,18 @@ +// !API_VERSION: 1.3 +// !DIAGNOSTICS: -UNUSED_PARAMETER + +class A { + fun foo(s: String = "", vararg xs: Long): String = "foo" +} + +fun coercionToUnit(f: (A, String, LongArray) -> Unit): Any = f +fun varargToElement(f: (A, String, Long, Long) -> String): Any = f +fun defaultAndVararg(f: (A) -> String): Any = f +fun allOfTheAbove(f: (A) -> Unit): Any = f + +fun test() { + coercionToUnit(A::foo) + varargToElement(A::foo) + defaultAndVararg(A::foo) + allOfTheAbove(A::foo) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/callableReference/referenceAdaptationHasDependencyOnApi14.txt b/compiler/testData/diagnostics/tests/callableReference/referenceAdaptationHasDependencyOnApi14.txt new file mode 100644 index 00000000000..a5ab4f39b56 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/referenceAdaptationHasDependencyOnApi14.txt @@ -0,0 +1,15 @@ +package + +public fun allOfTheAbove(/*0*/ f: (A) -> kotlin.Unit): kotlin.Any +public fun coercionToUnit(/*0*/ f: (A, kotlin.String, kotlin.LongArray) -> kotlin.Unit): kotlin.Any +public fun defaultAndVararg(/*0*/ f: (A) -> kotlin.String): kotlin.Any +public fun test(): kotlin.Unit +public fun varargToElement(/*0*/ f: (A, kotlin.String, kotlin.Long, kotlin.Long) -> kotlin.String): kotlin.Any + +public final class A { + public constructor A() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public final fun foo(/*0*/ s: kotlin.String = ..., /*1*/ vararg xs: kotlin.Long /*kotlin.LongArray*/): kotlin.String + 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 51686b96c02..388d9a6faa3 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java @@ -1956,6 +1956,11 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTestWithFirVali runTest("compiler/testData/diagnostics/tests/callableReference/referenceAdaptationCompatibility.kt"); } + @TestMetadata("referenceAdaptationHasDependencyOnApi14.kt") + public void testReferenceAdaptationHasDependencyOnApi14() throws Exception { + runTest("compiler/testData/diagnostics/tests/callableReference/referenceAdaptationHasDependencyOnApi14.kt"); + } + @TestMetadata("referenceToCompanionObjectMemberViaClassName.kt") public void testReferenceToCompanionObjectMemberViaClassName() throws Exception { runTest("compiler/testData/diagnostics/tests/callableReference/referenceToCompanionObjectMemberViaClassName.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java index ef94c80bf1f..8df9d580b7b 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java @@ -1951,6 +1951,11 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing runTest("compiler/testData/diagnostics/tests/callableReference/referenceAdaptationCompatibility.kt"); } + @TestMetadata("referenceAdaptationHasDependencyOnApi14.kt") + public void testReferenceAdaptationHasDependencyOnApi14() throws Exception { + runTest("compiler/testData/diagnostics/tests/callableReference/referenceAdaptationHasDependencyOnApi14.kt"); + } + @TestMetadata("referenceToCompanionObjectMemberViaClassName.kt") public void testReferenceToCompanionObjectMemberViaClassName() throws Exception { runTest("compiler/testData/diagnostics/tests/callableReference/referenceToCompanionObjectMemberViaClassName.kt");