Load Java enums as final classes
In case Java enum has an abstract member, it has the ACC_ABSTRACT flag set in the bytecode. However, we should still load it with final modality to be consistent with Kotlin enums which are always considered final #KT-23426 Fixed
This commit is contained in:
+5
@@ -13439,6 +13439,11 @@ public class FirDiagnosticsSmokeTestGenerated extends AbstractFirDiagnosticsSmok
|
||||
runTest("compiler/testData/diagnostics/tests/multiplatform/enum/enumEntryWithBody.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("javaEnum.kt")
|
||||
public void testJavaEnum() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/multiplatform/enum/javaEnum.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("simpleEnum.kt")
|
||||
public void testSimpleEnum() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/multiplatform/enum/simpleEnum.kt");
|
||||
|
||||
@@ -2,7 +2,7 @@ package test
|
||||
|
||||
public fun useEnum(): kotlin.String!
|
||||
|
||||
public abstract enum class AbstractEnum : kotlin.Enum<test.AbstractEnum!> {
|
||||
public final enum class AbstractEnum : kotlin.Enum<test.AbstractEnum!> {
|
||||
enum entry ONE
|
||||
|
||||
private constructor AbstractEnum()
|
||||
|
||||
@@ -2,7 +2,7 @@ package
|
||||
|
||||
public fun main(): kotlin.Unit
|
||||
|
||||
public abstract enum class A : kotlin.Enum<A!> {
|
||||
public final enum class A : kotlin.Enum<A!> {
|
||||
enum entry ENTRY
|
||||
|
||||
public constructor A()
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
// !LANGUAGE: +MultiPlatformProjects
|
||||
// MODULE: m1-common
|
||||
// FILE: common.kt
|
||||
expect enum class Foo {
|
||||
ENTRY
|
||||
}
|
||||
|
||||
expect enum class _TimeUnit
|
||||
|
||||
// MODULE: m2-jvm(m1-common)
|
||||
// FILE: jvm.kt
|
||||
actual typealias Foo = FooImpl
|
||||
|
||||
actual typealias _TimeUnit = java.util.concurrent.TimeUnit
|
||||
|
||||
// FILE: FooImpl.java
|
||||
public enum FooImpl {
|
||||
ENTRY("OK") {
|
||||
@Override
|
||||
public String getResult() {
|
||||
return value;
|
||||
}
|
||||
};
|
||||
|
||||
protected final String value;
|
||||
|
||||
public FooImpl(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public abstract String getResult();
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
// -- Module: <m1-common> --
|
||||
package
|
||||
|
||||
public final expect enum class Foo : kotlin.Enum<Foo> {
|
||||
expect enum entry ENTRY
|
||||
|
||||
public final override /*1*/ /*fake_override*/ val name: kotlin.String
|
||||
public final override /*1*/ /*fake_override*/ val ordinal: kotlin.Int
|
||||
protected final override /*1*/ /*fake_override*/ fun clone(): kotlin.Any
|
||||
public final override /*1*/ /*fake_override*/ fun compareTo(/*0*/ other: Foo): kotlin.Int
|
||||
public final override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public final override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
|
||||
// Static members
|
||||
public final /*synthesized*/ fun valueOf(/*0*/ value: kotlin.String): Foo
|
||||
public final /*synthesized*/ fun values(): kotlin.Array<Foo>
|
||||
}
|
||||
|
||||
public final expect enum class _TimeUnit : kotlin.Enum<_TimeUnit> {
|
||||
public final override /*1*/ /*fake_override*/ val name: kotlin.String
|
||||
public final override /*1*/ /*fake_override*/ val ordinal: kotlin.Int
|
||||
protected final override /*1*/ /*fake_override*/ fun clone(): kotlin.Any
|
||||
public final override /*1*/ /*fake_override*/ fun compareTo(/*0*/ other: _TimeUnit): kotlin.Int
|
||||
public final override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public final override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
|
||||
// Static members
|
||||
public final /*synthesized*/ fun valueOf(/*0*/ value: kotlin.String): _TimeUnit
|
||||
public final /*synthesized*/ fun values(): kotlin.Array<_TimeUnit>
|
||||
}
|
||||
|
||||
|
||||
// -- Module: <m2-jvm> --
|
||||
package
|
||||
|
||||
public final enum class FooImpl : kotlin.Enum<FooImpl!> {
|
||||
enum entry ENTRY
|
||||
|
||||
public constructor FooImpl(/*0*/ value: kotlin.String!)
|
||||
public final override /*1*/ /*fake_override*/ val name: kotlin.String
|
||||
public final override /*1*/ /*fake_override*/ val ordinal: kotlin.Int
|
||||
protected/*protected and package*/ final val value: kotlin.String!
|
||||
protected final override /*1*/ /*fake_override*/ fun clone(): kotlin.Any
|
||||
public final override /*1*/ /*fake_override*/ fun compareTo(/*0*/ other: FooImpl!): kotlin.Int
|
||||
public final override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
protected/*protected and package*/ final override /*1*/ /*fake_override*/ /*isHiddenForResolutionEverywhereBesideSupercalls*/ fun finalize(): kotlin.Unit
|
||||
public final override /*1*/ /*fake_override*/ /*isHiddenForResolutionEverywhereBesideSupercalls*/ fun getDeclaringClass(): java.lang.Class<FooImpl!>!
|
||||
public abstract fun getResult(): kotlin.String!
|
||||
public final override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
|
||||
// Static members
|
||||
public final /*synthesized*/ fun valueOf(/*0*/ value: kotlin.String): FooImpl
|
||||
public final /*synthesized*/ fun values(): kotlin.Array<FooImpl>
|
||||
}
|
||||
public actual typealias Foo = FooImpl
|
||||
public actual typealias _TimeUnit = java.util.concurrent.TimeUnit
|
||||
+1
-1
@@ -4,7 +4,7 @@ public open class EnumArgumentWithCustomToString {
|
||||
public constructor EnumArgumentWithCustomToString()
|
||||
@test.EnumArgumentWithCustomToString.EnumAnno(value = E.CAKE) @test.EnumArgumentWithCustomToString.EnumArrayAnno(value = {E.CAKE, E.CAKE}) public/*package*/ open fun annotated(): kotlin.Unit
|
||||
|
||||
public open enum class E : kotlin.Enum<test.EnumArgumentWithCustomToString.E!> {
|
||||
public final enum class E : kotlin.Enum<test.EnumArgumentWithCustomToString.E!> {
|
||||
enum entry CAKE
|
||||
|
||||
private constructor E()
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package test
|
||||
|
||||
public open enum class EnumWithSpecializedEntry : kotlin.Enum<test.EnumWithSpecializedEntry!> {
|
||||
public final enum class EnumWithSpecializedEntry : kotlin.Enum<test.EnumWithSpecializedEntry!> {
|
||||
enum entry E1
|
||||
|
||||
enum entry E2
|
||||
|
||||
@@ -13446,6 +13446,11 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
|
||||
runTest("compiler/testData/diagnostics/tests/multiplatform/enum/enumEntryWithBody.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("javaEnum.kt")
|
||||
public void testJavaEnum() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/multiplatform/enum/javaEnum.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("simpleEnum.kt")
|
||||
public void testSimpleEnum() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/multiplatform/enum/simpleEnum.kt");
|
||||
|
||||
Generated
+5
@@ -13441,6 +13441,11 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing
|
||||
runTest("compiler/testData/diagnostics/tests/multiplatform/enum/enumEntryWithBody.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("javaEnum.kt")
|
||||
public void testJavaEnum() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/multiplatform/enum/javaEnum.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("simpleEnum.kt")
|
||||
public void testSimpleEnum() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/multiplatform/enum/simpleEnum.kt");
|
||||
|
||||
+1
-1
@@ -72,7 +72,7 @@ class LazyJavaClassDescriptor(
|
||||
}
|
||||
|
||||
private val modality =
|
||||
if (jClass.isAnnotationType) Modality.FINAL
|
||||
if (jClass.isAnnotationType || jClass.isEnum) Modality.FINAL
|
||||
else Modality.convertFromFlags(jClass.isAbstract || jClass.isInterface, !jClass.isFinal)
|
||||
|
||||
private val visibility = jClass.visibility
|
||||
|
||||
Reference in New Issue
Block a user