[NI] Add check for non-null argument type in arguments check
#KT-31461 Fixed
This commit is contained in:
+9
@@ -29,6 +29,7 @@ import org.jetbrains.kotlin.types.UnwrappedType
|
||||
import org.jetbrains.kotlin.types.checker.captureFromExpression
|
||||
import org.jetbrains.kotlin.types.checker.hasSupertypeWithGivenTypeConstructor
|
||||
import org.jetbrains.kotlin.types.lowerIfFlexible
|
||||
import org.jetbrains.kotlin.types.typeUtil.makeNotNullable
|
||||
import org.jetbrains.kotlin.types.typeUtil.supertypes
|
||||
import org.jetbrains.kotlin.types.upperIfFlexible
|
||||
|
||||
@@ -66,6 +67,14 @@ private fun checkExpressionArgument(
|
||||
return UnstableSmartCast(expressionArgument, unstableType)
|
||||
}
|
||||
}
|
||||
|
||||
if (argumentType.isMarkedNullable) {
|
||||
if (csBuilder.addSubtypeConstraintIfCompatible(argumentType, actualExpectedType, position)) return null
|
||||
if (csBuilder.addSubtypeConstraintIfCompatible(argumentType.makeNotNullable(), actualExpectedType, position)) {
|
||||
return ArgumentTypeMismatchDiagnostic(actualExpectedType, argumentType, expressionArgument)
|
||||
}
|
||||
}
|
||||
|
||||
csBuilder.addSubtypeConstraint(argumentType, actualExpectedType, position)
|
||||
return null
|
||||
}
|
||||
|
||||
+10
@@ -185,4 +185,14 @@ class NonApplicableCallForBuilderInferenceDiagnostic(val kotlinCall: KotlinCall)
|
||||
override fun report(reporter: DiagnosticReporter) {
|
||||
reporter.onCall(this)
|
||||
}
|
||||
}
|
||||
|
||||
class ArgumentTypeMismatchDiagnostic(
|
||||
val expectedType: UnwrappedType,
|
||||
val actualType: UnwrappedType,
|
||||
val expressionArgument: ExpressionKotlinCallArgument
|
||||
) : KotlinCallDiagnostic(MAY_THROW_RUNTIME_ERROR) {
|
||||
override fun report(reporter: DiagnosticReporter) {
|
||||
reporter.onCallArgument(expressionArgument, this)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user