[FIR] Prohibit calling functions with dynamic receiver over non-dynamics

^KT-63071 Fixed
This commit is contained in:
Nikolay Lunyak
2023-11-28 12:08:05 +02:00
committed by Space Team
parent c69c34ff8b
commit 875e2b0cd6
16 changed files with 61 additions and 11 deletions
@@ -2467,6 +2467,13 @@ internal val KT_DIAGNOSTIC_CONVERTER = KtDiagnosticConverterBuilder.buildConvert
token,
)
}
add(FirErrors.DYNAMIC_RECEIVER_EXPECTED_BUT_WAS_NON_DYNAMIC) { firDiagnostic ->
DynamicReceiverExpectedButWasNonDynamicImpl(
firSymbolBuilder.typeBuilder.buildKtType(firDiagnostic.a),
firDiagnostic as KtPsiDiagnostic,
token,
)
}
add(FirErrors.INCOMPATIBLE_TYPES) { firDiagnostic ->
IncompatibleTypesImpl(
firSymbolBuilder.typeBuilder.buildKtType(firDiagnostic.a),
@@ -1748,6 +1748,11 @@ sealed interface KtFirDiagnostic<PSI : PsiElement> : KtDiagnosticWithPsi<PSI> {
override val diagnosticClass get() = DynamicReceiverNotAllowed::class
}
interface DynamicReceiverExpectedButWasNonDynamic : KtFirDiagnostic<PsiElement> {
override val diagnosticClass get() = DynamicReceiverExpectedButWasNonDynamic::class
val actualType: KtType
}
interface IncompatibleTypes : KtFirDiagnostic<KtElement> {
override val diagnosticClass get() = IncompatibleTypes::class
val typeA: KtType
@@ -2103,6 +2103,12 @@ internal class DynamicReceiverNotAllowedImpl(
token: KtLifetimeToken,
) : KtAbstractFirDiagnostic<KtElement>(firDiagnostic, token), KtFirDiagnostic.DynamicReceiverNotAllowed
internal class DynamicReceiverExpectedButWasNonDynamicImpl(
override val actualType: KtType,
firDiagnostic: KtPsiDiagnostic,
token: KtLifetimeToken,
) : KtAbstractFirDiagnostic<PsiElement>(firDiagnostic, token), KtFirDiagnostic.DynamicReceiverExpectedButWasNonDynamic
internal class IncompatibleTypesImpl(
override val typeA: KtType,
override val typeB: KtType,