diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirWhenExhaustivenessTransformer.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirWhenExhaustivenessTransformer.kt index 1c78aefd95a..00ce0ed10da 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirWhenExhaustivenessTransformer.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirWhenExhaustivenessTransformer.kt @@ -11,6 +11,7 @@ import org.jetbrains.kotlin.descriptors.Modality import org.jetbrains.kotlin.diagnostics.WhenMissingCase import org.jetbrains.kotlin.fir.* import org.jetbrains.kotlin.fir.declarations.* +import org.jetbrains.kotlin.fir.declarations.utils.isExpect import org.jetbrains.kotlin.fir.declarations.utils.modality import org.jetbrains.kotlin.fir.expressions.* import org.jetbrains.kotlin.fir.expressions.impl.FirElseIfTrueCondition @@ -120,19 +121,21 @@ class FirWhenExhaustivenessTransformer(private val bodyResolveComponents: BodyRe return } - val unwrappedIntersectionTypes = subjectType.unwrapIntersectionType() - var status: ExhaustivenessStatus = ExhaustivenessStatus.NotExhaustive.NO_ELSE_BRANCH - for (unwrappedSubjectType in unwrappedIntersectionTypes) { - val localStatus = computeStatusForNonIntersectionType(unwrappedSubjectType, session, whenExpression) - when { - localStatus === ExhaustivenessStatus.ProperlyExhaustive -> { - status = localStatus - break - } - localStatus !== ExhaustivenessStatus.NotExhaustive.NO_ELSE_BRANCH && status === ExhaustivenessStatus.NotExhaustive.NO_ELSE_BRANCH -> { - status = localStatus + if (subjectType.toRegularClassSymbol(session)?.isExpect != true) { + val unwrappedIntersectionTypes = subjectType.unwrapIntersectionType() + + for (unwrappedSubjectType in unwrappedIntersectionTypes) { + val localStatus = computeStatusForNonIntersectionType(unwrappedSubjectType, session, whenExpression) + when { + localStatus === ExhaustivenessStatus.ProperlyExhaustive -> { + status = localStatus + break + } + localStatus !== ExhaustivenessStatus.NotExhaustive.NO_ELSE_BRANCH && status === ExhaustivenessStatus.NotExhaustive.NO_ELSE_BRANCH -> { + status = localStatus + } } } } diff --git a/compiler/testData/diagnostics/tests/multiplatform/exhaustiveness/expectEnum.fir.kt b/compiler/testData/diagnostics/tests/multiplatform/exhaustiveness/expectEnum.fir.kt index 5e97794092b..18808977069 100644 --- a/compiler/testData/diagnostics/tests/multiplatform/exhaustiveness/expectEnum.fir.kt +++ b/compiler/testData/diagnostics/tests/multiplatform/exhaustiveness/expectEnum.fir.kt @@ -8,7 +8,7 @@ expect enum class Base { } fun testCommon(base: Base) { - val x = when (base) { // must be an error + val x = when (base) { // must be an error Base.A -> 1 Base.B -> 2 } diff --git a/compiler/testData/diagnostics/tests/multiplatform/exhaustiveness/expectSealedClass.fir.kt b/compiler/testData/diagnostics/tests/multiplatform/exhaustiveness/expectSealedClass.fir.kt index a1d270de619..e39f55a9f72 100644 --- a/compiler/testData/diagnostics/tests/multiplatform/exhaustiveness/expectSealedClass.fir.kt +++ b/compiler/testData/diagnostics/tests/multiplatform/exhaustiveness/expectSealedClass.fir.kt @@ -9,7 +9,7 @@ class A : Base() object B : Base() fun testCommon(base: Base) { - val x = when (base) { // must be an error + val x = when (base) { // must be an error is A -> 1 B -> 2 } diff --git a/compiler/testData/diagnostics/tests/multiplatform/exhaustiveness/expectSealedInterface.fir.kt b/compiler/testData/diagnostics/tests/multiplatform/exhaustiveness/expectSealedInterface.fir.kt index 1d5ef0265a6..28d97a55ab5 100644 --- a/compiler/testData/diagnostics/tests/multiplatform/exhaustiveness/expectSealedInterface.fir.kt +++ b/compiler/testData/diagnostics/tests/multiplatform/exhaustiveness/expectSealedInterface.fir.kt @@ -9,7 +9,7 @@ class A : Base object B : Base fun testCommon(base: Base) { - val x = when (base) { // must be an error + val x = when (base) { // must be an error is A -> 1 B -> 2 } diff --git a/compiler/testData/diagnostics/tests/multiplatform/exhaustiveness/kt45796.fir.kt b/compiler/testData/diagnostics/tests/multiplatform/exhaustiveness/kt45796.fir.kt index 80d21909659..481cd2ef425 100644 --- a/compiler/testData/diagnostics/tests/multiplatform/exhaustiveness/kt45796.fir.kt +++ b/compiler/testData/diagnostics/tests/multiplatform/exhaustiveness/kt45796.fir.kt @@ -8,7 +8,7 @@ expect sealed class SealedClass() { } fun whenForExpectSealed(s: SealedClass): Int { - return when (s) { // should be error, because actual sealed class may add more implementations + return when (s) { // should be error, because actual sealed class may add more implementations is SealedClass.Nested.NestedDeeper -> 7 is SealedClass.Nested -> 8 }