diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java index 5ee0abe7862..1820ff3c8b8 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java @@ -18036,6 +18036,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti runTest("compiler/testData/diagnostics/tests/multiplatform/exhaustiveness/expectSealedClass.kt"); } + @Test + @TestMetadata("expectSealedClassWithActualTypealias.kt") + public void testExpectSealedClassWithActualTypealias() throws Exception { + runTest("compiler/testData/diagnostics/tests/multiplatform/exhaustiveness/expectSealedClassWithActualTypealias.kt"); + } + @Test @TestMetadata("expectSealedInterface.kt") public void testExpectSealedInterface() throws Exception { diff --git a/compiler/testData/diagnostics/tests/multiplatform/exhaustiveness/expectSealedClassWithActualTypealias.kt b/compiler/testData/diagnostics/tests/multiplatform/exhaustiveness/expectSealedClassWithActualTypealias.kt new file mode 100644 index 00000000000..d9c2ae04c6e --- /dev/null +++ b/compiler/testData/diagnostics/tests/multiplatform/exhaustiveness/expectSealedClassWithActualTypealias.kt @@ -0,0 +1,25 @@ +// FIR_IDENTICAL +// !LANGUAGE: +MultiPlatformProjects +// ISSUE: KT-45796 +// SKIP_TXT + +// MODULE: m1-common +expect sealed class SealedClass() + +class Derived1 : SealedClass() + +// MODULE: m1-jvm(m1-common) +actual typealias SealedClass = MySealedClass + +sealed class MySealedClass + +class Derived2 : SealedClass() +class Derived3 : MySealedClass() + +fun whenForSealed(s: SealedClass): Int { + return when (s) { // Should be OK + is Derived1 -> 1 + is Derived2 -> 2 + is Derived3 -> 3 + } +} diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java index 372d5e61ac6..c1f60529aa7 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java @@ -18042,6 +18042,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/tests/multiplatform/exhaustiveness/expectSealedClass.kt"); } + @Test + @TestMetadata("expectSealedClassWithActualTypealias.kt") + public void testExpectSealedClassWithActualTypealias() throws Exception { + runTest("compiler/testData/diagnostics/tests/multiplatform/exhaustiveness/expectSealedClassWithActualTypealias.kt"); + } + @Test @TestMetadata("expectSealedInterface.kt") public void testExpectSealedInterface() throws Exception { diff --git a/core/descriptors/src/org/jetbrains/kotlin/resolve/SealedClassInheritorsProvider.kt b/core/descriptors/src/org/jetbrains/kotlin/resolve/SealedClassInheritorsProvider.kt index b73d6230fd3..ee7805389f9 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/resolve/SealedClassInheritorsProvider.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/resolve/SealedClassInheritorsProvider.kt @@ -8,14 +8,12 @@ package org.jetbrains.kotlin.resolve import org.jetbrains.kotlin.descriptors.ClassDescriptor import org.jetbrains.kotlin.descriptors.Modality import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor -import org.jetbrains.kotlin.incremental.components.LookupLocation +import org.jetbrains.kotlin.descriptors.TypeAliasDescriptor import org.jetbrains.kotlin.incremental.components.NoLookupLocation import org.jetbrains.kotlin.resolve.descriptorUtil.parents import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter import org.jetbrains.kotlin.resolve.scopes.MemberScope -import org.jetbrains.kotlin.types.checker.KotlinTypeRefiner import org.jetbrains.kotlin.types.refinement.TypeRefinement -import org.jetbrains.kotlin.utils.addToStdlib.runIf abstract class SealedClassInheritorsProvider { /** @@ -48,9 +46,15 @@ object CliSealedClassInheritorsProvider : SealedClassInheritorsProvider() { * of theirs actuals, so we need to lookup for descriptor once again via * scope.getContributedClassifier() to match expects (if possible) */ - val refinedDescriptor = runIf(descriptor.isExpect) { - scope.getContributedClassifier(descriptor.name, NoLookupLocation.WHEN_GET_ALL_DESCRIPTORS) as? ClassDescriptor - } ?: descriptor + val refinedDescriptor = if (descriptor.isExpect) { + when (val actualDescriptor = scope.getContributedClassifier(descriptor.name, NoLookupLocation.WHEN_GET_ALL_DESCRIPTORS)) { + is ClassDescriptor -> actualDescriptor + is TypeAliasDescriptor -> actualDescriptor.classDescriptor + else -> null + } + } else { + descriptor + } ?: continue if (DescriptorUtils.isDirectSubclass(refinedDescriptor, sealedClass)) { result.add(refinedDescriptor)