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
@@ -0,0 +1,25 @@
/*
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.serialization.deserialization
interface EnumEntriesDeserializationSupport {
/**
* Determines whether `Enum.entries` property can be synthesized for enums in this module,
* when this property is not present in compiled code.
* Returns `null` if it's not known.
*/
fun canSynthesizeEnumEntries(): Boolean?
object Default : EnumEntriesDeserializationSupport {
override fun canSynthesizeEnumEntries(): Boolean? = null
}
}
object JvmEnumEntriesDeserializationSupport : EnumEntriesDeserializationSupport {
// In JVM modules "entries" can be called even on enum compiled without this property.
override fun canSynthesizeEnumEntries(): Boolean = true
}
@@ -55,7 +55,8 @@ class DeserializationComponents(
val kotlinTypeChecker: NewKotlinTypeChecker = NewKotlinTypeChecker.Default,
val samConversionResolver: SamConversionResolver,
val platformDependentTypeTransformer: PlatformDependentTypeTransformer = PlatformDependentTypeTransformer.None,
val typeAttributeTranslators: List<TypeAttributeTranslator> = listOf(DefaultTypeAttributeTranslator)
val typeAttributeTranslators: List<TypeAttributeTranslator> = listOf(DefaultTypeAttributeTranslator),
val enumEntriesDeserializationSupport: EnumEntriesDeserializationSupport = EnumEntriesDeserializationSupport.Default,
) {
val classDeserializer: ClassDeserializer = ClassDeserializer(this)
@@ -53,10 +53,13 @@ class DeserializedClassDescriptor(
)
private val staticScope =
if (kind == ClassKind.ENUM_CLASS)
StaticScopeForKotlinEnum(c.storageManager, this)
else
if (kind == ClassKind.ENUM_CLASS) {
val enumEntriesCanBeUsed = Flags.HAS_ENUM_ENTRIES.get(classProto.flags) ||
c.components.enumEntriesDeserializationSupport.canSynthesizeEnumEntries() == true
StaticScopeForKotlinEnum(c.storageManager, this, enumEntriesCanBeUsed)
} else {
MemberScope.Empty
}
private val typeConstructor = DeserializedClassTypeConstructor()