[FE] Collect inheritors of sealed classes from new places in computeSealedSubclasses
#KT-13495
This commit is contained in:
committed by
TeamCityServer
parent
70c61be1ef
commit
e76acc8ee0
@@ -377,7 +377,7 @@ fun ClassifierDescriptor.getAllSuperClassifiers(): Sequence<ClassifierDescriptor
|
||||
// Note this is a generic and slow implementation which would work almost for any subclass of ClassDescriptor.
|
||||
// Please avoid using it in new code.
|
||||
// TODO: do something more clever instead at call sites of this function
|
||||
fun computeSealedSubclasses(sealedClass: ClassDescriptor): Collection<ClassDescriptor> {
|
||||
fun computeSealedSubclasses(sealedClass: ClassDescriptor, freedomForSealedInterfacesSupported: Boolean): Collection<ClassDescriptor> {
|
||||
if (sealedClass.modality != Modality.SEALED) return emptyList()
|
||||
|
||||
val result = linkedSetOf<ClassDescriptor>()
|
||||
@@ -396,9 +396,16 @@ fun computeSealedSubclasses(sealedClass: ClassDescriptor): Collection<ClassDescr
|
||||
}
|
||||
}
|
||||
|
||||
val container = sealedClass.containingDeclaration
|
||||
val container = if (!freedomForSealedInterfacesSupported) {
|
||||
sealedClass.containingDeclaration
|
||||
} else {
|
||||
sealedClass.parents.firstOrNull { it is PackageFragmentDescriptor }
|
||||
}
|
||||
if (container is PackageFragmentDescriptor) {
|
||||
collectSubclasses(container.getMemberScope(), collectNested = false)
|
||||
collectSubclasses(
|
||||
container.getMemberScope(),
|
||||
collectNested = freedomForSealedInterfacesSupported
|
||||
)
|
||||
}
|
||||
collectSubclasses(sealedClass.unsubstitutedInnerClassesScope, collectNested = true)
|
||||
return result
|
||||
|
||||
+1
-1
@@ -165,7 +165,7 @@ class DeserializedClassDescriptor(
|
||||
}
|
||||
|
||||
// This is needed because classes compiled with Kotlin 1.0 did not contain the sealed_subclass_fq_name field
|
||||
return computeSealedSubclasses(this)
|
||||
return computeSealedSubclasses(this, freedomForSealedInterfacesSupported = false)
|
||||
}
|
||||
|
||||
override fun getSealedSubclasses() = sealedSubclasses()
|
||||
|
||||
Reference in New Issue
Block a user