FIR checker: improve diagnostics message for SEALED_INHERITOR_IN_DIFFERENT_PACKAGE
This commit is contained in:
committed by
TeamCityServer
parent
10d4dfef04
commit
1e8e38e5ac
+1
-4
@@ -160,10 +160,7 @@ object DIAGNOSTICS_LIST : DiagnosticList("FirErrors") {
|
|||||||
val CLASS_IN_SUPERTYPE_FOR_ENUM by error<KtTypeReference>()
|
val CLASS_IN_SUPERTYPE_FOR_ENUM by error<KtTypeReference>()
|
||||||
val SEALED_SUPERTYPE by error<KtTypeReference>()
|
val SEALED_SUPERTYPE by error<KtTypeReference>()
|
||||||
val SEALED_SUPERTYPE_IN_LOCAL_CLASS by error<KtTypeReference>()
|
val SEALED_SUPERTYPE_IN_LOCAL_CLASS by error<KtTypeReference>()
|
||||||
val SEALED_INHERITOR_IN_DIFFERENT_PACKAGE by error<KtTypeReference> {
|
val SEALED_INHERITOR_IN_DIFFERENT_PACKAGE by error<KtTypeReference>()
|
||||||
parameter<FqName>("subclassPackage")
|
|
||||||
parameter<FqName>("basePackage")
|
|
||||||
}
|
|
||||||
val SEALED_INHERITOR_IN_DIFFERENT_MODULE by error<KtTypeReference>()
|
val SEALED_INHERITOR_IN_DIFFERENT_MODULE by error<KtTypeReference>()
|
||||||
val CLASS_INHERITS_JAVA_SEALED_CLASS by error<KtTypeReference>()
|
val CLASS_INHERITS_JAVA_SEALED_CLASS by error<KtTypeReference>()
|
||||||
val SUPERTYPE_NOT_A_CLASS_OR_INTERFACE by error<KtElement> {
|
val SUPERTYPE_NOT_A_CLASS_OR_INTERFACE by error<KtElement> {
|
||||||
|
|||||||
+1
-1
@@ -168,7 +168,7 @@ object FirErrors {
|
|||||||
val CLASS_IN_SUPERTYPE_FOR_ENUM by error0<KtTypeReference>()
|
val CLASS_IN_SUPERTYPE_FOR_ENUM by error0<KtTypeReference>()
|
||||||
val SEALED_SUPERTYPE by error0<KtTypeReference>()
|
val SEALED_SUPERTYPE by error0<KtTypeReference>()
|
||||||
val SEALED_SUPERTYPE_IN_LOCAL_CLASS by error0<KtTypeReference>()
|
val SEALED_SUPERTYPE_IN_LOCAL_CLASS by error0<KtTypeReference>()
|
||||||
val SEALED_INHERITOR_IN_DIFFERENT_PACKAGE by error2<KtTypeReference, FqName, FqName>()
|
val SEALED_INHERITOR_IN_DIFFERENT_PACKAGE by error0<KtTypeReference>()
|
||||||
val SEALED_INHERITOR_IN_DIFFERENT_MODULE by error0<KtTypeReference>()
|
val SEALED_INHERITOR_IN_DIFFERENT_MODULE by error0<KtTypeReference>()
|
||||||
val CLASS_INHERITS_JAVA_SEALED_CLASS by error0<KtTypeReference>()
|
val CLASS_INHERITS_JAVA_SEALED_CLASS by error0<KtTypeReference>()
|
||||||
val SUPERTYPE_NOT_A_CLASS_OR_INTERFACE by error1<KtElement, String>()
|
val SUPERTYPE_NOT_A_CLASS_OR_INTERFACE by error1<KtElement, String>()
|
||||||
|
|||||||
+1
-7
@@ -48,13 +48,7 @@ object FirSealedSupertypeChecker : FirClassChecker() {
|
|||||||
}
|
}
|
||||||
val superClassPackage = superClass.classId.packageFqName
|
val superClassPackage = superClass.classId.packageFqName
|
||||||
if (superClassPackage != subclassPackage) {
|
if (superClassPackage != subclassPackage) {
|
||||||
reporter.reportOn(
|
reporter.reportOn(superTypeRef.source, FirErrors.SEALED_INHERITOR_IN_DIFFERENT_PACKAGE, context)
|
||||||
superTypeRef.source,
|
|
||||||
FirErrors.SEALED_INHERITOR_IN_DIFFERENT_PACKAGE,
|
|
||||||
subclassPackage,
|
|
||||||
superClassPackage,
|
|
||||||
context
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
if (superClass.moduleData != declaration.moduleData) {
|
if (superClass.moduleData != declaration.moduleData) {
|
||||||
// TODO: implement logic like in org.jetbrains.kotlin.resolve.checkers.SealedInheritorInSameModuleChecker for MPP support.
|
// TODO: implement logic like in org.jetbrains.kotlin.resolve.checkers.SealedInheritorInSameModuleChecker for MPP support.
|
||||||
|
|||||||
+2
-7
@@ -573,14 +573,9 @@ class FirDefaultErrorMessages {
|
|||||||
map.put(CLASS_IN_SUPERTYPE_FOR_ENUM, "Enum class cannot inherit from classes")
|
map.put(CLASS_IN_SUPERTYPE_FOR_ENUM, "Enum class cannot inherit from classes")
|
||||||
map.put(SEALED_SUPERTYPE, "This type is sealed, so it can be inherited by only its own nested classes or objects")
|
map.put(SEALED_SUPERTYPE, "This type is sealed, so it can be inherited by only its own nested classes or objects")
|
||||||
map.put(SEALED_SUPERTYPE_IN_LOCAL_CLASS, "Local class cannot extend a sealed class")
|
map.put(SEALED_SUPERTYPE_IN_LOCAL_CLASS, "Local class cannot extend a sealed class")
|
||||||
map.put(
|
map.put(SEALED_INHERITOR_IN_DIFFERENT_PACKAGE, "A class can only inherit from a sealed class or interface declared in the same package")
|
||||||
SEALED_INHERITOR_IN_DIFFERENT_PACKAGE,
|
|
||||||
"Inheritor of sealed class or interface declared in package {0} but it must be in package {1} where base class is declared",
|
|
||||||
TO_STRING,
|
|
||||||
TO_STRING
|
|
||||||
)
|
|
||||||
map.put(SEALED_INHERITOR_IN_DIFFERENT_MODULE, "Inheritance of sealed classes or interfaces from different module is prohibited")
|
map.put(SEALED_INHERITOR_IN_DIFFERENT_MODULE, "Inheritance of sealed classes or interfaces from different module is prohibited")
|
||||||
map.put(CLASS_INHERITS_JAVA_SEALED_CLASS, "Inheritance of java sealed classes is prohibited")
|
map.put(CLASS_INHERITS_JAVA_SEALED_CLASS, "Inheritance of Java sealed classes is prohibited")
|
||||||
|
|
||||||
map.put(SUPERTYPE_NOT_A_CLASS_OR_INTERFACE, "Supertype is not a class or interface", TO_STRING)
|
map.put(SUPERTYPE_NOT_A_CLASS_OR_INTERFACE, "Supertype is not a class or interface", TO_STRING)
|
||||||
map.put(CYCLIC_INHERITANCE_HIERARCHY, "There's a cycle in the inheritance hierarchy for this type")
|
map.put(CYCLIC_INHERITANCE_HIERARCHY, "There's a cycle in the inheritance hierarchy for this type")
|
||||||
|
|||||||
-2
@@ -452,8 +452,6 @@ internal val KT_DIAGNOSTIC_CONVERTER = KtDiagnosticConverterBuilder.buildConvert
|
|||||||
}
|
}
|
||||||
add(FirErrors.SEALED_INHERITOR_IN_DIFFERENT_PACKAGE) { firDiagnostic ->
|
add(FirErrors.SEALED_INHERITOR_IN_DIFFERENT_PACKAGE) { firDiagnostic ->
|
||||||
SealedInheritorInDifferentPackageImpl(
|
SealedInheritorInDifferentPackageImpl(
|
||||||
firDiagnostic.a,
|
|
||||||
firDiagnostic.b,
|
|
||||||
firDiagnostic as FirPsiDiagnostic,
|
firDiagnostic as FirPsiDiagnostic,
|
||||||
token,
|
token,
|
||||||
)
|
)
|
||||||
|
|||||||
-2
@@ -343,8 +343,6 @@ sealed class KtFirDiagnostic<PSI : PsiElement> : KtDiagnosticWithPsi<PSI> {
|
|||||||
|
|
||||||
abstract class SealedInheritorInDifferentPackage : KtFirDiagnostic<KtTypeReference>() {
|
abstract class SealedInheritorInDifferentPackage : KtFirDiagnostic<KtTypeReference>() {
|
||||||
override val diagnosticClass get() = SealedInheritorInDifferentPackage::class
|
override val diagnosticClass get() = SealedInheritorInDifferentPackage::class
|
||||||
abstract val subclassPackage: FqName
|
|
||||||
abstract val basePackage: FqName
|
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract class SealedInheritorInDifferentModule : KtFirDiagnostic<KtTypeReference>() {
|
abstract class SealedInheritorInDifferentModule : KtFirDiagnostic<KtTypeReference>() {
|
||||||
|
|||||||
-2
@@ -523,8 +523,6 @@ internal class SealedSupertypeInLocalClassImpl(
|
|||||||
}
|
}
|
||||||
|
|
||||||
internal class SealedInheritorInDifferentPackageImpl(
|
internal class SealedInheritorInDifferentPackageImpl(
|
||||||
override val subclassPackage: FqName,
|
|
||||||
override val basePackage: FqName,
|
|
||||||
firDiagnostic: FirPsiDiagnostic,
|
firDiagnostic: FirPsiDiagnostic,
|
||||||
override val token: ValidityToken,
|
override val token: ValidityToken,
|
||||||
) : KtFirDiagnostic.SealedInheritorInDifferentPackage(), KtAbstractFirDiagnostic<KtTypeReference> {
|
) : KtFirDiagnostic.SealedInheritorInDifferentPackage(), KtAbstractFirDiagnostic<KtTypeReference> {
|
||||||
|
|||||||
Reference in New Issue
Block a user