Callable reference adaptation should have dependency on API version 1.4

#KT-38069 Fixed
This commit is contained in:
Mikhail Zarechenskiy
2020-06-26 06:54:21 +03:00
parent bc40669598
commit c5a2ab2512
7 changed files with 69 additions and 0 deletions
@@ -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");
@@ -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
@@ -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)
<!INAPPLICABLE_CANDIDATE!>varargToElement<!>(A::foo)
<!INAPPLICABLE_CANDIDATE!>defaultAndVararg<!>(A::foo)
<!INAPPLICABLE_CANDIDATE!>allOfTheAbove<!>(A::foo)
}
@@ -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(<!TYPE_MISMATCH!>A::foo<!>)
varargToElement(<!TYPE_MISMATCH!>A::foo<!>)
defaultAndVararg(<!TYPE_MISMATCH!>A::foo<!>)
allOfTheAbove(<!TYPE_MISMATCH!>A::foo<!>)
}
@@ -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
}
@@ -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");
@@ -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");