[FIR] Fix incompatible KClass<Any> and callable reference Collection::class, ^KT-51272 Fixed

This commit is contained in:
Ivan Kochurkin
2022-02-15 22:07:32 +03:00
committed by teamcity
parent 31d9313c51
commit f751f13c4d
7 changed files with 51 additions and 3 deletions
@@ -2646,6 +2646,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag
runTest("compiler/testData/diagnostics/tests/callableReference/callableReferenceAssignmentToVar.kt");
}
@Test
@TestMetadata("callableReferenceInWhenExpression.kt")
public void testCallableReferenceInWhenExpression() throws Exception {
runTest("compiler/testData/diagnostics/tests/callableReference/callableReferenceInWhenExpression.kt");
}
@Test
@TestMetadata("callableReferenceWithMostSpecificGenericTypeParameter.kt")
public void testCallableReferenceWithMostSpecificGenericTypeParameter() throws Exception {
@@ -2646,6 +2646,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
runTest("compiler/testData/diagnostics/tests/callableReference/callableReferenceAssignmentToVar.kt");
}
@Test
@TestMetadata("callableReferenceInWhenExpression.kt")
public void testCallableReferenceInWhenExpression() throws Exception {
runTest("compiler/testData/diagnostics/tests/callableReference/callableReferenceInWhenExpression.kt");
}
@Test
@TestMetadata("callableReferenceWithMostSpecificGenericTypeParameter.kt")
public void testCallableReferenceWithMostSpecificGenericTypeParameter() throws Exception {
@@ -2646,6 +2646,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac
runTest("compiler/testData/diagnostics/tests/callableReference/callableReferenceAssignmentToVar.kt");
}
@Test
@TestMetadata("callableReferenceInWhenExpression.kt")
public void testCallableReferenceInWhenExpression() throws Exception {
runTest("compiler/testData/diagnostics/tests/callableReference/callableReferenceInWhenExpression.kt");
}
@Test
@TestMetadata("callableReferenceWithMostSpecificGenericTypeParameter.kt")
public void testCallableReferenceWithMostSpecificGenericTypeParameter() throws Exception {
@@ -47,6 +47,8 @@ import org.jetbrains.kotlin.types.Variance
object ConeTypeCompatibilityChecker {
private val javaClassClassId = ClassId.fromString("java/lang/Class")
private val kotlinClassClassId = ClassId.fromString("kotlin/reflect/KClass")
/**
* The result returned by [ConeTypeCompatibilityChecker]. Note the order of enum entries matters.
@@ -134,6 +136,9 @@ object ConeTypeCompatibilityChecker {
return Compatibility.COMPATIBLE
}
// TODO: Due to KT-49358, we skip any checks on Java and Kotlin refection class.
if (upperBounds.any { it.classId == javaClassClassId || it.classId == kotlinClassClassId }) return Compatibility.COMPATIBLE
val leafClassesOrInterfaces = computeLeafClassesOrInterfaces(upperBoundClasses)
this.areClassesOrInterfacesCompatible(leafClassesOrInterfaces, compatibilityUpperBound)?.let { return it }
@@ -149,9 +154,6 @@ object ConeTypeCompatibilityChecker {
if (upperBounds.size < 2) return Compatibility.COMPATIBLE
// TODO: Due to KT-49358, we skip any checks on Java class.
if (upperBounds.any { it.classId == javaClassClassId }) return Compatibility.COMPATIBLE
// Base types are compatible. Now we check type parameters.
val typeArgumentMapping = mutableMapOf<FirTypeParameterSymbol, BoundTypeArguments>().apply {
@@ -0,0 +1,18 @@
// FIR_IDENTICAL
// ISSUE: KT-51272
import kotlin.reflect.KClass
fun testOnKClass(rootClass: KClass<Any>): Int {
return when (rootClass) {
Collection::class -> 1
else -> 2
}
}
fun testOnClass(rootClass: Class<Any>): Int {
return when (rootClass) {
Collection::class -> 1
else -> 2
}
}
@@ -0,0 +1,4 @@
package
public fun testOnClass(/*0*/ rootClass: java.lang.Class<kotlin.Any>): kotlin.Int
public fun testOnKClass(/*0*/ rootClass: kotlin.reflect.KClass<kotlin.Any>): kotlin.Int
@@ -2652,6 +2652,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
runTest("compiler/testData/diagnostics/tests/callableReference/callableReferenceAssignmentToVar.kt");
}
@Test
@TestMetadata("callableReferenceInWhenExpression.kt")
public void testCallableReferenceInWhenExpression() throws Exception {
runTest("compiler/testData/diagnostics/tests/callableReference/callableReferenceInWhenExpression.kt");
}
@Test
@TestMetadata("callableReferenceWithMostSpecificGenericTypeParameter.kt")
public void testCallableReferenceWithMostSpecificGenericTypeParameter() throws Exception {