[kotlin] KTIJ-36968 Fix conjunction type check

GitOrigin-RevId: d9339a2ab403104a7bcc9438746c0452eb279c1b
This commit is contained in:
Vladimir Dolzhenko
2025-12-25 14:56:34 +00:00
committed by intellij-monorepo-bot
parent 19f6212313
commit 0f19321e61
4 changed files with 27 additions and 4 deletions
@@ -152,6 +152,11 @@ public abstract class K2PostfixTemplateTestGenerated extends AbstractK2PostfixTe
performTest();
}
@TestMetadata("conjunctionType.kt")
public void testConjunctionType() throws Exception {
performTest();
}
@TestMetadata("forOnMap.kt")
public void testForOnMap() throws Exception {
performTest();
@@ -0,0 +1,10 @@
open class Foo
abstract class AbstractFoo : Foo(), Iterable<Int>
fun test(a: Iterable<*>) {
if (a is Foo) {
for (<selection>any<caret></selection> in a) {
}
}
}
@@ -0,0 +1,8 @@
open class Foo
abstract class AbstractFoo : Foo(), Iterable<Int>
fun test(a: Iterable<*>) {
if (a is Foo) {
a<caret>
}
}
@@ -4,7 +4,7 @@ package org.jetbrains.kotlin.idea.codeinsight.utils
import org.jetbrains.annotations.ApiStatus
import org.jetbrains.kotlin.analysis.api.KaContextParameterApi
import org.jetbrains.kotlin.analysis.api.KaSession
import org.jetbrains.kotlin.analysis.api.components.DefaultTypeClassIds
import org.jetbrains.kotlin.analysis.api.components.KaStandardTypeClassIds
import org.jetbrains.kotlin.analysis.api.components.allSupertypes
import org.jetbrains.kotlin.analysis.api.components.isMarkedNullable
import org.jetbrains.kotlin.analysis.api.components.lowerBoundIfFlexible
@@ -17,9 +17,9 @@ private val ITERABLE_CLASS_IDS: Set<ClassId> = buildSet {
this += StandardClassIds.primitiveArrayTypeByElementType.values // What about elementTypeByUnsignedArrayType?
this += StandardClassIds.Iterable
this += StandardClassIds.Map
this += ClassId.fromString("kotlin/sequences/Sequence")
this += StandardClassIds.Sequence
this += ClassId.fromString("java/util/stream/Stream")
this += DefaultTypeClassIds.CHAR_SEQUENCE
this += KaStandardTypeClassIds.CHAR_SEQUENCE
}
@OptIn(KaContextParameterApi::class)
@@ -40,7 +40,7 @@ context(_: KaSession)
private fun KaType.isInheritorOf(classIds: Set<ClassId>, checkNullability: Boolean = true): Boolean {
return when (this) {
is KaFlexibleType -> this.lowerBoundIfFlexible().isInheritorOf(classIds)
is KaIntersectionType -> this.conjuncts.all { it.isInheritorOf(classIds) }
is KaIntersectionType -> this.conjuncts.any { it.isInheritorOf(classIds) }
is KaDefinitelyNotNullType -> this.original.isInheritorOf(classIds, checkNullability = false)
is KaTypeParameterType -> symbol.upperBounds.any { it.isInheritorOf(classIds) }
is KaClassType -> {