Fix diagnostic inferred type calculation for null in some cases

#KT-36222 fixed
This commit is contained in:
Ilya Chernikov
2020-02-19 17:15:37 +01:00
parent 997debdd42
commit 2727507d18
7 changed files with 45 additions and 1 deletions
@@ -33,6 +33,8 @@ import org.jetbrains.kotlin.resolve.descriptorUtil.module
import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver
import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.types.expressions.ControlStructureTypingUtils
import org.jetbrains.kotlin.types.typeUtil.isNullableNothing
import org.jetbrains.kotlin.types.typeUtil.makeNullable
import org.jetbrains.kotlin.utils.addToStdlib.cast
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
@@ -333,12 +335,15 @@ class DiagnosticReporterByTrackingStrategy(
(position as? ExpectedTypeConstraintPosition)?.let {
val call = it.topLevelCall.psiKotlinCall.psiCall.callElement.safeAs<KtExpression>()
val inferredType =
if (!constraintError.lowerKotlinType.isNullableNothing()) constraintError.lowerKotlinType
else constraintError.upperKotlinType.makeNullable()
reportIfNonNull(call) {
trace.report(
Errors.TYPE_MISMATCH.on(
it,
constraintError.upperKotlinType,
constraintError.lowerKotlinType
inferredType
)
)
}