FIR checker: record whether type mismatch is due to nullability
This is useful for downstream quickfixes.
This commit is contained in:
committed by
teamcityserver
parent
d3e8cc577c
commit
951812f130
+1
-1
@@ -36,7 +36,7 @@ internal class KtFirBuiltInTypes(builtinTypes: BuiltinTypes, builder: KtSymbolBy
|
||||
override val NOTHING: KtType by cachedBuiltin(builtinTypes.nothingType)
|
||||
override val ANY: KtType by cachedBuiltin(builtinTypes.anyType)
|
||||
|
||||
|
||||
override val THROWABLE: KtType by cachedBuiltin(builtinTypes.throwableType)
|
||||
override val NULLABLE_ANY: KtType by cachedBuiltin(builtinTypes.nullableAnyType)
|
||||
override val NULLABLE_NOTHING: KtType by cachedBuiltin(builtinTypes.nullableNothingType)
|
||||
|
||||
|
||||
+7
@@ -1255,6 +1255,7 @@ internal val KT_DIAGNOSTIC_CONVERTER = KtDiagnosticConverterBuilder.buildConvert
|
||||
TypeMismatchImpl(
|
||||
firSymbolBuilder.typeBuilder.buildKtType(firDiagnostic.a),
|
||||
firSymbolBuilder.typeBuilder.buildKtType(firDiagnostic.b),
|
||||
firDiagnostic.c,
|
||||
firDiagnostic as FirPsiDiagnostic,
|
||||
token,
|
||||
)
|
||||
@@ -1262,6 +1263,7 @@ internal val KT_DIAGNOSTIC_CONVERTER = KtDiagnosticConverterBuilder.buildConvert
|
||||
add(FirErrors.THROWABLE_TYPE_MISMATCH) { firDiagnostic ->
|
||||
ThrowableTypeMismatchImpl(
|
||||
firSymbolBuilder.typeBuilder.buildKtType(firDiagnostic.a),
|
||||
firDiagnostic.b,
|
||||
firDiagnostic as FirPsiDiagnostic,
|
||||
token,
|
||||
)
|
||||
@@ -1269,6 +1271,7 @@ internal val KT_DIAGNOSTIC_CONVERTER = KtDiagnosticConverterBuilder.buildConvert
|
||||
add(FirErrors.CONDITION_TYPE_MISMATCH) { firDiagnostic ->
|
||||
ConditionTypeMismatchImpl(
|
||||
firSymbolBuilder.typeBuilder.buildKtType(firDiagnostic.a),
|
||||
firDiagnostic.b,
|
||||
firDiagnostic as FirPsiDiagnostic,
|
||||
token,
|
||||
)
|
||||
@@ -1345,6 +1348,7 @@ internal val KT_DIAGNOSTIC_CONVERTER = KtDiagnosticConverterBuilder.buildConvert
|
||||
AssignmentTypeMismatchImpl(
|
||||
firSymbolBuilder.typeBuilder.buildKtType(firDiagnostic.a),
|
||||
firSymbolBuilder.typeBuilder.buildKtType(firDiagnostic.b),
|
||||
firDiagnostic.c,
|
||||
firDiagnostic as FirPsiDiagnostic,
|
||||
token,
|
||||
)
|
||||
@@ -1711,6 +1715,7 @@ internal val KT_DIAGNOSTIC_CONVERTER = KtDiagnosticConverterBuilder.buildConvert
|
||||
firSymbolBuilder.typeBuilder.buildKtType(firDiagnostic.a),
|
||||
firSymbolBuilder.typeBuilder.buildKtType(firDiagnostic.b),
|
||||
firSymbolBuilder.buildSymbol(firDiagnostic.c),
|
||||
firDiagnostic.d,
|
||||
firDiagnostic as FirPsiDiagnostic,
|
||||
token,
|
||||
)
|
||||
@@ -1780,6 +1785,7 @@ internal val KT_DIAGNOSTIC_CONVERTER = KtDiagnosticConverterBuilder.buildConvert
|
||||
firSymbolBuilder.typeBuilder.buildKtType(firDiagnostic.a),
|
||||
firDiagnostic.b.source!!.psi as KtExpression,
|
||||
firDiagnostic.c,
|
||||
firDiagnostic.d,
|
||||
firDiagnostic as FirPsiDiagnostic,
|
||||
token,
|
||||
)
|
||||
@@ -2416,6 +2422,7 @@ internal val KT_DIAGNOSTIC_CONVERTER = KtDiagnosticConverterBuilder.buildConvert
|
||||
InitializerTypeMismatchImpl(
|
||||
firSymbolBuilder.typeBuilder.buildKtType(firDiagnostic.a),
|
||||
firSymbolBuilder.typeBuilder.buildKtType(firDiagnostic.b),
|
||||
firDiagnostic.c,
|
||||
firDiagnostic as FirPsiDiagnostic,
|
||||
token,
|
||||
)
|
||||
|
||||
+7
@@ -904,16 +904,19 @@ sealed class KtFirDiagnostic<PSI : PsiElement> : KtDiagnosticWithPsi<PSI> {
|
||||
override val diagnosticClass get() = TypeMismatch::class
|
||||
abstract val expectedType: KtType
|
||||
abstract val actualType: KtType
|
||||
abstract val isMismatchDueToNullability: Boolean
|
||||
}
|
||||
|
||||
abstract class ThrowableTypeMismatch : KtFirDiagnostic<PsiElement>() {
|
||||
override val diagnosticClass get() = ThrowableTypeMismatch::class
|
||||
abstract val actualType: KtType
|
||||
abstract val isMismatchDueToNullability: Boolean
|
||||
}
|
||||
|
||||
abstract class ConditionTypeMismatch : KtFirDiagnostic<PsiElement>() {
|
||||
override val diagnosticClass get() = ConditionTypeMismatch::class
|
||||
abstract val actualType: KtType
|
||||
abstract val isMismatchDueToNullability: Boolean
|
||||
}
|
||||
|
||||
abstract class ArgumentTypeMismatch : KtFirDiagnostic<PsiElement>() {
|
||||
@@ -968,6 +971,7 @@ sealed class KtFirDiagnostic<PSI : PsiElement> : KtDiagnosticWithPsi<PSI> {
|
||||
override val diagnosticClass get() = AssignmentTypeMismatch::class
|
||||
abstract val expectedType: KtType
|
||||
abstract val actualType: KtType
|
||||
abstract val isMismatchDueToNullability: Boolean
|
||||
}
|
||||
|
||||
abstract class ResultTypeMismatch : KtFirDiagnostic<KtExpression>() {
|
||||
@@ -1216,6 +1220,7 @@ sealed class KtFirDiagnostic<PSI : PsiElement> : KtDiagnosticWithPsi<PSI> {
|
||||
abstract val expectedType: KtType
|
||||
abstract val actualType: KtType
|
||||
abstract val targetFunction: KtSymbol
|
||||
abstract val isMismatchDueToNullability: Boolean
|
||||
}
|
||||
|
||||
abstract class CyclicGenericUpperBound : KtFirDiagnostic<PsiElement>() {
|
||||
@@ -1267,6 +1272,7 @@ sealed class KtFirDiagnostic<PSI : PsiElement> : KtDiagnosticWithPsi<PSI> {
|
||||
abstract val desiredType: KtType
|
||||
abstract val subject: KtExpression
|
||||
abstract val description: String
|
||||
abstract val isCastToNotNull: Boolean
|
||||
}
|
||||
|
||||
abstract class ExtensionInClassReferenceNotAllowed : KtFirDiagnostic<KtExpression>() {
|
||||
@@ -1709,6 +1715,7 @@ sealed class KtFirDiagnostic<PSI : PsiElement> : KtDiagnosticWithPsi<PSI> {
|
||||
override val diagnosticClass get() = InitializerTypeMismatch::class
|
||||
abstract val expectedType: KtType
|
||||
abstract val actualType: KtType
|
||||
abstract val isMismatchDueToNullability: Boolean
|
||||
}
|
||||
|
||||
abstract class GetterVisibilityDiffersFromPropertyVisibility : KtFirDiagnostic<KtModifierListOwner>() {
|
||||
|
||||
+7
@@ -1438,6 +1438,7 @@ internal class InapplicableCandidateImpl(
|
||||
internal class TypeMismatchImpl(
|
||||
override val expectedType: KtType,
|
||||
override val actualType: KtType,
|
||||
override val isMismatchDueToNullability: Boolean,
|
||||
firDiagnostic: FirPsiDiagnostic,
|
||||
override val token: ValidityToken,
|
||||
) : KtFirDiagnostic.TypeMismatch(), KtAbstractFirDiagnostic<PsiElement> {
|
||||
@@ -1446,6 +1447,7 @@ internal class TypeMismatchImpl(
|
||||
|
||||
internal class ThrowableTypeMismatchImpl(
|
||||
override val actualType: KtType,
|
||||
override val isMismatchDueToNullability: Boolean,
|
||||
firDiagnostic: FirPsiDiagnostic,
|
||||
override val token: ValidityToken,
|
||||
) : KtFirDiagnostic.ThrowableTypeMismatch(), KtAbstractFirDiagnostic<PsiElement> {
|
||||
@@ -1454,6 +1456,7 @@ internal class ThrowableTypeMismatchImpl(
|
||||
|
||||
internal class ConditionTypeMismatchImpl(
|
||||
override val actualType: KtType,
|
||||
override val isMismatchDueToNullability: Boolean,
|
||||
firDiagnostic: FirPsiDiagnostic,
|
||||
override val token: ValidityToken,
|
||||
) : KtFirDiagnostic.ConditionTypeMismatch(), KtAbstractFirDiagnostic<PsiElement> {
|
||||
@@ -1541,6 +1544,7 @@ internal class NamedParameterNotFoundImpl(
|
||||
internal class AssignmentTypeMismatchImpl(
|
||||
override val expectedType: KtType,
|
||||
override val actualType: KtType,
|
||||
override val isMismatchDueToNullability: Boolean,
|
||||
firDiagnostic: FirPsiDiagnostic,
|
||||
override val token: ValidityToken,
|
||||
) : KtFirDiagnostic.AssignmentTypeMismatch(), KtAbstractFirDiagnostic<KtExpression> {
|
||||
@@ -1951,6 +1955,7 @@ internal class ReturnTypeMismatchImpl(
|
||||
override val expectedType: KtType,
|
||||
override val actualType: KtType,
|
||||
override val targetFunction: KtSymbol,
|
||||
override val isMismatchDueToNullability: Boolean,
|
||||
firDiagnostic: FirPsiDiagnostic,
|
||||
override val token: ValidityToken,
|
||||
) : KtFirDiagnostic.ReturnTypeMismatch(), KtAbstractFirDiagnostic<KtExpression> {
|
||||
@@ -2029,6 +2034,7 @@ internal class SmartcastImpossibleImpl(
|
||||
override val desiredType: KtType,
|
||||
override val subject: KtExpression,
|
||||
override val description: String,
|
||||
override val isCastToNotNull: Boolean,
|
||||
firDiagnostic: FirPsiDiagnostic,
|
||||
override val token: ValidityToken,
|
||||
) : KtFirDiagnostic.SmartcastImpossible(), KtAbstractFirDiagnostic<KtExpression> {
|
||||
@@ -2747,6 +2753,7 @@ internal class WrongSetterParameterTypeImpl(
|
||||
internal class InitializerTypeMismatchImpl(
|
||||
override val expectedType: KtType,
|
||||
override val actualType: KtType,
|
||||
override val isMismatchDueToNullability: Boolean,
|
||||
firDiagnostic: FirPsiDiagnostic,
|
||||
override val token: ValidityToken,
|
||||
) : KtFirDiagnostic.InitializerTypeMismatch(), KtAbstractFirDiagnostic<KtProperty> {
|
||||
|
||||
+2
@@ -96,6 +96,8 @@ public abstract class KtBuiltinTypes : ValidityTokenOwner {
|
||||
public abstract val NOTHING: KtType
|
||||
public abstract val ANY: KtType
|
||||
|
||||
public abstract val THROWABLE: KtType
|
||||
|
||||
public abstract val NULLABLE_ANY: KtType
|
||||
public abstract val NULLABLE_NOTHING: KtType
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user