[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 ece3a0fe90
commit 18f9272f56
15 changed files with 115 additions and 36 deletions
@@ -17,6 +17,7 @@
package org.jetbrains.kotlin.resolve.calls.smartcasts
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.config.LanguageFeature
import org.jetbrains.kotlin.config.LanguageVersionSettings
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.diagnostics.Errors
@@ -33,6 +34,7 @@ import org.jetbrains.kotlin.resolve.scopes.receivers.ImplicitReceiver
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.types.TypeUtils
import org.jetbrains.kotlin.types.typeUtil.expandIntersectionTypeIfNecessary
import java.util.*
class SmartCastManager {
@@ -178,8 +180,13 @@ class SmartCastManager {
recordExpressionType: Boolean
): SmartCastResult? {
val calleeExpression = call?.calleeExpression
val expectedTypes = if (c.languageVersionSettings.supportsFeature(LanguageFeature.NewInference))
expectedType.expandIntersectionTypeIfNecessary()
else
listOf(expectedType)
for (possibleType in c.dataFlowInfo.getCollectedTypes(dataFlowValue, c.languageVersionSettings)) {
if (ArgumentTypeResolver.isSubtypeOfForArgumentType(possibleType, expectedType) &&
if (expectedTypes.any { ArgumentTypeResolver.isSubtypeOfForArgumentType(possibleType, it) } &&
(additionalPredicate == null || additionalPredicate(possibleType))
) {
if (expression != null) {