Fir2Ir: more precise calculation of enum class modality

Use the same condition as in the already existing `createIrEnumEntry`
function (and as in psi2ir): enum class should be final unless there's
an enum entry with any declaration other than its constructor.

 #KT-57216
This commit is contained in:
Alexander Udalov
2023-03-15 00:11:36 +01:00
committed by Space Team
parent 2cc3b542fd
commit 68b94b07b8
17 changed files with 43 additions and 45 deletions
+6 -6
View File
@@ -61,14 +61,14 @@ FILE fqName:<root> fileName:/enum.kt
overridden:
public final fun <get-ordinal> (): kotlin.Int declared in kotlin.Enum
$this: VALUE_PARAMETER name:<this> type:kotlin.Enum<E of kotlin.Enum>
CLASS ENUM_CLASS name:TestEnum2 modality:OPEN visibility:public superTypes:[kotlin.Enum<<root>.TestEnum2>]
CLASS ENUM_CLASS name:TestEnum2 modality:FINAL visibility:public superTypes:[kotlin.Enum<<root>.TestEnum2>]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.TestEnum2
CONSTRUCTOR visibility:private <> (x:kotlin.Int) returnType:<root>.TestEnum2 [primary]
VALUE_PARAMETER name:x index:0 type:kotlin.Int
BLOCK_BODY
ENUM_CONSTRUCTOR_CALL 'public constructor <init> (name: kotlin.String, ordinal: kotlin.Int) [primary] declared in kotlin.Enum'
<E>: <root>.TestEnum2
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS ENUM_CLASS name:TestEnum2 modality:OPEN visibility:public superTypes:[kotlin.Enum<<root>.TestEnum2>]'
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS ENUM_CLASS name:TestEnum2 modality:FINAL visibility:public superTypes:[kotlin.Enum<<root>.TestEnum2>]'
PROPERTY name:x visibility:public modality:FINAL [val]
FIELD PROPERTY_BACKING_FIELD name:x type:kotlin.Int visibility:private [final]
EXPRESSION_BODY
@@ -470,7 +470,7 @@ FILE fqName:<root> fileName:/enum.kt
overridden:
public final fun <get-ordinal> (): kotlin.Int declared in kotlin.Enum
$this: VALUE_PARAMETER name:<this> type:kotlin.Enum<E of kotlin.Enum>
CLASS ENUM_CLASS name:TestEnum5 modality:OPEN visibility:public superTypes:[kotlin.Enum<<root>.TestEnum5>]
CLASS ENUM_CLASS name:TestEnum5 modality:FINAL visibility:public superTypes:[kotlin.Enum<<root>.TestEnum5>]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.TestEnum5
CONSTRUCTOR visibility:private <> (x:kotlin.Int) returnType:<root>.TestEnum5 [primary]
VALUE_PARAMETER name:x index:0 type:kotlin.Int
@@ -479,7 +479,7 @@ FILE fqName:<root> fileName:/enum.kt
BLOCK_BODY
ENUM_CONSTRUCTOR_CALL 'public constructor <init> (name: kotlin.String, ordinal: kotlin.Int) [primary] declared in kotlin.Enum'
<E>: <root>.TestEnum5
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS ENUM_CLASS name:TestEnum5 modality:OPEN visibility:public superTypes:[kotlin.Enum<<root>.TestEnum5>]'
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS ENUM_CLASS name:TestEnum5 modality:FINAL visibility:public superTypes:[kotlin.Enum<<root>.TestEnum5>]'
PROPERTY name:x visibility:public modality:FINAL [val]
FIELD PROPERTY_BACKING_FIELD name:x type:kotlin.Int visibility:private [final]
EXPRESSION_BODY
@@ -554,7 +554,7 @@ FILE fqName:<root> fileName:/enum.kt
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun f (): kotlin.Int declared in <root>'
CONST Int type=kotlin.Int value=1
CLASS ENUM_CLASS name:TestEnum6 modality:OPEN visibility:public superTypes:[kotlin.Enum<<root>.TestEnum6>]
CLASS ENUM_CLASS name:TestEnum6 modality:FINAL visibility:public superTypes:[kotlin.Enum<<root>.TestEnum6>]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.TestEnum6
CONSTRUCTOR visibility:private <> (x:kotlin.Int, y:kotlin.Int) returnType:<root>.TestEnum6 [primary]
VALUE_PARAMETER name:x index:0 type:kotlin.Int
@@ -562,7 +562,7 @@ FILE fqName:<root> fileName:/enum.kt
BLOCK_BODY
ENUM_CONSTRUCTOR_CALL 'public constructor <init> (name: kotlin.String, ordinal: kotlin.Int) [primary] declared in kotlin.Enum'
<E>: <root>.TestEnum6
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS ENUM_CLASS name:TestEnum6 modality:OPEN visibility:public superTypes:[kotlin.Enum<<root>.TestEnum6>]'
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS ENUM_CLASS name:TestEnum6 modality:FINAL visibility:public superTypes:[kotlin.Enum<<root>.TestEnum6>]'
PROPERTY name:x visibility:public modality:FINAL [val]
FIELD PROPERTY_BACKING_FIELD name:x type:kotlin.Int visibility:private [final]
EXPRESSION_BODY
+3 -3
View File
@@ -18,7 +18,7 @@ enum class TestEnum1 : Enum<TestEnum1> {
}
open enum class TestEnum2 : Enum<TestEnum2> {
enum class TestEnum2 : Enum<TestEnum2> {
private constructor(x: Int) /* primary */ {
super/*Enum*/<TestEnum2>()
/* <init>() */
@@ -131,7 +131,7 @@ abstract enum class TestEnum4 : Enum<TestEnum4> {
}
open enum class TestEnum5 : Enum<TestEnum5> {
enum class TestEnum5 : Enum<TestEnum5> {
private constructor(x: Int = 0) /* primary */ {
super/*Enum*/<TestEnum5>()
/* <init>() */
@@ -161,7 +161,7 @@ fun f(): Int {
return 1
}
open enum class TestEnum6 : Enum<TestEnum6> {
enum class TestEnum6 : Enum<TestEnum6> {
private constructor(x: Int, y: Int) /* primary */ {
super/*Enum*/<TestEnum6>()
/* <init>() */
@@ -58,14 +58,14 @@ FILE fqName:<root> fileName:/enumClassModality.kt
overridden:
public final fun <get-ordinal> (): kotlin.Int declared in kotlin.Enum
$this: VALUE_PARAMETER name:<this> type:kotlin.Enum<E of kotlin.Enum>
CLASS ENUM_CLASS name:TestFinalEnum2 modality:OPEN visibility:public superTypes:[kotlin.Enum<<root>.TestFinalEnum2>]
CLASS ENUM_CLASS name:TestFinalEnum2 modality:FINAL visibility:public superTypes:[kotlin.Enum<<root>.TestFinalEnum2>]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.TestFinalEnum2
CONSTRUCTOR visibility:private <> (x:kotlin.Int) returnType:<root>.TestFinalEnum2 [primary]
VALUE_PARAMETER name:x index:0 type:kotlin.Int
BLOCK_BODY
ENUM_CONSTRUCTOR_CALL 'public constructor <init> (name: kotlin.String, ordinal: kotlin.Int) [primary] declared in kotlin.Enum'
<E>: <root>.TestFinalEnum2
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS ENUM_CLASS name:TestFinalEnum2 modality:OPEN visibility:public superTypes:[kotlin.Enum<<root>.TestFinalEnum2>]'
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS ENUM_CLASS name:TestFinalEnum2 modality:FINAL visibility:public superTypes:[kotlin.Enum<<root>.TestFinalEnum2>]'
PROPERTY name:x visibility:public modality:FINAL [val]
FIELD PROPERTY_BACKING_FIELD name:x type:kotlin.Int visibility:private [final]
EXPRESSION_BODY
@@ -16,7 +16,7 @@ enum class TestFinalEnum1 : Enum<TestFinalEnum1> {
}
open enum class TestFinalEnum2 : Enum<TestFinalEnum2> {
enum class TestFinalEnum2 : Enum<TestFinalEnum2> {
private constructor(x: Int) /* primary */ {
super/*Enum*/<TestFinalEnum2>()
/* <init>() */
@@ -184,3 +184,4 @@ abstract enum class TestAbstractEnum2 : IFoo, Enum<TestAbstractEnum2> {
get(): EnumEntries<TestAbstractEnum2> /* Synthetic body for ENUM_ENTRIES */
}
@@ -1,12 +1,12 @@
FILE fqName:<root> fileName:/enumWithSecondaryCtor.kt
CLASS ENUM_CLASS name:Test0 modality:OPEN visibility:public superTypes:[kotlin.Enum<<root>.Test0>]
CLASS ENUM_CLASS name:Test0 modality:FINAL visibility:public superTypes:[kotlin.Enum<<root>.Test0>]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.Test0
CONSTRUCTOR visibility:private <> (x:kotlin.Int) returnType:<root>.Test0 [primary]
VALUE_PARAMETER name:x index:0 type:kotlin.Int
BLOCK_BODY
ENUM_CONSTRUCTOR_CALL 'public constructor <init> (name: kotlin.String, ordinal: kotlin.Int) [primary] declared in kotlin.Enum'
<E>: <root>.Test0
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS ENUM_CLASS name:Test0 modality:OPEN visibility:public superTypes:[kotlin.Enum<<root>.Test0>]'
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS ENUM_CLASS name:Test0 modality:FINAL visibility:public superTypes:[kotlin.Enum<<root>.Test0>]'
PROPERTY name:x visibility:public modality:FINAL [val]
FIELD PROPERTY_BACKING_FIELD name:x type:kotlin.Int visibility:private [final]
EXPRESSION_BODY
@@ -74,14 +74,14 @@ FILE fqName:<root> fileName:/enumWithSecondaryCtor.kt
overridden:
public final fun <get-ordinal> (): kotlin.Int declared in kotlin.Enum
$this: VALUE_PARAMETER name:<this> type:kotlin.Enum<E of kotlin.Enum>
CLASS ENUM_CLASS name:Test1 modality:OPEN visibility:public superTypes:[kotlin.Enum<<root>.Test1>]
CLASS ENUM_CLASS name:Test1 modality:FINAL visibility:public superTypes:[kotlin.Enum<<root>.Test1>]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.Test1
CONSTRUCTOR visibility:private <> (x:kotlin.Int) returnType:<root>.Test1 [primary]
VALUE_PARAMETER name:x index:0 type:kotlin.Int
BLOCK_BODY
ENUM_CONSTRUCTOR_CALL 'public constructor <init> (name: kotlin.String, ordinal: kotlin.Int) [primary] declared in kotlin.Enum'
<E>: <root>.Test1
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS ENUM_CLASS name:Test1 modality:OPEN visibility:public superTypes:[kotlin.Enum<<root>.Test1>]'
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS ENUM_CLASS name:Test1 modality:FINAL visibility:public superTypes:[kotlin.Enum<<root>.Test1>]'
PROPERTY name:x visibility:public modality:FINAL [val]
FIELD PROPERTY_BACKING_FIELD name:x type:kotlin.Int visibility:private [final]
EXPRESSION_BODY
@@ -1,4 +1,4 @@
open enum class Test0 : Enum<Test0> {
enum class Test0 : Enum<Test0> {
private constructor(x: Int) /* primary */ {
super/*Enum*/<Test0>()
/* <init>() */
@@ -24,7 +24,7 @@ open enum class Test0 : Enum<Test0> {
}
open enum class Test1 : Enum<Test1> {
enum class Test1 : Enum<Test1> {
private constructor(x: Int) /* primary */ {
super/*Enum*/<Test1>()
/* <init>() */