FIR: check subclass of sealed class

This commit is contained in:
Tianyu Geng
2021-06-25 17:39:35 -07:00
committed by TeamCityServer
parent ed152e74a0
commit 10d4dfef04
18 changed files with 110 additions and 66 deletions
@@ -450,6 +450,26 @@ internal val KT_DIAGNOSTIC_CONVERTER = KtDiagnosticConverterBuilder.buildConvert
token,
)
}
add(FirErrors.SEALED_INHERITOR_IN_DIFFERENT_PACKAGE) { firDiagnostic ->
SealedInheritorInDifferentPackageImpl(
firDiagnostic.a,
firDiagnostic.b,
firDiagnostic as FirPsiDiagnostic,
token,
)
}
add(FirErrors.SEALED_INHERITOR_IN_DIFFERENT_MODULE) { firDiagnostic ->
SealedInheritorInDifferentModuleImpl(
firDiagnostic as FirPsiDiagnostic,
token,
)
}
add(FirErrors.CLASS_INHERITS_JAVA_SEALED_CLASS) { firDiagnostic ->
ClassInheritsJavaSealedClassImpl(
firDiagnostic as FirPsiDiagnostic,
token,
)
}
add(FirErrors.SUPERTYPE_NOT_A_CLASS_OR_INTERFACE) { firDiagnostic ->
SupertypeNotAClassOrInterfaceImpl(
firDiagnostic.a,
@@ -341,6 +341,20 @@ sealed class KtFirDiagnostic<PSI : PsiElement> : KtDiagnosticWithPsi<PSI> {
override val diagnosticClass get() = SealedSupertypeInLocalClass::class
}
abstract class SealedInheritorInDifferentPackage : KtFirDiagnostic<KtTypeReference>() {
override val diagnosticClass get() = SealedInheritorInDifferentPackage::class
abstract val subclassPackage: FqName
abstract val basePackage: FqName
}
abstract class SealedInheritorInDifferentModule : KtFirDiagnostic<KtTypeReference>() {
override val diagnosticClass get() = SealedInheritorInDifferentModule::class
}
abstract class ClassInheritsJavaSealedClass : KtFirDiagnostic<KtTypeReference>() {
override val diagnosticClass get() = ClassInheritsJavaSealedClass::class
}
abstract class SupertypeNotAClassOrInterface : KtFirDiagnostic<KtElement>() {
override val diagnosticClass get() = SupertypeNotAClassOrInterface::class
abstract val reason: String
@@ -522,6 +522,29 @@ internal class SealedSupertypeInLocalClassImpl(
override val firDiagnostic: FirPsiDiagnostic by weakRef(firDiagnostic)
}
internal class SealedInheritorInDifferentPackageImpl(
override val subclassPackage: FqName,
override val basePackage: FqName,
firDiagnostic: FirPsiDiagnostic,
override val token: ValidityToken,
) : KtFirDiagnostic.SealedInheritorInDifferentPackage(), KtAbstractFirDiagnostic<KtTypeReference> {
override val firDiagnostic: FirPsiDiagnostic by weakRef(firDiagnostic)
}
internal class SealedInheritorInDifferentModuleImpl(
firDiagnostic: FirPsiDiagnostic,
override val token: ValidityToken,
) : KtFirDiagnostic.SealedInheritorInDifferentModule(), KtAbstractFirDiagnostic<KtTypeReference> {
override val firDiagnostic: FirPsiDiagnostic by weakRef(firDiagnostic)
}
internal class ClassInheritsJavaSealedClassImpl(
firDiagnostic: FirPsiDiagnostic,
override val token: ValidityToken,
) : KtFirDiagnostic.ClassInheritsJavaSealedClass(), KtAbstractFirDiagnostic<KtTypeReference> {
override val firDiagnostic: FirPsiDiagnostic by weakRef(firDiagnostic)
}
internal class SupertypeNotAClassOrInterfaceImpl(
override val reason: String,
firDiagnostic: FirPsiDiagnostic,