[NI] Fix reporting smartcast diagnostics for intersection types

#KT-30826 Fixed
This commit is contained in:
Dmitriy Novozhilov
2019-04-08 12:37:56 +03:00
parent 47b1ea7fa4
commit 033d7262a2
15 changed files with 115 additions and 36 deletions
@@ -22,6 +22,7 @@ import org.jetbrains.kotlin.descriptors.ReceiverParameterDescriptor
import org.jetbrains.kotlin.resolve.calls.model.*
import org.jetbrains.kotlin.types.UnwrappedType
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker
import org.jetbrains.kotlin.types.typeUtil.expandIntersectionTypeIfNecessary
// very initial state of component
// todo: handle all diagnostic inside DiagnosticReporterByTrackingStrategy
@@ -43,10 +44,14 @@ class AdditionalDiagnosticReporter(private val languageVersionSettings: Language
expectedResultType: UnwrappedType
): SmartCastDiagnostic? {
if (argument !is ExpressionKotlinCallArgument) return null
if (!KotlinTypeChecker.DEFAULT.isSubtypeOf(argument.receiver.receiverValue.type, expectedResultType)) {
return SmartCastDiagnostic(argument, expectedResultType.unwrap(), candidate.atom)
}
return null
val types = expectedResultType.expandIntersectionTypeIfNecessary()
val argumentType = argument.receiver.receiverValue.type
val isSubtype = types.map { KotlinTypeChecker.DEFAULT.isSubtypeOf(argumentType, it) }
if (isSubtype.any { it }) return null
return SmartCastDiagnostic(argument, types.first().unwrap(), candidate.atom)
}
private fun reportSmartCastOnReceiver(