KT-56687: Unify handling of EnumEntries.
`supportsEnumEntries` in `EnumCLassLowering` is not really needed, but it was left just in case. Both K1 and K2 ensure the feature is enabled before they generate IR. `supportsEnumEntries` is not enough, because the frontend will not generate `entries` if `kotlin.enums.EnumEntries` is not available (linking against an outdated stdlib is considered a valid use-case). From the resolution point of view, it's OK to resolve into `entries` while the feature is off, because then K1 reports an error on the call site. ^KT-56687 Fixed ^KT-55614 Fixed
This commit is contained in:
committed by
Space Team
parent
bcfafc601e
commit
bb368bd191
+10
-7
@@ -124,7 +124,13 @@ private class EnumClassLowering(private val context: JvmBackendContext) : ClassL
|
||||
val valuesField = buildValuesField(valuesHelperFunction)
|
||||
|
||||
val entriesField = when {
|
||||
irClass.declarations.any { it.isGetEntriesFunction } -> {
|
||||
!irClass.hasGetEntriesFunction -> {
|
||||
null
|
||||
}
|
||||
!supportsEnumEntries -> {
|
||||
error("The frontend must have checked if the feature is supported while emitting the IR")
|
||||
}
|
||||
else -> {
|
||||
// Constructs the synthetic $entries() function that returns plain $VALUES without copy
|
||||
val entriesHelperFunction = buildEntriesHelperFunction(valuesField)
|
||||
|
||||
@@ -137,12 +143,6 @@ private class EnumClassLowering(private val context: JvmBackendContext) : ClassL
|
||||
*/
|
||||
buildEntriesField(entriesHelperFunction)
|
||||
}
|
||||
supportsEnumEntries -> {
|
||||
error("kotlin.enums.EnumEntries is not available to the frontend. Is non-full kotlin stdlib being used?")
|
||||
}
|
||||
else -> {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
// Add synthetic parameters to enum constructors and implement the values and valueOf functions
|
||||
@@ -152,6 +152,9 @@ private class EnumClassLowering(private val context: JvmBackendContext) : ClassL
|
||||
irClass.transformChildrenVoid(EnumClassCallTransformer())
|
||||
}
|
||||
|
||||
private val IrClass.hasGetEntriesFunction: Boolean
|
||||
get() = declarations.any { it.isGetEntriesFunction }
|
||||
|
||||
private val IrDeclaration.isGetEntriesFunction: Boolean
|
||||
get() = this is IrFunction && name == SpecialNames.ENUM_GET_ENTRIES && origin == IrDeclarationOrigin.ENUM_CLASS_SPECIAL_MEMBER
|
||||
|
||||
|
||||
Reference in New Issue
Block a user