[FIR] Properly report SEALED_INHERITOR_IN_DIFFERENT_MODULE
^KT-46031 Fixed ^KT-59804 Fixed
This commit is contained in:
committed by
Space Team
parent
387898056a
commit
de68ec7cd5
+6
@@ -1083,6 +1083,12 @@ public class FirOldFrontendMPPDiagnosticsWithLightTreeTestGenerated extends Abst
|
|||||||
public void testKt45796() throws Exception {
|
public void testKt45796() throws Exception {
|
||||||
runTest("compiler/testData/diagnostics/tests/multiplatform/exhaustiveness/kt45796.kt");
|
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
|
@Nested
|
||||||
|
|||||||
+6
@@ -1083,6 +1083,12 @@ public class FirOldFrontendMPPDiagnosticsWithPsiTestGenerated extends AbstractFi
|
|||||||
public void testKt45796() throws Exception {
|
public void testKt45796() throws Exception {
|
||||||
runTest("compiler/testData/diagnostics/tests/multiplatform/exhaustiveness/kt45796.kt");
|
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
|
@Nested
|
||||||
|
|||||||
+2
-2
@@ -14,6 +14,7 @@ import org.jetbrains.kotlin.fir.declarations.FirAnonymousObject
|
|||||||
import org.jetbrains.kotlin.fir.declarations.FirClass
|
import org.jetbrains.kotlin.fir.declarations.FirClass
|
||||||
import org.jetbrains.kotlin.fir.declarations.FirDeclarationOrigin
|
import org.jetbrains.kotlin.fir.declarations.FirDeclarationOrigin
|
||||||
import org.jetbrains.kotlin.fir.declarations.utils.classId
|
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.isSealed
|
||||||
import org.jetbrains.kotlin.fir.declarations.utils.modality
|
import org.jetbrains.kotlin.fir.declarations.utils.modality
|
||||||
import org.jetbrains.kotlin.fir.resolve.providers.symbolProvider
|
import org.jetbrains.kotlin.fir.resolve.providers.symbolProvider
|
||||||
@@ -51,8 +52,7 @@ object FirSealedSupertypeChecker : FirClassChecker() {
|
|||||||
if (superClassPackage != subclassPackage) {
|
if (superClassPackage != subclassPackage) {
|
||||||
reporter.reportOn(superTypeRef.source, FirErrors.SEALED_INHERITOR_IN_DIFFERENT_PACKAGE, context)
|
reporter.reportOn(superTypeRef.source, FirErrors.SEALED_INHERITOR_IN_DIFFERENT_PACKAGE, context)
|
||||||
}
|
}
|
||||||
if (superClass.moduleData != declaration.moduleData) {
|
if (superClass.moduleData != declaration.moduleData && !superClass.isExpect) {
|
||||||
// TODO, KT-59804: implement logic like in org.jetbrains.kotlin.resolve.checkers.SealedInheritorInSameModuleChecker for MPP support.
|
|
||||||
reporter.reportOn(superTypeRef.source, FirErrors.SEALED_INHERITOR_IN_DIFFERENT_MODULE, context)
|
reporter.reportOn(superTypeRef.source, FirErrors.SEALED_INHERITOR_IN_DIFFERENT_MODULE, context)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+29
@@ -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 : <!SEALED_INHERITOR_IN_DIFFERENT_MODULE!>Base<!>() // Error, D not in same module with actual Base
|
||||||
|
|
||||||
|
// MODULE: jvm()()(common-d)
|
||||||
|
// TARGET_PLATFORM: JVM
|
||||||
|
|
||||||
|
class E : <!SEALED_INHERITOR_IN_DIFFERENT_MODULE!>Base<!>() // Error, E not in same module with actual Base
|
||||||
+29
@@ -0,0 +1,29 @@
|
|||||||
|
// LANGUAGE: +MultiPlatformProjects
|
||||||
|
// ISSUE: KT-46031
|
||||||
|
|
||||||
|
// MODULE: common-a
|
||||||
|
// TARGET_PLATFORM: Common
|
||||||
|
|
||||||
|
expect sealed <!EXPECT_AND_ACTUAL_IN_THE_SAME_MODULE{COMMON}, EXPECT_AND_ACTUAL_IN_THE_SAME_MODULE{COMMON}!>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 <!EXPECT_AND_ACTUAL_IN_THE_SAME_MODULE, EXPECT_AND_ACTUAL_IN_THE_SAME_MODULE{COMMON}!>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 : <!SEALED_INHERITOR_IN_DIFFERENT_MODULE!>Base<!>() // Error, D not in same module with actual Base
|
||||||
|
|
||||||
|
// MODULE: jvm()()(common-d)
|
||||||
|
// TARGET_PLATFORM: JVM
|
||||||
|
|
||||||
|
class E : <!SEALED_INHERITOR_IN_DIFFERENT_MODULE!>Base<!>() // Error, E not in same module with actual Base
|
||||||
+1
-1
@@ -12,7 +12,7 @@ expect sealed class SealedWithPlatformActuals : SealedWithSharedActual
|
|||||||
package foo
|
package foo
|
||||||
|
|
||||||
actual sealed class SealedWithSharedActual
|
actual sealed class SealedWithSharedActual
|
||||||
class SimpleShared : <!SEALED_INHERITOR_IN_DIFFERENT_MODULE, UNRESOLVED_REFERENCE!>SealedWithPlatformActuals<!>()
|
class SimpleShared : <!UNRESOLVED_REFERENCE!>SealedWithPlatformActuals<!>()
|
||||||
|
|
||||||
// MODULE: main()()(intermediate)
|
// MODULE: main()()(intermediate)
|
||||||
// TARGET_PLATFORM: JVM
|
// TARGET_PLATFORM: JVM
|
||||||
|
|||||||
Generated
+6
@@ -23952,6 +23952,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
|||||||
public void testKt45796() throws Exception {
|
public void testKt45796() throws Exception {
|
||||||
runTest("compiler/testData/diagnostics/tests/multiplatform/exhaustiveness/kt45796.kt");
|
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
|
@Nested
|
||||||
|
|||||||
Reference in New Issue
Block a user