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