[FIR] Implement NULL_FOR_NONNULL_TYPE diagnostics, fix tests
This commit is contained in:
+6
@@ -739,6 +739,12 @@ internal val KT_DIAGNOSTIC_CONVERTER = KtDiagnosticConverterBuilder.buildConvert
|
||||
token,
|
||||
)
|
||||
}
|
||||
add(FirErrors.NULL_FOR_NONNULL_TYPE) { firDiagnostic ->
|
||||
NullForNonnullTypeImpl(
|
||||
firDiagnostic as FirPsiDiagnostic<*>,
|
||||
token,
|
||||
)
|
||||
}
|
||||
add(FirErrors.INAPPLICABLE_LATEINIT_MODIFIER) { firDiagnostic ->
|
||||
InapplicableLateinitModifierImpl(
|
||||
firDiagnostic.a,
|
||||
|
||||
+4
@@ -532,6 +532,10 @@ sealed class KtFirDiagnostic<PSI: PsiElement> : KtDiagnosticWithPsi<PSI> {
|
||||
abstract val actualType: KtType
|
||||
}
|
||||
|
||||
abstract class NullForNonnullType : KtFirDiagnostic<PsiElement>() {
|
||||
override val diagnosticClass get() = NullForNonnullType::class
|
||||
}
|
||||
|
||||
abstract class InapplicableLateinitModifier : KtFirDiagnostic<KtModifierListOwner>() {
|
||||
override val diagnosticClass get() = InapplicableLateinitModifier::class
|
||||
abstract val reason: String
|
||||
|
||||
+7
@@ -851,6 +851,13 @@ internal class ArgumentTypeMismatchImpl(
|
||||
override val firDiagnostic: FirPsiDiagnostic<*> by weakRef(firDiagnostic)
|
||||
}
|
||||
|
||||
internal class NullForNonnullTypeImpl(
|
||||
firDiagnostic: FirPsiDiagnostic<*>,
|
||||
override val token: ValidityToken,
|
||||
) : KtFirDiagnostic.NullForNonnullType(), KtAbstractFirDiagnostic<PsiElement> {
|
||||
override val firDiagnostic: FirPsiDiagnostic<*> by weakRef(firDiagnostic)
|
||||
}
|
||||
|
||||
internal class InapplicableLateinitModifierImpl(
|
||||
override val reason: String,
|
||||
firDiagnostic: FirPsiDiagnostic<*>,
|
||||
|
||||
+1
-1
@@ -27,7 +27,7 @@ fun foo(expr: StringBuilder): Int {
|
||||
|
||||
fun unitShort() : Unit = Unit
|
||||
fun unitShortConv() : Unit = <error descr="[RETURN_TYPE_MISMATCH] Return type mismatch: expected kotlin/Unit, actual kotlin/Int">1</error>
|
||||
fun unitShortNull() : Unit = <error descr="[RETURN_TYPE_MISMATCH] Return type mismatch: expected kotlin/Unit, actual kotlin/Nothing?">null</error>
|
||||
fun unitShortNull() : Unit = <error descr="[NULL_FOR_NONNULL_TYPE] ">null</error>
|
||||
|
||||
fun intEmpty() : Int {}
|
||||
fun intShortInfer() = 1
|
||||
|
||||
+2
-2
@@ -3,8 +3,8 @@ package test
|
||||
|
||||
annotation class A(val value: String)
|
||||
|
||||
@A(<error descr="[ARGUMENT_TYPE_MISMATCH] Argument type mismatch: actual type is kotlin/Nothing? but kotlin/String was expected">null</error>)
|
||||
@A(<error descr="[NULL_FOR_NONNULL_TYPE] ">null</error>)
|
||||
fun foo() {}
|
||||
|
||||
@A(<error descr="[ARGUMENT_TYPE_MISMATCH] Argument type mismatch: actual type is kotlin/Nothing? but kotlin/String was expected">null</error>)
|
||||
@A(<error descr="[NULL_FOR_NONNULL_TYPE] ">null</error>)
|
||||
class B
|
||||
|
||||
Reference in New Issue
Block a user