[FE] Don't analyze members with CLASSIFIERS kind filter in AbstractLazyMemberScope
This commit introduces partial support of descriptorKindFilter in
`AbstractPsiBasedDeclarationProvider`. Without it there may be an error
in following case:
```
sealed class Base
class Derived : Base()
class Test<out V>(val x: Base) {
private val y = when (x) {
is Derived -> null
}
}
```
Here we start to resolve type of `y`, then go to computation of inheritors
of sealed class Base, which also may be inside Test, so we need get all
nested classifiers in Test. But without this filtration we will start
computing descriptor for `y` again, which leads to ReenteringLazyComputationException
#KT-44316 Fixed
This commit is contained in:
+7
-2
@@ -88,8 +88,13 @@ abstract class AbstractPsiBasedDeclarationProvider(storageManager: StorageManage
|
||||
|
||||
internal fun toInfoString() = toString() + ": " + index().toString()
|
||||
|
||||
override fun getDeclarations(kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean): List<KtDeclaration> =
|
||||
index().allDeclarations
|
||||
override fun getDeclarations(kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean): List<KtDeclaration> {
|
||||
val allDeclarations = index().allDeclarations
|
||||
if (kindFilter == DescriptorKindFilter.CLASSIFIERS) {
|
||||
return allDeclarations.filter { it is KtClassOrObject || it is KtTypeAlias }
|
||||
}
|
||||
return allDeclarations
|
||||
}
|
||||
|
||||
override fun getFunctionDeclarations(name: Name): List<KtNamedFunction> = index().functions[name.safeNameForLazyResolve()].toList()
|
||||
|
||||
|
||||
+17
-1
@@ -70,10 +70,26 @@ open class LazyClassMemberScope(
|
||||
result.toList()
|
||||
}
|
||||
|
||||
private val allClassifierDescriptors = storageManager.createLazyValue {
|
||||
val result = LinkedHashSet(
|
||||
computeDescriptorsFromDeclaredElements(
|
||||
DescriptorKindFilter.CLASSIFIERS,
|
||||
MemberScope.ALL_NAME_FILTER,
|
||||
NoLookupLocation.WHEN_GET_ALL_DESCRIPTORS
|
||||
)
|
||||
)
|
||||
addSyntheticCompanionObject(result, NoLookupLocation.FOR_ALREADY_TRACKED)
|
||||
addSyntheticNestedClasses(result, NoLookupLocation.FOR_ALREADY_TRACKED)
|
||||
result.toList()
|
||||
}
|
||||
|
||||
override fun getContributedDescriptors(
|
||||
kindFilter: DescriptorKindFilter,
|
||||
nameFilter: (Name) -> Boolean
|
||||
): Collection<DeclarationDescriptor> = allDescriptors()
|
||||
): Collection<DeclarationDescriptor> = when (kindFilter) {
|
||||
DescriptorKindFilter.CLASSIFIERS -> allClassifierDescriptors()
|
||||
else -> allDescriptors()
|
||||
}
|
||||
|
||||
protected open fun computeExtraDescriptors(location: LookupLocation): Collection<DeclarationDescriptor> {
|
||||
val result = ArrayList<DeclarationDescriptor>()
|
||||
|
||||
Reference in New Issue
Block a user