[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:
Dmitriy Novozhilov
2021-02-10 12:08:18 +03:00
parent 903defdf30
commit 0c0c53cc2e
7 changed files with 89 additions and 3 deletions
@@ -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()
@@ -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>()