FIR checker: make SMARTCAST_IMPOSSIBLE report the desired type at receiver position

Previously the smartcast type is reported. This is undesirable because
usually this type is an intersection and hence not denotable.
This commit is contained in:
Tianyu Geng
2021-08-03 18:54:14 -07:00
committed by teamcityserver
parent 951812f130
commit 5b0ca06e95
@@ -122,14 +122,13 @@ object CheckDispatchReceiver : ResolutionStage() {
!explicitReceiverExpression.isStable &&
(isCandidateFromUnstableSmartcast || (isReceiverNullable && !explicitReceiverExpression.smartcastType.canBeNull))
) {
val targetType =
(candidate.symbol as? FirCallableSymbol<*>)?.dispatchReceiverType ?: explicitReceiverExpression.smartcastType.coneType
sink.yieldDiagnostic(
UnstableSmartCast(
explicitReceiverExpression,
explicitReceiverExpression.smartcastType.coneType,
context.session.typeContext.isTypeMismatchDueToNullability(
explicitReceiverExpression.originalType.coneType,
explicitReceiverExpression.smartcastType.coneType
)
targetType,
context.session.typeContext.isTypeMismatchDueToNullability(explicitReceiverExpression.originalType.coneType, targetType)
)
)
} else if (isReceiverNullable) {