[NI] Fix reporting smartcast diagnostics for intersection types
#KT-30826 Fixed
This commit is contained in:
+9
-4
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user