FIR checker: ILLEGAL_DECLARATION_IN_WHEN_SUBJECT

This commit is contained in:
Tianyu Geng
2021-06-22 15:35:15 -07:00
committed by Mikhail Glukhikh
parent 31573a98e8
commit 768ddea18f
8 changed files with 68 additions and 6 deletions
@@ -2379,7 +2379,7 @@ internal val KT_DIAGNOSTIC_CONVERTER = KtDiagnosticConverterBuilder.buildConvert
}
add(FirErrors.EXPECTED_CONDITION) { firDiagnostic ->
ExpectedConditionImpl(
firDiagnostic as FirPsiDiagnostic<*>,
firDiagnostic as FirPsiDiagnostic,
token,
)
}
@@ -2404,6 +2404,13 @@ internal val KT_DIAGNOSTIC_CONVERTER = KtDiagnosticConverterBuilder.buildConvert
token,
)
}
add(FirErrors.ILLEGAL_DECLARATION_IN_WHEN_SUBJECT) { firDiagnostic ->
IllegalDeclarationInWhenSubjectImpl(
firDiagnostic.a,
firDiagnostic as FirPsiDiagnostic,
token,
)
}
add(FirErrors.TYPE_PARAMETER_IS_NOT_AN_EXPRESSION) { firDiagnostic ->
TypeParameterIsNotAnExpressionImpl(
firSymbolBuilder.classifierBuilder.buildTypeParameterSymbol(firDiagnostic.a.fir),
@@ -1693,6 +1693,11 @@ sealed class KtFirDiagnostic<PSI: PsiElement> : KtDiagnosticWithPsi<PSI> {
override val diagnosticClass get() = ElseMisplacedInWhen::class
}
abstract class IllegalDeclarationInWhenSubject : KtFirDiagnostic<KtElement>() {
override val diagnosticClass get() = IllegalDeclarationInWhenSubject::class
abstract val illegalReason: String
}
abstract class TypeParameterIsNotAnExpression : KtFirDiagnostic<KtSimpleNameExpression>() {
override val diagnosticClass get() = TypeParameterIsNotAnExpression::class
abstract val typeParameter: KtTypeParameterSymbol
@@ -2710,10 +2710,10 @@ internal class UselessIsCheckImpl(
}
internal class ExpectedConditionImpl(
firDiagnostic: FirPsiDiagnostic<*>,
firDiagnostic: FirPsiDiagnostic,
override val token: ValidityToken,
) : KtFirDiagnostic.ExpectedCondition(), KtAbstractFirDiagnostic<KtWhenCondition> {
override val firDiagnostic: FirPsiDiagnostic<*> by weakRef(firDiagnostic)
override val firDiagnostic: FirPsiDiagnostic by weakRef(firDiagnostic)
}
internal class NoElseInWhenImpl(
@@ -2738,6 +2738,14 @@ internal class ElseMisplacedInWhenImpl(
override val firDiagnostic: FirPsiDiagnostic by weakRef(firDiagnostic)
}
internal class IllegalDeclarationInWhenSubjectImpl(
override val illegalReason: String,
firDiagnostic: FirPsiDiagnostic,
override val token: ValidityToken,
) : KtFirDiagnostic.IllegalDeclarationInWhenSubject(), KtAbstractFirDiagnostic<KtElement> {
override val firDiagnostic: FirPsiDiagnostic by weakRef(firDiagnostic)
}
internal class TypeParameterIsNotAnExpressionImpl(
override val typeParameter: KtTypeParameterSymbol,
firDiagnostic: FirPsiDiagnostic,