[NI] Report unstable smart cast directly instead of using SmartCastManager

Fix compilation errors, revealed by this fix.

SmartCastManager is unnecessary for error reporting, intermediate diagnostics from the NI contain all required infromation.
When SmartCastManager is used it leads to missing unstable smart casts in case of expressions with captured types.
This happens, because data flow info is recorded for original expression without captured types, which is used as a key.
DataFlowValues created from receivers with captured types can't be used to retrieve that info.

^KT-39010 Fixed
This commit is contained in:
Pavel Kirpichenkov
2020-05-20 12:49:38 +03:00
parent b808d5f381
commit 0b33e9430b
15 changed files with 156 additions and 15 deletions
@@ -32,6 +32,7 @@ import org.jetbrains.kotlin.resolve.constants.evaluate.ConstantExpressionEvaluat
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.checker.intersectWrappedTypes
import org.jetbrains.kotlin.types.expressions.ControlStructureTypingUtils
import org.jetbrains.kotlin.types.typeUtil.isNullableNothing
import org.jetbrains.kotlin.types.typeUtil.makeNullable
@@ -283,8 +284,19 @@ class DiagnosticReporterByTrackingStrategy(
}
private fun reportUnstableSmartCast(unstableSmartCast: UnstableSmartCast) {
// todo hack -- remove it after removing SmartCastManager
reportSmartCast(SmartCastDiagnostic(unstableSmartCast.argument, unstableSmartCast.targetType, null))
val dataFlowValue = dataFlowValueFactory.createDataFlowValue(unstableSmartCast.argument.receiver.receiverValue, context)
val possibleTypes = unstableSmartCast.argument.receiver.typesFromSmartCasts
val argumentExpression = unstableSmartCast.argument.psiExpression ?: return
require(possibleTypes.isNotEmpty()) { "Receiver for unstable smart cast without possible types" }
trace.report(
SMARTCAST_IMPOSSIBLE.on(
argumentExpression,
intersectWrappedTypes(possibleTypes),
argumentExpression.text,
dataFlowValue.kind.description
)
)
}
override fun constraintError(diagnostic: KotlinCallDiagnostic) {