[NI] Add checking @NotNull parameters for candidates
This commit is contained in:
+15
@@ -25,6 +25,7 @@ import org.jetbrains.kotlin.resolve.calls.inference.model.ArgumentConstraintPosi
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.model.ConstraintPosition
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.model.ReceiverConstraintPosition
|
||||
import org.jetbrains.kotlin.resolve.calls.model.*
|
||||
import org.jetbrains.kotlin.types.NotNullTypeVariable
|
||||
import org.jetbrains.kotlin.types.UnwrappedType
|
||||
import org.jetbrains.kotlin.types.checker.captureFromExpression
|
||||
import org.jetbrains.kotlin.types.checker.hasSupertypeWithGivenTypeConstructor
|
||||
@@ -81,6 +82,20 @@ private fun checkExpressionArgument(
|
||||
|
||||
val expectedNullableType = expectedType.makeNullableAsSpecified(true)
|
||||
val position = if (isReceiver) ReceiverConstraintPosition(expressionArgument) else ArgumentConstraintPosition(expressionArgument)
|
||||
|
||||
// Used only for arguments with @NotNull annotation
|
||||
if (expectedType is NotNullTypeVariable) {
|
||||
var expectedTypeIsNull: Boolean = false
|
||||
csBuilder.runTransaction {
|
||||
addNotNullUpperConstraint(argumentType, position)
|
||||
expectedTypeIsNull = hasContradiction
|
||||
false
|
||||
}
|
||||
if (expectedTypeIsNull) {
|
||||
diagnosticsHolder.addDiagnostic(ArgumentTypeMismatchDiagnostic(expectedType, argumentType, expressionArgument))
|
||||
}
|
||||
}
|
||||
|
||||
if (expressionArgument.isSafeCall) {
|
||||
if (!csBuilder.addSubtypeConstraintIfCompatible(argumentType, expectedNullableType, position)) {
|
||||
diagnosticsHolder.addDiagnosticIfNotNull(
|
||||
|
||||
+2
@@ -40,6 +40,8 @@ interface ConstraintSystemOperation {
|
||||
fun isPostponedTypeVariable(typeVariable: TypeVariableMarker): Boolean
|
||||
|
||||
fun getProperSuperTypeConstructors(type: KotlinTypeMarker): List<TypeConstructorMarker>
|
||||
|
||||
fun addNotNullUpperConstraint(type: KotlinTypeMarker, position: ConstraintPosition)
|
||||
}
|
||||
|
||||
interface ConstraintSystemBuilder : ConstraintSystemOperation {
|
||||
|
||||
+4
@@ -302,4 +302,8 @@ class NewConstraintSystemImpl(
|
||||
|
||||
return constraints.any { (it.kind == ConstraintKind.UPPER || it.kind == ConstraintKind.EQUALITY) && it.type.isUnit() }
|
||||
}
|
||||
|
||||
override fun addNotNullUpperConstraint(type: KotlinTypeMarker, position: ConstraintPosition) {
|
||||
addSubtypeConstraint(type, anyType(), position)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user