Support actualization of expect sealed class with typealias in CliSealedClassInheritorsProvider
This commit is contained in:
committed by
TeamCityServer
parent
fe81078366
commit
a107e3d160
+6
@@ -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 {
|
||||
|
||||
+25
@@ -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
|
||||
}
|
||||
}
|
||||
Generated
+6
@@ -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 {
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user