[FIR] Support static getters along with fake Enum.entries declaration in FIR
#KT-48872
This commit is contained in:
committed by
Space
parent
45b89de9f4
commit
93f17a2b86
+1
@@ -190,6 +190,7 @@ fun deserializeClassToSymbol(
|
|||||||
classId.relativeClassName
|
classId.relativeClassName
|
||||||
)
|
)
|
||||||
generateValueOfFunction(moduleData, classId.packageFqName, classId.relativeClassName)
|
generateValueOfFunction(moduleData, classId.packageFqName, classId.relativeClassName)
|
||||||
|
generateEntriesGetter(moduleData, classId.packageFqName, classId.relativeClassName)
|
||||||
}
|
}
|
||||||
|
|
||||||
addCloneForArrayIfNeeded(classId, context.dispatchReceiver)
|
addCloneForArrayIfNeeded(classId, context.dispatchReceiver)
|
||||||
|
|||||||
+7
-3
@@ -740,7 +740,8 @@ class Fir2IrDeclarationStorage(
|
|||||||
}
|
}
|
||||||
bindAndDeclareParameters(
|
bindAndDeclareParameters(
|
||||||
propertyAccessor, irParent,
|
propertyAccessor, irParent,
|
||||||
thisReceiverOwner, isStatic = irParent !is IrClass, parentPropertyReceiverType = property.receiverTypeRef
|
thisReceiverOwner, isStatic = irParent !is IrClass || propertyAccessor?.isStatic == true,
|
||||||
|
parentPropertyReceiverType = property.receiverTypeRef
|
||||||
)
|
)
|
||||||
leaveScope(this)
|
leaveScope(this)
|
||||||
if (irParent != null) {
|
if (irParent != null) {
|
||||||
@@ -853,7 +854,9 @@ class Fir2IrDeclarationStorage(
|
|||||||
containingClass: ConeClassLikeLookupTag? = (irParent as? IrClass)?.classId?.let { ConeClassLikeLookupTagImpl(it) },
|
containingClass: ConeClassLikeLookupTag? = (irParent as? IrClass)?.classId?.let { ConeClassLikeLookupTagImpl(it) },
|
||||||
forceTopLevelPrivate: Boolean = false,
|
forceTopLevelPrivate: Boolean = false,
|
||||||
): IrProperty = convertCatching(property) {
|
): IrProperty = convertCatching(property) {
|
||||||
val origin = property.computeIrOrigin(predefinedOrigin)
|
val origin = if (property.isStatic && property.name in ENUM_SYNTHETIC_NAMES)
|
||||||
|
IrDeclarationOrigin.ENUM_CLASS_SPECIAL_MEMBER
|
||||||
|
else property.computeIrOrigin(predefinedOrigin)
|
||||||
// See similar comments in createIrFunction above
|
// See similar comments in createIrFunction above
|
||||||
val signature =
|
val signature =
|
||||||
runUnless(
|
runUnless(
|
||||||
@@ -1606,7 +1609,8 @@ class Fir2IrDeclarationStorage(
|
|||||||
companion object {
|
companion object {
|
||||||
internal val ENUM_SYNTHETIC_NAMES = mapOf(
|
internal val ENUM_SYNTHETIC_NAMES = mapOf(
|
||||||
Name.identifier("values") to IrSyntheticBodyKind.ENUM_VALUES,
|
Name.identifier("values") to IrSyntheticBodyKind.ENUM_VALUES,
|
||||||
Name.identifier("valueOf") to IrSyntheticBodyKind.ENUM_VALUEOF
|
Name.identifier("valueOf") to IrSyntheticBodyKind.ENUM_VALUEOF,
|
||||||
|
Name.identifier("entries") to IrSyntheticBodyKind.ENUM_ENTRIES
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+7
@@ -168,6 +168,7 @@ internal class ClassMemberGenerator(
|
|||||||
}
|
}
|
||||||
} else if (irFunction !is IrConstructor && !irFunction.isExpect) {
|
} else if (irFunction !is IrConstructor && !irFunction.isExpect) {
|
||||||
when {
|
when {
|
||||||
|
// Create fake bodies for Enum.values/Enum.valueOf
|
||||||
irFunction.origin == IrDeclarationOrigin.ENUM_CLASS_SPECIAL_MEMBER -> {
|
irFunction.origin == IrDeclarationOrigin.ENUM_CLASS_SPECIAL_MEMBER -> {
|
||||||
val kind = Fir2IrDeclarationStorage.ENUM_SYNTHETIC_NAMES.getValue(irFunction.name)
|
val kind = Fir2IrDeclarationStorage.ENUM_SYNTHETIC_NAMES.getValue(irFunction.name)
|
||||||
irFunction.body = IrSyntheticBodyImpl(startOffset, endOffset, kind)
|
irFunction.body = IrSyntheticBodyImpl(startOffset, endOffset, kind)
|
||||||
@@ -215,6 +216,12 @@ internal class ClassMemberGenerator(
|
|||||||
isGetter = true,
|
isGetter = true,
|
||||||
containingClass = containingClass
|
containingClass = containingClass
|
||||||
)
|
)
|
||||||
|
// Create fake body for Enum.entries
|
||||||
|
if (irProperty.origin == IrDeclarationOrigin.ENUM_CLASS_SPECIAL_MEMBER) {
|
||||||
|
val kind = Fir2IrDeclarationStorage.ENUM_SYNTHETIC_NAMES.getValue(irProperty.name)
|
||||||
|
irProperty.getter!!.body = IrSyntheticBodyImpl(irProperty.startOffset, irProperty.endOffset, kind)
|
||||||
|
}
|
||||||
|
|
||||||
if (property.isVar) {
|
if (property.isVar) {
|
||||||
irProperty.setter?.setPropertyAccessorContent(
|
irProperty.setter?.setPropertyAccessorContent(
|
||||||
property, property.setter, irProperty, propertyType,
|
property, property.setter, irProperty, propertyType,
|
||||||
|
|||||||
Generated
+6
@@ -136,6 +136,12 @@ public class Fir2IrTextTestGenerated extends AbstractFir2IrTextTest {
|
|||||||
runTest("compiler/testData/ir/irText/classes/enumClassModality.kt");
|
runTest("compiler/testData/ir/irText/classes/enumClassModality.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("enumEntries.kt")
|
||||||
|
public void testEnumEntries() throws Exception {
|
||||||
|
runTest("compiler/testData/ir/irText/classes/enumEntries.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("enumWithMultipleCtors.kt")
|
@TestMetadata("enumWithMultipleCtors.kt")
|
||||||
public void testEnumWithMultipleCtors() throws Exception {
|
public void testEnumWithMultipleCtors() throws Exception {
|
||||||
|
|||||||
+6
@@ -136,6 +136,12 @@ public class LightTreeFir2IrTextTestGenerated extends AbstractLightTreeFir2IrTex
|
|||||||
runTest("compiler/testData/ir/irText/classes/enumClassModality.kt");
|
runTest("compiler/testData/ir/irText/classes/enumClassModality.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("enumEntries.kt")
|
||||||
|
public void testEnumEntries() throws Exception {
|
||||||
|
runTest("compiler/testData/ir/irText/classes/enumEntries.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("enumWithMultipleCtors.kt")
|
@TestMetadata("enumWithMultipleCtors.kt")
|
||||||
public void testEnumWithMultipleCtors() throws Exception {
|
public void testEnumWithMultipleCtors() throws Exception {
|
||||||
|
|||||||
@@ -348,6 +348,7 @@ abstract class FirJavaFacade(
|
|||||||
classId.relativeClassName
|
classId.relativeClassName
|
||||||
)
|
)
|
||||||
generateValueOfFunction(moduleData, classId.packageFqName, classId.relativeClassName)
|
generateValueOfFunction(moduleData, classId.packageFqName, classId.relativeClassName)
|
||||||
|
generateEntriesGetter(moduleData, classId.packageFqName, classId.relativeClassName)
|
||||||
}
|
}
|
||||||
if (classIsAnnotation) {
|
if (classIsAnnotation) {
|
||||||
declarations +=
|
declarations +=
|
||||||
|
|||||||
+6
@@ -590,6 +590,12 @@ class DeclarationsConverter(
|
|||||||
context.className,
|
context.className,
|
||||||
modifiers.hasExpect()
|
modifiers.hasExpect()
|
||||||
)
|
)
|
||||||
|
generateEntriesGetter(
|
||||||
|
baseModuleData,
|
||||||
|
context.packageFqName,
|
||||||
|
context.className,
|
||||||
|
modifiers.hasExpect()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
initCompanionObjectSymbolAttr()
|
initCompanionObjectSymbolAttr()
|
||||||
|
|
||||||
|
|||||||
@@ -1167,6 +1167,10 @@ open class RawFirBuilder(
|
|||||||
baseModuleData, context.packageFqName, context.className,
|
baseModuleData, context.packageFqName, context.className,
|
||||||
classIsExpect
|
classIsExpect
|
||||||
)
|
)
|
||||||
|
generateEntriesGetter(
|
||||||
|
baseModuleData, context.packageFqName, context.className,
|
||||||
|
classIsExpect
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
initCompanionObjectSymbolAttr()
|
initCompanionObjectSymbolAttr()
|
||||||
|
|||||||
@@ -7,22 +7,24 @@ package org.jetbrains.kotlin.fir
|
|||||||
|
|
||||||
import org.jetbrains.kotlin.KtFakeSourceElementKind
|
import org.jetbrains.kotlin.KtFakeSourceElementKind
|
||||||
import org.jetbrains.kotlin.builtins.StandardNames.DEFAULT_VALUE_PARAMETER
|
import org.jetbrains.kotlin.builtins.StandardNames.DEFAULT_VALUE_PARAMETER
|
||||||
|
import org.jetbrains.kotlin.builtins.StandardNames.ENUM_ENTRIES
|
||||||
import org.jetbrains.kotlin.builtins.StandardNames.ENUM_VALUES
|
import org.jetbrains.kotlin.builtins.StandardNames.ENUM_VALUES
|
||||||
import org.jetbrains.kotlin.builtins.StandardNames.ENUM_VALUE_OF
|
import org.jetbrains.kotlin.builtins.StandardNames.ENUM_VALUE_OF
|
||||||
|
import org.jetbrains.kotlin.config.LanguageFeature
|
||||||
import org.jetbrains.kotlin.descriptors.Modality
|
import org.jetbrains.kotlin.descriptors.Modality
|
||||||
import org.jetbrains.kotlin.descriptors.Visibilities
|
import org.jetbrains.kotlin.descriptors.Visibilities
|
||||||
import org.jetbrains.kotlin.fakeElement
|
import org.jetbrains.kotlin.fakeElement
|
||||||
import org.jetbrains.kotlin.fir.declarations.FirDeclarationOrigin
|
import org.jetbrains.kotlin.fir.declarations.FirDeclarationOrigin
|
||||||
import org.jetbrains.kotlin.fir.declarations.FirDeclarationStatus
|
import org.jetbrains.kotlin.fir.declarations.FirDeclarationStatus
|
||||||
import org.jetbrains.kotlin.fir.declarations.FirResolvePhase
|
import org.jetbrains.kotlin.fir.declarations.FirResolvePhase
|
||||||
import org.jetbrains.kotlin.fir.declarations.builder.FirRegularClassBuilder
|
import org.jetbrains.kotlin.fir.declarations.builder.*
|
||||||
import org.jetbrains.kotlin.fir.declarations.builder.buildSimpleFunction
|
|
||||||
import org.jetbrains.kotlin.fir.declarations.builder.buildValueParameter
|
|
||||||
import org.jetbrains.kotlin.fir.declarations.impl.FirDeclarationStatusImpl
|
import org.jetbrains.kotlin.fir.declarations.impl.FirDeclarationStatusImpl
|
||||||
|
import org.jetbrains.kotlin.fir.declarations.impl.FirDefaultPropertyGetter
|
||||||
import org.jetbrains.kotlin.fir.declarations.impl.FirResolvedDeclarationStatusImpl
|
import org.jetbrains.kotlin.fir.declarations.impl.FirResolvedDeclarationStatusImpl
|
||||||
import org.jetbrains.kotlin.fir.expressions.builder.buildEmptyExpressionBlock
|
import org.jetbrains.kotlin.fir.expressions.builder.buildEmptyExpressionBlock
|
||||||
import org.jetbrains.kotlin.fir.symbols.impl.ConeClassLikeLookupTagImpl
|
import org.jetbrains.kotlin.fir.symbols.impl.ConeClassLikeLookupTagImpl
|
||||||
import org.jetbrains.kotlin.fir.symbols.impl.FirNamedFunctionSymbol
|
import org.jetbrains.kotlin.fir.symbols.impl.FirNamedFunctionSymbol
|
||||||
|
import org.jetbrains.kotlin.fir.symbols.impl.FirPropertySymbol
|
||||||
import org.jetbrains.kotlin.fir.symbols.impl.FirValueParameterSymbol
|
import org.jetbrains.kotlin.fir.symbols.impl.FirValueParameterSymbol
|
||||||
import org.jetbrains.kotlin.fir.types.builder.buildResolvedTypeRef
|
import org.jetbrains.kotlin.fir.types.builder.buildResolvedTypeRef
|
||||||
import org.jetbrains.kotlin.fir.types.impl.ConeClassLikeTypeImpl
|
import org.jetbrains.kotlin.fir.types.impl.ConeClassLikeTypeImpl
|
||||||
@@ -114,6 +116,49 @@ fun FirRegularClassBuilder.generateValueOfFunction(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun FirRegularClassBuilder.generateEntriesGetter(
|
||||||
|
moduleData: FirModuleData, packageFqName: FqName, classFqName: FqName, makeExpect: Boolean = false
|
||||||
|
) {
|
||||||
|
if (!moduleData.session.languageVersionSettings.supportsFeature(LanguageFeature.EnumEntries)) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
val sourceElement = source?.fakeElement(KtFakeSourceElementKind.EnumGeneratedDeclaration)
|
||||||
|
declarations += buildProperty {
|
||||||
|
source = sourceElement
|
||||||
|
isVar = false
|
||||||
|
isLocal = false
|
||||||
|
origin = FirDeclarationOrigin.Source
|
||||||
|
this.moduleData = moduleData
|
||||||
|
returnTypeRef = buildResolvedTypeRef {
|
||||||
|
source = sourceElement
|
||||||
|
type = ConeClassLikeTypeImpl(
|
||||||
|
ConeClassLikeLookupTagImpl(StandardClassIds.EnumEntries),
|
||||||
|
arrayOf(
|
||||||
|
ConeClassLikeTypeImpl(this@generateEntriesGetter.symbol.toLookupTag(), emptyArray(), isNullable = false)
|
||||||
|
),
|
||||||
|
isNullable = false
|
||||||
|
)
|
||||||
|
}
|
||||||
|
name = ENUM_ENTRIES
|
||||||
|
this.status = createStatus(this@generateEntriesGetter.status).apply {
|
||||||
|
isStatic = true
|
||||||
|
isExpect = makeExpect
|
||||||
|
}
|
||||||
|
symbol = FirPropertySymbol(CallableId(packageFqName, classFqName, ENUM_ENTRIES))
|
||||||
|
resolvePhase = FirResolvePhase.BODY_RESOLVE
|
||||||
|
getter = FirDefaultPropertyGetter(
|
||||||
|
sourceElement?.fakeElement(KtFakeSourceElementKind.EnumGeneratedDeclaration),
|
||||||
|
moduleData, FirDeclarationOrigin.Source, returnTypeRef.copyWithNewSourceKind(KtFakeSourceElementKind.EnumGeneratedDeclaration),
|
||||||
|
Visibilities.Public, symbol
|
||||||
|
).apply {
|
||||||
|
(status as FirDeclarationStatusImpl).isStatic = true
|
||||||
|
}
|
||||||
|
}.apply {
|
||||||
|
containingClassForStaticMemberAttr = this@generateEntriesGetter.symbol.toLookupTag()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun createStatus(parentStatus: FirDeclarationStatus): FirDeclarationStatusImpl {
|
private fun createStatus(parentStatus: FirDeclarationStatus): FirDeclarationStatusImpl {
|
||||||
val parentEffectiveVisibility = (parentStatus as? FirResolvedDeclarationStatusImpl)?.effectiveVisibility
|
val parentEffectiveVisibility = (parentStatus as? FirResolvedDeclarationStatusImpl)?.effectiveVisibility
|
||||||
return if (parentEffectiveVisibility != null) {
|
return if (parentEffectiveVisibility != null) {
|
||||||
|
|||||||
+1
@@ -77,6 +77,7 @@ val FirProperty.hasBackingField: Boolean
|
|||||||
if (isAbstract) return false
|
if (isAbstract) return false
|
||||||
if (delegate != null) return false
|
if (delegate != null) return false
|
||||||
if (hasExplicitBackingField) return true
|
if (hasExplicitBackingField) return true
|
||||||
|
if (isStatic) return false // For Enum.entries
|
||||||
when (origin) {
|
when (origin) {
|
||||||
FirDeclarationOrigin.SubstitutionOverride -> return false
|
FirDeclarationOrigin.SubstitutionOverride -> return false
|
||||||
FirDeclarationOrigin.IntersectionOverride -> return false
|
FirDeclarationOrigin.IntersectionOverride -> return false
|
||||||
|
|||||||
+1
@@ -490,6 +490,7 @@ class EnumSyntheticFunctionsLowering(val context: JsCommonBackendContext) : Decl
|
|||||||
statements += when (kind) {
|
statements += when (kind) {
|
||||||
IrSyntheticBodyKind.ENUM_VALUES -> createEnumValuesBody(declaration, enumClass)
|
IrSyntheticBodyKind.ENUM_VALUES -> createEnumValuesBody(declaration, enumClass)
|
||||||
IrSyntheticBodyKind.ENUM_VALUEOF -> createEnumValueOfBody(declaration, enumClass)
|
IrSyntheticBodyKind.ENUM_VALUEOF -> createEnumValueOfBody(declaration, enumClass)
|
||||||
|
IrSyntheticBodyKind.ENUM_ENTRIES -> TODO("NOT IMPLEMENTED ON JS")
|
||||||
}.statements
|
}.statements
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,5 +7,6 @@ package org.jetbrains.kotlin.ir.expressions
|
|||||||
|
|
||||||
enum class IrSyntheticBodyKind {
|
enum class IrSyntheticBodyKind {
|
||||||
ENUM_VALUES,
|
ENUM_VALUES,
|
||||||
ENUM_VALUEOF
|
ENUM_VALUEOF,
|
||||||
|
ENUM_ENTRIES
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,73 @@
|
|||||||
|
FILE fqName:<root> fileName:/enumEntries.kt
|
||||||
|
CLASS ENUM_CLASS name:MyEnum modality:FINAL visibility:public superTypes:[kotlin.Enum<<root>.MyEnum>]
|
||||||
|
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.MyEnum
|
||||||
|
CONSTRUCTOR visibility:private <> () returnType:<root>.MyEnum [primary]
|
||||||
|
BLOCK_BODY
|
||||||
|
ENUM_CONSTRUCTOR_CALL 'public constructor <init> (name: kotlin.String, ordinal: kotlin.Int) [primary] declared in kotlin.Enum'
|
||||||
|
<E>: <root>.MyEnum
|
||||||
|
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS ENUM_CLASS name:MyEnum modality:FINAL visibility:public superTypes:[kotlin.Enum<<root>.MyEnum>]'
|
||||||
|
ENUM_ENTRY name:Ok
|
||||||
|
init: EXPRESSION_BODY
|
||||||
|
ENUM_CONSTRUCTOR_CALL 'private constructor <init> () [primary] declared in <root>.MyEnum'
|
||||||
|
ENUM_ENTRY name:Nope
|
||||||
|
init: EXPRESSION_BODY
|
||||||
|
ENUM_CONSTRUCTOR_CALL 'private constructor <init> () [primary] declared in <root>.MyEnum'
|
||||||
|
FUN ENUM_CLASS_SPECIAL_MEMBER name:values visibility:public modality:FINAL <> () returnType:kotlin.Array<<root>.MyEnum>
|
||||||
|
SYNTHETIC_BODY kind=ENUM_VALUES
|
||||||
|
FUN ENUM_CLASS_SPECIAL_MEMBER name:valueOf visibility:public modality:FINAL <> (value:kotlin.String) returnType:<root>.MyEnum
|
||||||
|
VALUE_PARAMETER name:value index:0 type:kotlin.String
|
||||||
|
SYNTHETIC_BODY kind=ENUM_VALUEOF
|
||||||
|
PROPERTY ENUM_CLASS_SPECIAL_MEMBER name:entries visibility:public modality:FINAL [val]
|
||||||
|
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-entries> visibility:public modality:FINAL <> () returnType:kotlin.enums.EnumEntries<<root>.MyEnum>
|
||||||
|
correspondingProperty: PROPERTY ENUM_CLASS_SPECIAL_MEMBER name:entries visibility:public modality:FINAL [val]
|
||||||
|
SYNTHETIC_BODY kind=ENUM_ENTRIES
|
||||||
|
FUN FAKE_OVERRIDE name:clone visibility:protected modality:FINAL <> ($this:kotlin.Enum<E of kotlin.Enum>) returnType:kotlin.Any [fake_override]
|
||||||
|
overridden:
|
||||||
|
protected final fun clone (): kotlin.Any declared in kotlin.Enum
|
||||||
|
$this: VALUE_PARAMETER name:<this> type:kotlin.Enum<E of kotlin.Enum>
|
||||||
|
FUN FAKE_OVERRIDE name:compareTo visibility:public modality:FINAL <> ($this:kotlin.Enum<E of kotlin.Enum>, other:<root>.MyEnum) returnType:kotlin.Int [fake_override,operator]
|
||||||
|
overridden:
|
||||||
|
public final fun compareTo (other: E of kotlin.Enum): kotlin.Int [operator] declared in kotlin.Enum
|
||||||
|
$this: VALUE_PARAMETER name:<this> type:kotlin.Enum<E of kotlin.Enum>
|
||||||
|
VALUE_PARAMETER name:other index:0 type:<root>.MyEnum
|
||||||
|
FUN FAKE_OVERRIDE name:equals visibility:public modality:FINAL <> ($this:kotlin.Enum<E of kotlin.Enum>, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator]
|
||||||
|
overridden:
|
||||||
|
public final fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Enum
|
||||||
|
$this: VALUE_PARAMETER name:<this> type:kotlin.Enum<E of kotlin.Enum>
|
||||||
|
VALUE_PARAMETER name:other index:0 type:kotlin.Any?
|
||||||
|
FUN FAKE_OVERRIDE name:hashCode visibility:public modality:FINAL <> ($this:kotlin.Enum<E of kotlin.Enum>) returnType:kotlin.Int [fake_override]
|
||||||
|
overridden:
|
||||||
|
public final fun hashCode (): kotlin.Int declared in kotlin.Enum
|
||||||
|
$this: VALUE_PARAMETER name:<this> type:kotlin.Enum<E of kotlin.Enum>
|
||||||
|
FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Enum<E of kotlin.Enum>) returnType:kotlin.String [fake_override]
|
||||||
|
overridden:
|
||||||
|
public open fun toString (): kotlin.String declared in kotlin.Enum
|
||||||
|
$this: VALUE_PARAMETER name:<this> type:kotlin.Enum<E of kotlin.Enum>
|
||||||
|
PROPERTY FAKE_OVERRIDE name:name visibility:public modality:FINAL [fake_override,val]
|
||||||
|
annotations:
|
||||||
|
IntrinsicConstEvaluation
|
||||||
|
overridden:
|
||||||
|
public final name: kotlin.String [val]
|
||||||
|
FUN FAKE_OVERRIDE name:<get-name> visibility:public modality:FINAL <> ($this:kotlin.Enum<E of kotlin.Enum>) returnType:kotlin.String [fake_override]
|
||||||
|
correspondingProperty: PROPERTY FAKE_OVERRIDE name:name visibility:public modality:FINAL [fake_override,val]
|
||||||
|
overridden:
|
||||||
|
public final fun <get-name> (): kotlin.String declared in kotlin.Enum
|
||||||
|
$this: VALUE_PARAMETER name:<this> type:kotlin.Enum<E of kotlin.Enum>
|
||||||
|
PROPERTY FAKE_OVERRIDE name:ordinal visibility:public modality:FINAL [fake_override,val]
|
||||||
|
overridden:
|
||||||
|
public final ordinal: kotlin.Int [val]
|
||||||
|
FUN FAKE_OVERRIDE name:<get-ordinal> visibility:public modality:FINAL <> ($this:kotlin.Enum<E of kotlin.Enum>) returnType:kotlin.Int [fake_override]
|
||||||
|
correspondingProperty: PROPERTY FAKE_OVERRIDE name:ordinal visibility:public modality:FINAL [fake_override,val]
|
||||||
|
overridden:
|
||||||
|
public final fun <get-ordinal> (): kotlin.Int declared in kotlin.Enum
|
||||||
|
$this: VALUE_PARAMETER name:<this> type:kotlin.Enum<E of kotlin.Enum>
|
||||||
|
FUN FAKE_OVERRIDE name:getDeclaringClass visibility:public modality:FINAL <> ($this:kotlin.Enum<E of kotlin.Enum>) returnType:@[FlexibleNullability] java.lang.Class<@[FlexibleNullability] <root>.MyEnum?>? [fake_override]
|
||||||
|
overridden:
|
||||||
|
public final fun getDeclaringClass (): @[FlexibleNullability] java.lang.Class<@[FlexibleNullability] E of kotlin.Enum?>? declared in kotlin.Enum
|
||||||
|
$this: VALUE_PARAMETER name:<this> type:kotlin.Enum<E of kotlin.Enum>
|
||||||
|
FUN name:box visibility:public modality:FINAL <> () returnType:kotlin.enums.EnumEntries<<root>.MyEnum>
|
||||||
|
annotations:
|
||||||
|
OptIn(markerClass = [CLASS_REFERENCE 'CLASS IR_EXTERNAL_DECLARATION_STUB ANNOTATION_CLASS name:ExperimentalStdlibApi modality:FINAL visibility:public superTypes:[kotlin.Annotation]' type=kotlin.reflect.KClass<kotlin.ExperimentalStdlibApi>])
|
||||||
|
BLOCK_BODY
|
||||||
|
RETURN type=kotlin.Nothing from='public final fun box (): kotlin.enums.EnumEntries<<root>.MyEnum> declared in <root>'
|
||||||
|
CALL 'public final fun <get-entries> (): kotlin.enums.EnumEntries<<root>.MyEnum> declared in <root>.MyEnum' type=kotlin.enums.EnumEntries<<root>.MyEnum> origin=GET_PROPERTY
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
// FIR_IDENTICAL
|
||||||
|
// !LANGUAGE: +EnumEntries
|
||||||
|
// TARGET_BACKEND: JVM_IR
|
||||||
|
// FULL_JDK
|
||||||
|
// WITH_STDLIB
|
||||||
|
|
||||||
|
enum class MyEnum {
|
||||||
|
Ok, Nope
|
||||||
|
}
|
||||||
|
|
||||||
|
@OptIn(ExperimentalStdlibApi::class)
|
||||||
|
fun box() = MyEnum.entries
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
enum class MyEnum : Enum<MyEnum> {
|
||||||
|
private constructor() /* primary */ {
|
||||||
|
super/*Enum*/<MyEnum>()
|
||||||
|
/* <init>() */
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok = MyEnum()
|
||||||
|
|
||||||
|
Nope = MyEnum()
|
||||||
|
|
||||||
|
fun values(): Array<MyEnum> /* Synthetic body for ENUM_VALUES */
|
||||||
|
|
||||||
|
fun valueOf(value: String): MyEnum /* Synthetic body for ENUM_VALUEOF */
|
||||||
|
|
||||||
|
val entries: EnumEntries<MyEnum>
|
||||||
|
get
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@OptIn(markerClass = [ExperimentalStdlibApi::class])
|
||||||
|
fun box(): EnumEntries<MyEnum> {
|
||||||
|
return <get-entries>()
|
||||||
|
}
|
||||||
@@ -264,6 +264,7 @@ enum class LanguageFeature(
|
|||||||
GenericInlineClassParameter(sinceVersion = KOTLIN_1_8, kind = UNSTABLE_FEATURE), // KT-32162
|
GenericInlineClassParameter(sinceVersion = KOTLIN_1_8, kind = UNSTABLE_FEATURE), // KT-32162
|
||||||
DataObjects(KOTLIN_1_8), // KT-4107
|
DataObjects(KOTLIN_1_8), // KT-4107
|
||||||
LightweightLambdas(KOTLIN_1_8, defaultState = State.DISABLED),
|
LightweightLambdas(KOTLIN_1_8, defaultState = State.DISABLED),
|
||||||
|
EnumEntries(KOTLIN_1_8, sinceApiVersion = ApiVersion.KOTLIN_1_8, defaultState = State.DISABLED), // KT-48872
|
||||||
|
|
||||||
// 1.9
|
// 1.9
|
||||||
|
|
||||||
|
|||||||
@@ -22,6 +22,8 @@ object StandardNames {
|
|||||||
|
|
||||||
@JvmField val ENUM_VALUES = Name.identifier("values")
|
@JvmField val ENUM_VALUES = Name.identifier("values")
|
||||||
|
|
||||||
|
@JvmField val ENUM_ENTRIES = Name.identifier("entries")
|
||||||
|
|
||||||
@JvmField val ENUM_VALUE_OF = Name.identifier("valueOf")
|
@JvmField val ENUM_VALUE_OF = Name.identifier("valueOf")
|
||||||
|
|
||||||
@JvmField val DATA_CLASS_COPY = Name.identifier("copy")
|
@JvmField val DATA_CLASS_COPY = Name.identifier("copy")
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ object StandardClassIds {
|
|||||||
val BASE_INTERNAL_PACKAGE = BASE_KOTLIN_PACKAGE.child(Name.identifier("internal"))
|
val BASE_INTERNAL_PACKAGE = BASE_KOTLIN_PACKAGE.child(Name.identifier("internal"))
|
||||||
val BASE_INTERNAL_IR_PACKAGE = BASE_INTERNAL_PACKAGE.child(Name.identifier("ir"))
|
val BASE_INTERNAL_IR_PACKAGE = BASE_INTERNAL_PACKAGE.child(Name.identifier("ir"))
|
||||||
val BASE_COROUTINES_PACKAGE = BASE_KOTLIN_PACKAGE.child(Name.identifier("coroutines"))
|
val BASE_COROUTINES_PACKAGE = BASE_KOTLIN_PACKAGE.child(Name.identifier("coroutines"))
|
||||||
|
val BASE_ENUMS_PACKAGE = BASE_KOTLIN_PACKAGE.child(Name.identifier("enums"))
|
||||||
|
|
||||||
val builtInsPackages = setOf(
|
val builtInsPackages = setOf(
|
||||||
BASE_KOTLIN_PACKAGE,
|
BASE_KOTLIN_PACKAGE,
|
||||||
@@ -24,7 +25,7 @@ object StandardClassIds {
|
|||||||
BASE_ANNOTATION_PACKAGE,
|
BASE_ANNOTATION_PACKAGE,
|
||||||
BASE_REFLECT_PACKAGE,
|
BASE_REFLECT_PACKAGE,
|
||||||
BASE_INTERNAL_PACKAGE,
|
BASE_INTERNAL_PACKAGE,
|
||||||
BASE_COROUTINES_PACKAGE,
|
BASE_COROUTINES_PACKAGE
|
||||||
)
|
)
|
||||||
|
|
||||||
val Nothing = "Nothing".baseId()
|
val Nothing = "Nothing".baseId()
|
||||||
@@ -134,6 +135,8 @@ object StandardClassIds {
|
|||||||
val AnnotationRetention = "AnnotationRetention".annotationId()
|
val AnnotationRetention = "AnnotationRetention".annotationId()
|
||||||
val AnnotationTarget = "AnnotationTarget".annotationId()
|
val AnnotationTarget = "AnnotationTarget".annotationId()
|
||||||
|
|
||||||
|
val EnumEntries = "EnumEntries".enumsId()
|
||||||
|
|
||||||
object Annotations {
|
object Annotations {
|
||||||
val Suppress = "Suppress".baseId()
|
val Suppress = "Suppress".baseId()
|
||||||
val PublishedApi = "PublishedApi".baseId()
|
val PublishedApi = "PublishedApi".baseId()
|
||||||
@@ -213,6 +216,7 @@ private fun String.jvmInternalId() = ClassId(StandardClassIds.BASE_JVM_INTERNAL_
|
|||||||
private fun String.internalId() = ClassId(StandardClassIds.BASE_INTERNAL_PACKAGE, Name.identifier(this))
|
private fun String.internalId() = ClassId(StandardClassIds.BASE_INTERNAL_PACKAGE, Name.identifier(this))
|
||||||
private fun String.internalIrId() = ClassId(StandardClassIds.BASE_INTERNAL_IR_PACKAGE, Name.identifier(this))
|
private fun String.internalIrId() = ClassId(StandardClassIds.BASE_INTERNAL_IR_PACKAGE, Name.identifier(this))
|
||||||
private fun String.coroutinesId() = ClassId(StandardClassIds.BASE_COROUTINES_PACKAGE, Name.identifier(this))
|
private fun String.coroutinesId() = ClassId(StandardClassIds.BASE_COROUTINES_PACKAGE, Name.identifier(this))
|
||||||
|
private fun String.enumsId() = ClassId(StandardClassIds.BASE_ENUMS_PACKAGE, Name.identifier(this))
|
||||||
|
|
||||||
private fun String.callableId(packageName: FqName) = CallableId(packageName, Name.identifier(this))
|
private fun String.callableId(packageName: FqName) = CallableId(packageName, Name.identifier(this))
|
||||||
private fun String.callableId(classId: ClassId) = CallableId(classId, Name.identifier(this))
|
private fun String.callableId(classId: ClassId) = CallableId(classId, Name.identifier(this))
|
||||||
|
|||||||
Reference in New Issue
Block a user