Fix diagnostic inferred type calculation for null in some cases
#KT-36222 fixed
This commit is contained in:
+6
-1
@@ -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
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user