[FIR] Fix incompatible KClass<Any> and callable reference Collection::class, ^KT-51272 Fixed
This commit is contained in:
+6
@@ -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 {
|
||||
|
||||
+6
@@ -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 {
|
||||
|
||||
+6
@@ -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 {
|
||||
|
||||
+5
-3
@@ -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 {
|
||||
|
||||
+18
@@ -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
|
||||
}
|
||||
}
|
||||
Vendored
+4
@@ -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
|
||||
Generated
+6
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user