diff --git a/plugins/kotlin/code-insight/postfix-templates/test/org/jetbrains/kotlin/idea/k2/codeInsight/postfix/test/K2PostfixTemplateTestGenerated.java b/plugins/kotlin/code-insight/postfix-templates/test/org/jetbrains/kotlin/idea/k2/codeInsight/postfix/test/K2PostfixTemplateTestGenerated.java index 770b3fe35c57..f229fb5df4f3 100644 --- a/plugins/kotlin/code-insight/postfix-templates/test/org/jetbrains/kotlin/idea/k2/codeInsight/postfix/test/K2PostfixTemplateTestGenerated.java +++ b/plugins/kotlin/code-insight/postfix-templates/test/org/jetbrains/kotlin/idea/k2/codeInsight/postfix/test/K2PostfixTemplateTestGenerated.java @@ -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(); diff --git a/plugins/kotlin/code-insight/postfix-templates/testData/expansion/for/conjunctionType.after.kt b/plugins/kotlin/code-insight/postfix-templates/testData/expansion/for/conjunctionType.after.kt new file mode 100644 index 000000000000..a21953952f28 --- /dev/null +++ b/plugins/kotlin/code-insight/postfix-templates/testData/expansion/for/conjunctionType.after.kt @@ -0,0 +1,10 @@ +open class Foo +abstract class AbstractFoo : Foo(), Iterable + +fun test(a: Iterable<*>) { + if (a is Foo) { + for (any in a) { + + } + } +} diff --git a/plugins/kotlin/code-insight/postfix-templates/testData/expansion/for/conjunctionType.kt b/plugins/kotlin/code-insight/postfix-templates/testData/expansion/for/conjunctionType.kt new file mode 100644 index 000000000000..3e6ef1a2db04 --- /dev/null +++ b/plugins/kotlin/code-insight/postfix-templates/testData/expansion/for/conjunctionType.kt @@ -0,0 +1,8 @@ +open class Foo +abstract class AbstractFoo : Foo(), Iterable + +fun test(a: Iterable<*>) { + if (a is Foo) { + a + } +} diff --git a/plugins/kotlin/code-insight/utils/src/org/jetbrains/kotlin/idea/codeinsight/utils/CheckCanBeIteratedUtils.kt b/plugins/kotlin/code-insight/utils/src/org/jetbrains/kotlin/idea/codeinsight/utils/CheckCanBeIteratedUtils.kt index f7734524ed48..d81aaf7711bd 100644 --- a/plugins/kotlin/code-insight/utils/src/org/jetbrains/kotlin/idea/codeinsight/utils/CheckCanBeIteratedUtils.kt +++ b/plugins/kotlin/code-insight/utils/src/org/jetbrains/kotlin/idea/codeinsight/utils/CheckCanBeIteratedUtils.kt @@ -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 = 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, 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 -> {