diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/LogicSystem.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/LogicSystem.kt index dfdc0d3fe79..6e11d2ed8cf 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/LogicSystem.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/LogicSystem.kt @@ -140,14 +140,17 @@ abstract class LogicSystem(protected val context: ConeInferenceCont private fun orForTypes(types: Collection>): MutableSet { if (types.any { it.isEmpty() }) return mutableSetOf() - val allTypes = types.flatMapTo(mutableSetOf()) { it } - val commonTypes = allTypes.toMutableSet() - types.forEach { commonTypes.retainAll(it) } - val differentTypes = types.mapNotNull { typeSet -> (typeSet - commonTypes).takeIf { it.isNotEmpty() } } - if (differentTypes.size == types.size) { - context.commonSuperTypeOrNull(differentTypes.flatten())?.let { commonTypes += it } + val intersectedTypes = types.map { + if (it.size > 1) { + context.intersectTypes(it.toList()) as ConeKotlinType + } else { + assert(it.size == 1) { "We've already checked each set of types is not empty." } + it.single() + } } - return commonTypes + val result = mutableSetOf() + context.commonSuperTypeOrNull(intersectedTypes)?.let { result.add(it) } + return result } protected fun and(statements: Collection): MutableTypeStatement = diff --git a/compiler/testData/ir/irText/firProblems/inapplicableCollectionSet.fir.kt.txt b/compiler/testData/ir/irText/firProblems/inapplicableCollectionSet.fir.kt.txt index 50b799c254c..7537cea0936 100644 --- a/compiler/testData/ir/irText/firProblems/inapplicableCollectionSet.fir.kt.txt +++ b/compiler/testData/ir/irText/firProblems/inapplicableCollectionSet.fir.kt.txt @@ -23,10 +23,10 @@ class Flaf { result = Flaf(javaName = javaName) } } - error("") /* ErrorCallExpression */javaName; result; + .().set(key = javaName, value = result /*as Flaf */) } } - return result + return result /*as Flaf */ } } diff --git a/compiler/testData/ir/irText/firProblems/inapplicableCollectionSet.fir.txt b/compiler/testData/ir/irText/firProblems/inapplicableCollectionSet.fir.txt index 4a37c0bf4a6..43ce9eeb68b 100644 --- a/compiler/testData/ir/irText/firProblems/inapplicableCollectionSet.fir.txt +++ b/compiler/testData/ir/irText/firProblems/inapplicableCollectionSet.fir.txt @@ -62,11 +62,17 @@ FILE fqName: fileName:/inapplicableCollectionSet.kt SET_VAR 'var result: .Flaf? [var] declared in .Flaf.forJavaName' type=kotlin.Unit origin=EQ CONSTRUCTOR_CALL 'public constructor (javaName: kotlin.String) [primary] declared in .Flaf' type=.Flaf origin=null javaName: GET_VAR 'javaName: kotlin.String declared in .Flaf.forJavaName' type=kotlin.String origin=null - ERROR_CALL 'Unresolved reference: #' type=kotlin.Unit - GET_VAR 'javaName: kotlin.String declared in .Flaf.forJavaName' type=kotlin.String origin=null - GET_VAR 'var result: .Flaf? [var] declared in .Flaf.forJavaName' type=.Flaf? origin=null + CALL 'public final fun set (key: K of kotlin.collections.set, value: V of kotlin.collections.set): kotlin.Unit [inline,operator] declared in kotlin.collections' type=kotlin.Unit origin=null + : kotlin.String + : .Flaf + $receiver: CALL 'private final fun (): kotlin.collections.MutableMap.Flaf> declared in .Flaf' type=kotlin.collections.MutableMap.Flaf> origin=GET_PROPERTY + $this: GET_VAR ': .Flaf declared in .Flaf.forJavaName' type=.Flaf origin=null + key: GET_VAR 'javaName: kotlin.String declared in .Flaf.forJavaName' type=kotlin.String origin=null + value: TYPE_OP type=.Flaf origin=IMPLICIT_CAST typeOperand=.Flaf + GET_VAR 'var result: .Flaf? [var] declared in .Flaf.forJavaName' type=.Flaf? origin=null RETURN type=kotlin.Nothing from='public final fun forJavaName (javaName: kotlin.String): .Flaf declared in .Flaf' - GET_VAR 'var result: .Flaf? [var] declared in .Flaf.forJavaName' type=.Flaf? origin=null + TYPE_OP type=.Flaf origin=IMPLICIT_CAST typeOperand=.Flaf + GET_VAR 'var result: .Flaf? [var] declared in .Flaf.forJavaName' type=.Flaf? origin=null FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] overridden: public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/42.fir.kt b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/42.fir.kt index 3f3d9c5291d..9f0ec94f07c 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/42.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/42.fir.kt @@ -19,8 +19,8 @@ fun case_1(x: Any) { */ fun case_2(x: Any?) { if (x is Int || x is Float?) { - x - x.toByte() + ? & kotlin.Any?")!>x + ? & kotlin.Any?")!>x.toByte() } } @@ -30,8 +30,8 @@ fun case_2(x: Any?) { */ fun case_3(x: Any?) { if (x is Int? || x is Float) { - x - x.toByte() + ? & kotlin.Any?")!>x + ? & kotlin.Any?")!>x.toByte() } }