[FIR] Check only for visibility modifiers for NON_PRIVATE_OR_PROTECTED_CONSTRUCTOR_IN_SEALED error

^KT-58033 Fixed
This commit is contained in:
Dmitriy Novozhilov
2023-04-18 17:17:00 +03:00
committed by Space Team
parent 8314812ef9
commit 6544220b3e
6 changed files with 32 additions and 2 deletions
@@ -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 {
@@ -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 {
@@ -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)
@@ -18,4 +18,4 @@ class SimpleShared : <!SEALED_INHERITOR_IN_DIFFERENT_MODULE, UNRESOLVED_REFERENC
// TARGET_PLATFORM: JVM
package foo
actual sealed class SealedWithPlatformActuals <!ACTUAL_WITHOUT_EXPECT, NON_PRIVATE_OR_PROTECTED_CONSTRUCTOR_IN_SEALED!>actual constructor()<!>: <!SEALED_INHERITOR_IN_DIFFERENT_MODULE!>SealedWithSharedActual<!>()
actual sealed class SealedWithPlatformActuals <!ACTUAL_WITHOUT_EXPECT!>actual constructor()<!>: <!SEALED_INHERITOR_IN_DIFFERENT_MODULE!>SealedWithSharedActual<!>()
@@ -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()
@@ -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 {