K2: add ConeKotlinType argument for NULL_FOR_NONNULL_TYPE
This commit is contained in:
committed by
Space Team
parent
9d9d7880af
commit
17da09bf17
+1
@@ -1718,6 +1718,7 @@ internal val KT_DIAGNOSTIC_CONVERTER = KtDiagnosticConverterBuilder.buildConvert
|
||||
}
|
||||
add(FirErrors.NULL_FOR_NONNULL_TYPE) { firDiagnostic ->
|
||||
NullForNonnullTypeImpl(
|
||||
firSymbolBuilder.typeBuilder.buildKtType(firDiagnostic.a),
|
||||
firDiagnostic as KtPsiDiagnostic,
|
||||
token,
|
||||
)
|
||||
|
||||
+1
@@ -1234,6 +1234,7 @@ sealed interface KtFirDiagnostic<PSI : PsiElement> : KtDiagnosticWithPsi<PSI> {
|
||||
|
||||
interface NullForNonnullType : KtFirDiagnostic<PsiElement> {
|
||||
override val diagnosticClass get() = NullForNonnullType::class
|
||||
val expectedType: KtType
|
||||
}
|
||||
|
||||
interface InapplicableLateinitModifier : KtFirDiagnostic<KtModifierListOwner> {
|
||||
|
||||
+1
@@ -1479,6 +1479,7 @@ internal class ArgumentTypeMismatchImpl(
|
||||
) : KtAbstractFirDiagnostic<PsiElement>(firDiagnostic, token), KtFirDiagnostic.ArgumentTypeMismatch
|
||||
|
||||
internal class NullForNonnullTypeImpl(
|
||||
override val expectedType: KtType,
|
||||
firDiagnostic: KtPsiDiagnostic,
|
||||
token: KtLifetimeToken,
|
||||
) : KtAbstractFirDiagnostic<PsiElement>(firDiagnostic, token), KtFirDiagnostic.NullForNonnullType
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@ class C
|
||||
class B
|
||||
|
||||
class A {
|
||||
val B.foo: C.() -> Unit get() = <!NULL_FOR_NONNULL_TYPE!>null<!>
|
||||
val B.foo: C.() -> Unit get() = <!NULL_FOR_NONNULL_TYPE("@ExtensionFunctionType kotlin/Function1<C, kotlin/Unit>")!>null<!>
|
||||
}
|
||||
|
||||
fun <T, R> with(arg: T, f: T.() -> R): R = arg.f()
|
||||
|
||||
+3
-1
@@ -531,7 +531,9 @@ object DIAGNOSTICS_LIST : DiagnosticList("FirErrors") {
|
||||
parameter<Boolean>("isMismatchDueToNullability")
|
||||
}
|
||||
|
||||
val NULL_FOR_NONNULL_TYPE by error<PsiElement> { }
|
||||
val NULL_FOR_NONNULL_TYPE by error<PsiElement> {
|
||||
parameter<ConeKotlinType>("expectedType")
|
||||
}
|
||||
|
||||
val INAPPLICABLE_LATEINIT_MODIFIER by error<KtModifierListOwner>(PositioningStrategy.LATEINIT_MODIFIER) {
|
||||
parameter<String>("reason")
|
||||
|
||||
+1
-1
@@ -360,7 +360,7 @@ object FirErrors {
|
||||
val THROWABLE_TYPE_MISMATCH by error2<PsiElement, ConeKotlinType, Boolean>()
|
||||
val CONDITION_TYPE_MISMATCH by error2<PsiElement, ConeKotlinType, Boolean>()
|
||||
val ARGUMENT_TYPE_MISMATCH by error3<PsiElement, ConeKotlinType, ConeKotlinType, Boolean>()
|
||||
val NULL_FOR_NONNULL_TYPE by error0<PsiElement>()
|
||||
val NULL_FOR_NONNULL_TYPE by error1<PsiElement, ConeKotlinType>()
|
||||
val INAPPLICABLE_LATEINIT_MODIFIER by error1<KtModifierListOwner, String>(SourceElementPositioningStrategies.LATEINIT_MODIFIER)
|
||||
val VARARG_OUTSIDE_PARENTHESES by error0<KtElement>()
|
||||
val NAMED_ARGUMENTS_NOT_ALLOWED by error1<KtValueArgument, ForbiddenNamedArgumentsTarget>(SourceElementPositioningStrategies.NAME_OF_NAMED_ARGUMENT)
|
||||
|
||||
@@ -475,7 +475,7 @@ fun checkTypeMismatch(
|
||||
reporter.reportOn(assignment.source, FirErrors.SETTER_PROJECTED_OUT, resolvedSymbol, context)
|
||||
}
|
||||
rValue.isNullLiteral && lValueType.nullability == ConeNullability.NOT_NULL -> {
|
||||
reporter.reportOn(rValue.source, FirErrors.NULL_FOR_NONNULL_TYPE, context)
|
||||
reporter.reportOn(rValue.source, FirErrors.NULL_FOR_NONNULL_TYPE, lValueType, context)
|
||||
}
|
||||
isInitializer -> {
|
||||
reporter.reportOn(
|
||||
|
||||
+1
-1
@@ -58,7 +58,7 @@ object FirFunctionReturnTypeMismatchChecker : FirReturnExpressionChecker() {
|
||||
|
||||
if (!isSubtypeForTypeMismatch(typeContext, subtype = returnExpressionType, supertype = functionReturnType)) {
|
||||
if (resultExpression.isNullLiteral && functionReturnType.nullability == ConeNullability.NOT_NULL) {
|
||||
reporter.reportOn(resultExpression.source, NULL_FOR_NONNULL_TYPE, context)
|
||||
reporter.reportOn(resultExpression.source, NULL_FOR_NONNULL_TYPE, functionReturnType, context)
|
||||
} else {
|
||||
val isDueToNullability =
|
||||
context.session.typeContext.isTypeMismatchDueToNullability(returnExpressionType, functionReturnType)
|
||||
|
||||
+1
-1
@@ -707,7 +707,7 @@ object FirErrorsDefaultMessages : BaseDiagnosticRendererFactory() {
|
||||
map.put(INCORRECT_CHARACTER_LITERAL, "Incorrect character literal")
|
||||
map.put(TOO_MANY_CHARACTERS_IN_CHARACTER_LITERAL, "Too many characters in a character literal")
|
||||
map.put(ILLEGAL_ESCAPE, "Illegal escape")
|
||||
map.put(NULL_FOR_NONNULL_TYPE, "Null can not be a value of a non-null type")
|
||||
map.put(NULL_FOR_NONNULL_TYPE, "Null can not be a value of a non-null type ''{0}''", RENDER_TYPE)
|
||||
|
||||
// Unresolved
|
||||
map.put(INVISIBLE_REFERENCE, "Cannot access ''{0}'': it is {1} in {2}", SYMBOL, VISIBILITY, NAME_OF_DECLARATION_OR_FILE)
|
||||
|
||||
+1
-1
@@ -271,7 +271,7 @@ private fun mapInapplicableCandidateError(
|
||||
)
|
||||
|
||||
is NullForNotNullType -> FirErrors.NULL_FOR_NONNULL_TYPE.createOn(
|
||||
rootCause.argument.source ?: source
|
||||
rootCause.argument.source ?: source, rootCause.expectedType.removeTypeVariableTypes(typeContext)
|
||||
)
|
||||
|
||||
is NonVarargSpread -> FirErrors.NON_VARARG_SPREAD.createOn(rootCause.argument.source?.getChild(KtTokens.MUL, depth = 1)!!)
|
||||
|
||||
@@ -345,7 +345,7 @@ private fun checkApplicabilityForArgumentType(
|
||||
|
||||
fun subtypeError(actualExpectedType: ConeKotlinType): ResolutionDiagnostic {
|
||||
if (argument.isNullLiteral && actualExpectedType.nullability == ConeNullability.NOT_NULL) {
|
||||
return NullForNotNullType(argument)
|
||||
return NullForNotNullType(argument, actualExpectedType)
|
||||
}
|
||||
|
||||
fun tryGetConeTypeThatCompatibleWithKtType(type: ConeKotlinType): ConeKotlinType {
|
||||
|
||||
+1
-1
@@ -112,7 +112,7 @@ class ArgumentTypeMismatch(
|
||||
) : ResolutionDiagnostic(INAPPLICABLE)
|
||||
|
||||
class NullForNotNullType(
|
||||
val argument: FirExpression
|
||||
val argument: FirExpression, val expectedType: ConeKotlinType
|
||||
) : ResolutionDiagnostic(INAPPLICABLE)
|
||||
|
||||
class ManyLambdaExpressionArguments(
|
||||
|
||||
+1
-1
@@ -8,7 +8,7 @@ compiler/testData/cli/jvm/firLightTree.kt:3:15: error: classifier 'class System
|
||||
compiler/testData/cli/jvm/firLightTree.kt:3:15: error: variable expected
|
||||
java.lang.System = null
|
||||
^
|
||||
compiler/testData/cli/jvm/firLightTree.kt:3:24: error: null can not be a value of a non-null type
|
||||
compiler/testData/cli/jvm/firLightTree.kt:3:24: error: null can not be a value of a non-null type 'kotlin/Unit'
|
||||
java.lang.System = null
|
||||
^
|
||||
COMPILATION_ERROR
|
||||
|
||||
+1
-1
@@ -8,7 +8,7 @@ compiler/testData/cli/jvm/firLightTree.kt:3:15: error: classifier 'class System
|
||||
compiler/testData/cli/jvm/firLightTree.kt:3:15: error: variable expected
|
||||
java.lang.System = null
|
||||
^
|
||||
compiler/testData/cli/jvm/firLightTree.kt:3:24: error: null can not be a value of a non-null type
|
||||
compiler/testData/cli/jvm/firLightTree.kt:3:24: error: null can not be a value of a non-null type 'kotlin/Unit'
|
||||
java.lang.System = null
|
||||
^
|
||||
COMPILATION_ERROR
|
||||
|
||||
Reference in New Issue
Block a user