diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendMPPDiagnosticsWithLightTreeTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendMPPDiagnosticsWithLightTreeTestGenerated.java index 4b20766a086..a761ea2284f 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendMPPDiagnosticsWithLightTreeTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendMPPDiagnosticsWithLightTreeTestGenerated.java @@ -1083,6 +1083,12 @@ public class FirOldFrontendMPPDiagnosticsWithLightTreeTestGenerated extends Abst public void testKt45796() throws Exception { runTest("compiler/testData/diagnostics/tests/multiplatform/exhaustiveness/kt45796.kt"); } + + @Test + @TestMetadata("sealedHierarchyInBambooMppStructure.kt") + public void testSealedHierarchyInBambooMppStructure() throws Exception { + runTest("compiler/testData/diagnostics/tests/multiplatform/exhaustiveness/sealedHierarchyInBambooMppStructure.kt"); + } } @Nested diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendMPPDiagnosticsWithPsiTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendMPPDiagnosticsWithPsiTestGenerated.java index 0ff0ecefd5e..919e63e1e1e 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendMPPDiagnosticsWithPsiTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendMPPDiagnosticsWithPsiTestGenerated.java @@ -1083,6 +1083,12 @@ public class FirOldFrontendMPPDiagnosticsWithPsiTestGenerated extends AbstractFi public void testKt45796() throws Exception { runTest("compiler/testData/diagnostics/tests/multiplatform/exhaustiveness/kt45796.kt"); } + + @Test + @TestMetadata("sealedHierarchyInBambooMppStructure.kt") + public void testSealedHierarchyInBambooMppStructure() throws Exception { + runTest("compiler/testData/diagnostics/tests/multiplatform/exhaustiveness/sealedHierarchyInBambooMppStructure.kt"); + } } @Nested diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirSealedSupertypeChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirSealedSupertypeChecker.kt index ff1c727eb95..9125e47de3a 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirSealedSupertypeChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirSealedSupertypeChecker.kt @@ -14,6 +14,7 @@ import org.jetbrains.kotlin.fir.declarations.FirAnonymousObject import org.jetbrains.kotlin.fir.declarations.FirClass import org.jetbrains.kotlin.fir.declarations.FirDeclarationOrigin import org.jetbrains.kotlin.fir.declarations.utils.classId +import org.jetbrains.kotlin.fir.declarations.utils.isExpect import org.jetbrains.kotlin.fir.declarations.utils.isSealed import org.jetbrains.kotlin.fir.declarations.utils.modality import org.jetbrains.kotlin.fir.resolve.providers.symbolProvider @@ -51,8 +52,7 @@ object FirSealedSupertypeChecker : FirClassChecker() { if (superClassPackage != subclassPackage) { reporter.reportOn(superTypeRef.source, FirErrors.SEALED_INHERITOR_IN_DIFFERENT_PACKAGE, context) } - if (superClass.moduleData != declaration.moduleData) { - // TODO, KT-59804: implement logic like in org.jetbrains.kotlin.resolve.checkers.SealedInheritorInSameModuleChecker for MPP support. + if (superClass.moduleData != declaration.moduleData && !superClass.isExpect) { reporter.reportOn(superTypeRef.source, FirErrors.SEALED_INHERITOR_IN_DIFFERENT_MODULE, context) } } diff --git a/compiler/testData/diagnostics/tests/multiplatform/exhaustiveness/sealedHierarchyInBambooMppStructure.fir.kt b/compiler/testData/diagnostics/tests/multiplatform/exhaustiveness/sealedHierarchyInBambooMppStructure.fir.kt new file mode 100644 index 00000000000..820056ba05d --- /dev/null +++ b/compiler/testData/diagnostics/tests/multiplatform/exhaustiveness/sealedHierarchyInBambooMppStructure.fir.kt @@ -0,0 +1,29 @@ +// LANGUAGE: +MultiPlatformProjects +// ISSUE: KT-46031 + +// MODULE: common-a +// TARGET_PLATFORM: Common + +expect sealed class Base() +class A : Base() // OK, A in same module with Base + +// MODULE: common-b()()(common-a) +// TARGET_PLATFORM: Common + +class B : Base() // OK, B inherits `expect` class, not `actual` + +// MODULE: common-c()()(common-b) +// TARGET_PLATFORM: Common + +actual sealed class Base actual constructor() +class C : Base() // OK, C in same module with actual Base + +// MODULE: common-d()()(common-c) +// TARGET_PLATFORM: Common + +class D : Base() // Error, D not in same module with actual Base + +// MODULE: jvm()()(common-d) +// TARGET_PLATFORM: JVM + +class E : Base() // Error, E not in same module with actual Base diff --git a/compiler/testData/diagnostics/tests/multiplatform/exhaustiveness/sealedHierarchyInBambooMppStructure.kt b/compiler/testData/diagnostics/tests/multiplatform/exhaustiveness/sealedHierarchyInBambooMppStructure.kt new file mode 100644 index 00000000000..fb3dea1a483 --- /dev/null +++ b/compiler/testData/diagnostics/tests/multiplatform/exhaustiveness/sealedHierarchyInBambooMppStructure.kt @@ -0,0 +1,29 @@ +// LANGUAGE: +MultiPlatformProjects +// ISSUE: KT-46031 + +// MODULE: common-a +// TARGET_PLATFORM: Common + +expect sealed class Base() +class A : Base() // OK, A in same module with Base + +// MODULE: common-b()()(common-a) +// TARGET_PLATFORM: Common + +class B : Base() // OK, B inherits `expect` class, not `actual` + +// MODULE: common-c()()(common-b) +// TARGET_PLATFORM: Common + +actual sealed class Base actual constructor() +class C : Base() // OK, C in same module with actual Base + +// MODULE: common-d()()(common-c) +// TARGET_PLATFORM: Common + +class D : Base() // Error, D not in same module with actual Base + +// MODULE: jvm()()(common-d) +// TARGET_PLATFORM: JVM + +class E : Base() // Error, E not in same module with actual Base diff --git a/compiler/testData/diagnostics/tests/multiplatform/hmpp/multiplatformCompositeAnalysis/sealedInheritorsInComplexModuleStructure.fir.kt b/compiler/testData/diagnostics/tests/multiplatform/hmpp/multiplatformCompositeAnalysis/sealedInheritorsInComplexModuleStructure.fir.kt index f7e2a4f45d4..85dcf1cdc33 100644 --- a/compiler/testData/diagnostics/tests/multiplatform/hmpp/multiplatformCompositeAnalysis/sealedInheritorsInComplexModuleStructure.fir.kt +++ b/compiler/testData/diagnostics/tests/multiplatform/hmpp/multiplatformCompositeAnalysis/sealedInheritorsInComplexModuleStructure.fir.kt @@ -12,7 +12,7 @@ expect sealed class SealedWithPlatformActuals : SealedWithSharedActual package foo actual sealed class SealedWithSharedActual -class SimpleShared : SealedWithPlatformActuals() +class SimpleShared : SealedWithPlatformActuals() // MODULE: main()()(intermediate) // TARGET_PLATFORM: JVM 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 4f2fe12d715..22cc56453ff 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 @@ -23952,6 +23952,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { public void testKt45796() throws Exception { runTest("compiler/testData/diagnostics/tests/multiplatform/exhaustiveness/kt45796.kt"); } + + @Test + @TestMetadata("sealedHierarchyInBambooMppStructure.kt") + public void testSealedHierarchyInBambooMppStructure() throws Exception { + runTest("compiler/testData/diagnostics/tests/multiplatform/exhaustiveness/sealedHierarchyInBambooMppStructure.kt"); + } } @Nested