Don't add Enum.entries to scope if it can't be called

^KT-53929 Fixed
This commit is contained in:
Roman Efremov
2023-01-03 14:44:35 +01:00
parent 2dc3871954
commit 878608b7b2
14 changed files with 88 additions and 19 deletions
@@ -31,7 +31,8 @@ import org.jetbrains.kotlin.utils.SmartList
// We don't need to track lookups here since this scope used only for introduce special Enum class members
class StaticScopeForKotlinEnum(
storageManager: StorageManager,
private val containingClass: ClassDescriptor
private val containingClass: ClassDescriptor,
private val enumEntriesCanBeUsed: Boolean,
) : MemberScopeImpl() {
init {
assert(containingClass.kind == ClassKind.ENUM_CLASS) { "Class should be an enum: $containingClass" }
@@ -44,7 +45,12 @@ class StaticScopeForKotlinEnum(
}
private val properties: List<PropertyDescriptor> by storageManager.createLazyValue {
listOfNotNull(createEnumEntriesProperty(containingClass))
if (enumEntriesCanBeUsed) {
// It still might be filtered out later in tower resolve if feature disabled
listOfNotNull(createEnumEntriesProperty(containingClass))
} else {
emptyList()
}
}
override fun getContributedDescriptors(kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean) = functions + properties