diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java index bd6ae48bee8..dbd90e9b516 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java @@ -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 { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java index 4c53da76a9b..52487b4e638 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java @@ -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 { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java index 240a4d636ac..a68aa2f137e 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java @@ -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 { diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/ConeTypeCompatibilityChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/ConeTypeCompatibilityChecker.kt index f06bbf1f840..b124d2ca8ab 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/ConeTypeCompatibilityChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/ConeTypeCompatibilityChecker.kt @@ -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().apply { diff --git a/compiler/testData/diagnostics/tests/callableReference/callableReferenceInWhenExpression.kt b/compiler/testData/diagnostics/tests/callableReference/callableReferenceInWhenExpression.kt new file mode 100644 index 00000000000..af393eeda5a --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/callableReferenceInWhenExpression.kt @@ -0,0 +1,18 @@ +// FIR_IDENTICAL +// ISSUE: KT-51272 + +import kotlin.reflect.KClass + +fun testOnKClass(rootClass: KClass): Int { + return when (rootClass) { + Collection::class -> 1 + else -> 2 + } +} + +fun testOnClass(rootClass: Class): Int { + return when (rootClass) { + Collection::class -> 1 + else -> 2 + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/callableReference/callableReferenceInWhenExpression.txt b/compiler/testData/diagnostics/tests/callableReference/callableReferenceInWhenExpression.txt new file mode 100644 index 00000000000..0d180a3a02d --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/callableReferenceInWhenExpression.txt @@ -0,0 +1,4 @@ +package + +public fun testOnClass(/*0*/ rootClass: java.lang.Class): kotlin.Int +public fun testOnKClass(/*0*/ rootClass: kotlin.reflect.KClass): kotlin.Int diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java index 7f053ffe4fc..b463905f907 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java @@ -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 {