[FIR] Add checker for EXPANSIVE_INHERITANCE

^KT-59402 Fixed
This commit is contained in:
Brian Norman
2023-10-20 15:10:28 -05:00
committed by Space Team
parent a991a13295
commit e9983a947f
19 changed files with 266 additions and 68 deletions
@@ -461,8 +461,7 @@ internal class KtSymbolByFirBuilder constructor(
// TODO this is a temporary hack to prevent FIR IDE from crashing on builder inference, see KT-50916
val typeVariable = coneType.constructor.variable as? ConeTypeParameterBasedTypeVariable
val typeParameterSymbol = typeVariable?.typeParameterSymbol ?: throwUnexpectedElementError(coneType)
val coneTypeParameterType = (typeParameterSymbol.toConeType() as ConeTypeParameterType)
.withNullability(coneType.nullability, rootSession.typeContext)
val coneTypeParameterType = typeParameterSymbol.toConeType(coneType.nullability.isNullable)
KtFirTypeParameterType(coneTypeParameterType, this@KtSymbolByFirBuilder)
}
@@ -2427,6 +2427,21 @@ internal val KT_DIAGNOSTIC_CONVERTER = KtDiagnosticConverterBuilder.buildConvert
token,
)
}
add(FirErrors.EXPANSIVE_INHERITANCE) { firDiagnostic ->
ExpansiveInheritanceImpl(
firDiagnostic as KtPsiDiagnostic,
token,
)
}
add(FirErrors.EXPANSIVE_INHERITANCE_IN_JAVA) { firDiagnostic ->
ExpansiveInheritanceInJavaImpl(
firDiagnostic.a.map { firBasedSymbol ->
firSymbolBuilder.buildSymbol(firBasedSymbol)
},
firDiagnostic as KtPsiDiagnostic,
token,
)
}
add(FirErrors.DEPRECATED_TYPE_PARAMETER_SYNTAX) { firDiagnostic ->
DeprecatedTypeParameterSyntaxImpl(
firDiagnostic as KtPsiDiagnostic,
@@ -1723,6 +1723,15 @@ sealed interface KtFirDiagnostic<PSI : PsiElement> : KtDiagnosticWithPsi<PSI> {
val containingTypes: List<KtSymbol>
}
interface ExpansiveInheritance : KtFirDiagnostic<PsiElement> {
override val diagnosticClass get() = ExpansiveInheritance::class
}
interface ExpansiveInheritanceInJava : KtFirDiagnostic<PsiElement> {
override val diagnosticClass get() = ExpansiveInheritanceInJava::class
val containingTypes: List<KtSymbol>
}
interface DeprecatedTypeParameterSyntax : KtFirDiagnostic<KtDeclaration> {
override val diagnosticClass get() = DeprecatedTypeParameterSyntax::class
}
@@ -2072,6 +2072,17 @@ internal class FiniteBoundsViolationInJavaImpl(
token: KtLifetimeToken,
) : KtAbstractFirDiagnostic<PsiElement>(firDiagnostic, token), KtFirDiagnostic.FiniteBoundsViolationInJava
internal class ExpansiveInheritanceImpl(
firDiagnostic: KtPsiDiagnostic,
token: KtLifetimeToken,
) : KtAbstractFirDiagnostic<PsiElement>(firDiagnostic, token), KtFirDiagnostic.ExpansiveInheritance
internal class ExpansiveInheritanceInJavaImpl(
override val containingTypes: List<KtSymbol>,
firDiagnostic: KtPsiDiagnostic,
token: KtLifetimeToken,
) : KtAbstractFirDiagnostic<PsiElement>(firDiagnostic, token), KtFirDiagnostic.ExpansiveInheritanceInJava
internal class DeprecatedTypeParameterSyntaxImpl(
firDiagnostic: KtPsiDiagnostic,
token: KtLifetimeToken,