[FIR] Report NON_EXHAUSTIVE_WHEN_STATEMENT/NO_ELSE_IN_WHEN for when's on logical types

^KT-47709 In Progress
This commit is contained in:
Dmitriy Novozhilov
2021-07-13 13:15:49 +03:00
committed by teamcityserver
parent ef635f6a96
commit a6edd852ff
38 changed files with 120 additions and 431 deletions
@@ -2649,6 +2649,16 @@ internal val KT_DIAGNOSTIC_CONVERTER = KtDiagnosticConverterBuilder.buildConvert
token,
)
}
add(FirErrors.NON_EXHAUSTIVE_WHEN_STATEMENT) { firDiagnostic ->
NonExhaustiveWhenStatementImpl(
firDiagnostic.a,
firDiagnostic.b.map { whenMissingCase ->
whenMissingCase
},
firDiagnostic as FirPsiDiagnostic,
token,
)
}
add(FirErrors.INVALID_IF_AS_EXPRESSION) { firDiagnostic ->
InvalidIfAsExpressionImpl(
firDiagnostic as FirPsiDiagnostic,
@@ -1855,6 +1855,12 @@ sealed class KtFirDiagnostic<PSI : PsiElement> : KtDiagnosticWithPsi<PSI> {
abstract val missingWhenCases: List<WhenMissingCase>
}
abstract class NonExhaustiveWhenStatement : KtFirDiagnostic<KtWhenExpression>() {
override val diagnosticClass get() = NonExhaustiveWhenStatement::class
abstract val type: String
abstract val missingWhenCases: List<WhenMissingCase>
}
abstract class InvalidIfAsExpression : KtFirDiagnostic<KtIfExpression>() {
override val diagnosticClass get() = InvalidIfAsExpression::class
}
@@ -2990,6 +2990,15 @@ internal class NoElseInWhenImpl(
override val firDiagnostic: FirPsiDiagnostic by weakRef(firDiagnostic)
}
internal class NonExhaustiveWhenStatementImpl(
override val type: String,
override val missingWhenCases: List<WhenMissingCase>,
firDiagnostic: FirPsiDiagnostic,
override val token: ValidityToken,
) : KtFirDiagnostic.NonExhaustiveWhenStatement(), KtAbstractFirDiagnostic<KtWhenExpression> {
override val firDiagnostic: FirPsiDiagnostic by weakRef(firDiagnostic)
}
internal class InvalidIfAsExpressionImpl(
firDiagnostic: FirPsiDiagnostic,
override val token: ValidityToken,