[FIR] Implement checks for contract not allowed

^KT-55423 Fixed
This commit is contained in:
Kirill Rakhman
2023-02-08 12:03:36 +01:00
committed by Space Team
parent b2fbf8bed5
commit f946ddeb40
50 changed files with 377 additions and 178 deletions
@@ -3678,6 +3678,13 @@ internal val KT_DIAGNOSTIC_CONVERTER = KtDiagnosticConverterBuilder.buildConvert
token,
)
}
add(FirErrors.CONTRACT_NOT_ALLOWED) { firDiagnostic ->
ContractNotAllowedImpl(
firDiagnostic.a,
firDiagnostic as KtPsiDiagnostic,
token,
)
}
add(FirErrors.NO_GET_METHOD) { firDiagnostic ->
NoGetMethodImpl(
firDiagnostic as KtPsiDiagnostic,
@@ -2567,6 +2567,11 @@ sealed class KtFirDiagnostic<PSI : PsiElement> : KtDiagnosticWithPsi<PSI> {
abstract val reason: String
}
abstract class ContractNotAllowed : KtFirDiagnostic<KtElement>() {
override val diagnosticClass get() = ContractNotAllowed::class
abstract val reason: String
}
abstract class NoGetMethod : KtFirDiagnostic<KtArrayAccessExpression>() {
override val diagnosticClass get() = NoGetMethod::class
}
@@ -3096,6 +3096,12 @@ internal class ErrorInContractDescriptionImpl(
override val token: KtLifetimeToken,
) : KtFirDiagnostic.ErrorInContractDescription(), KtAbstractFirDiagnostic<KtElement>
internal class ContractNotAllowedImpl(
override val reason: String,
override val firDiagnostic: KtPsiDiagnostic,
override val token: KtLifetimeToken,
) : KtFirDiagnostic.ContractNotAllowed(), KtAbstractFirDiagnostic<KtElement>
internal class NoGetMethodImpl(
override val firDiagnostic: KtPsiDiagnostic,
override val token: KtLifetimeToken,
@@ -107,6 +107,7 @@ internal object FirLazyBodiesCalculator {
constructor.apply {
replaceBody(newConstructor.body)
replaceContractDescription(newConstructor.contractDescription)
replaceDelegatedConstructor(newConstructor.delegatedConstructor)
replaceValueParameterDefaultValues(valueParameters, newConstructor.valueParameters)
}