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 595b9d53c67..a749607bd97 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 @@ -109,6 +109,12 @@ public class FirOldFrontendMPPDiagnosticsWithLightTreeTestGenerated extends Abst runTest("compiler/testData/diagnostics/tests/multiplatform/privateTopLevelDeclarations.kt"); } + @Test + @TestMetadata("sealedClassWithPrivateConstructor.kt") + public void testSealedClassWithPrivateConstructor() throws Exception { + runTest("compiler/testData/diagnostics/tests/multiplatform/sealedClassWithPrivateConstructor.kt"); + } + @Test @TestMetadata("sealedTypeAlias.kt") public void testSealedTypeAlias() throws Exception { 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 131564738d8..2c0d779f6d8 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 @@ -109,6 +109,12 @@ public class FirOldFrontendMPPDiagnosticsWithPsiTestGenerated extends AbstractFi runTest("compiler/testData/diagnostics/tests/multiplatform/privateTopLevelDeclarations.kt"); } + @Test + @TestMetadata("sealedClassWithPrivateConstructor.kt") + public void testSealedClassWithPrivateConstructor() throws Exception { + runTest("compiler/testData/diagnostics/tests/multiplatform/sealedClassWithPrivateConstructor.kt"); + } + @Test @TestMetadata("sealedTypeAlias.kt") public void testSealedTypeAlias() throws Exception { diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirConstructorAllowedChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirConstructorAllowedChecker.kt index e84e9b50948..0f3c8ec9a99 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirConstructorAllowedChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirConstructorAllowedChecker.kt @@ -39,7 +39,8 @@ object FirConstructorAllowedChecker : FirConstructorChecker() { ClassKind.CLASS -> if (containingClass is FirRegularClass && containingClass.modality == Modality.SEALED) { val modifierList = source.getModifierList() ?: return val hasIllegalModifier = modifierList.modifiers.any { - it.token != KtTokens.PROTECTED_KEYWORD && it.token != KtTokens.PRIVATE_KEYWORD + val token = it.token + token in KtTokens.VISIBILITY_MODIFIERS && token != KtTokens.PROTECTED_KEYWORD && token != KtTokens.PRIVATE_KEYWORD } if (hasIllegalModifier) { reporter.reportOn(source, FirErrors.NON_PRIVATE_OR_PROTECTED_CONSTRUCTOR_IN_SEALED, context) 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 03d8d7876d0..f7e2a4f45d4 100644 --- a/compiler/testData/diagnostics/tests/multiplatform/hmpp/multiplatformCompositeAnalysis/sealedInheritorsInComplexModuleStructure.fir.kt +++ b/compiler/testData/diagnostics/tests/multiplatform/hmpp/multiplatformCompositeAnalysis/sealedInheritorsInComplexModuleStructure.fir.kt @@ -18,4 +18,4 @@ class SimpleShared : actual constructor(): SealedWithSharedActual() +actual sealed class SealedWithPlatformActuals actual constructor(): SealedWithSharedActual() diff --git a/compiler/testData/diagnostics/tests/multiplatform/sealedClassWithPrivateConstructor.kt b/compiler/testData/diagnostics/tests/multiplatform/sealedClassWithPrivateConstructor.kt new file mode 100644 index 00000000000..d86ca746282 --- /dev/null +++ b/compiler/testData/diagnostics/tests/multiplatform/sealedClassWithPrivateConstructor.kt @@ -0,0 +1,11 @@ +// FIR_IDENTICAL +// ISSUE: KT-58033 +// MODULE: m1-common +// FILE: common.kt + +expect sealed class Frame private constructor() + +// MODULE: m2-jvm()()(m1-common) +// FILE: jvm.kt + +actual sealed class Frame actual constructor() 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 72b150b6d27..1ce5e3dc603 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 @@ -21930,6 +21930,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/tests/multiplatform/privateTopLevelDeclarations.kt"); } + @Test + @TestMetadata("sealedClassWithPrivateConstructor.kt") + public void testSealedClassWithPrivateConstructor() throws Exception { + runTest("compiler/testData/diagnostics/tests/multiplatform/sealedClassWithPrivateConstructor.kt"); + } + @Test @TestMetadata("sealedTypeAlias.kt") public void testSealedTypeAlias() throws Exception {