Kapt+JVM_IR: do not generate bodies of enum entries
#KT-59247 Fixed
This commit is contained in:
committed by
Space Team
parent
91f0c3c342
commit
fd4e59f279
+1
-1
@@ -144,7 +144,7 @@ private class EnumClassLowering(private val context: JvmBackendContext) : ClassL
|
||||
|
||||
private fun buildEnumEntryField(enumEntry: IrEnumEntry): IrField =
|
||||
context.cachedDeclarations.getFieldForEnumEntry(enumEntry).apply {
|
||||
initializer = IrExpressionBodyImpl(enumEntry.initializerExpression!!.expression.patchDeclarationParents(this))
|
||||
initializer = enumEntry.initializerExpression?.let { IrExpressionBodyImpl(it.expression.patchDeclarationParents(this)) }
|
||||
annotations = annotations + enumEntry.annotations
|
||||
}
|
||||
|
||||
|
||||
@@ -531,7 +531,7 @@ internal class ClassGenerator(
|
||||
).buildWithScope { irEnumEntry ->
|
||||
irEnumEntry.parent = irEnumClass
|
||||
|
||||
if (!enumEntryDescriptor.isExpect) {
|
||||
if (!enumEntryDescriptor.isExpect && context.configuration.generateBodies) {
|
||||
irEnumEntry.initializerExpression =
|
||||
context.irFactory.createExpressionBody(
|
||||
createBodyGenerator(irEnumEntry.symbol)
|
||||
|
||||
Vendored
+29
@@ -0,0 +1,29 @@
|
||||
@kotlin.Metadata()
|
||||
public abstract interface Callback {
|
||||
|
||||
@org.jetbrains.annotations.NotNull()
|
||||
public abstract java.lang.String invoke();
|
||||
}
|
||||
|
||||
////////////////////
|
||||
|
||||
|
||||
@kotlin.Metadata()
|
||||
public enum Foo {
|
||||
/*public static final*/ FOO /* = new Foo() */;
|
||||
@org.jetbrains.annotations.NotNull()
|
||||
private final Callback callback = null;
|
||||
|
||||
Foo(Callback callback) {
|
||||
}
|
||||
|
||||
@org.jetbrains.annotations.NotNull()
|
||||
public final Callback getCallback() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@org.jetbrains.annotations.NotNull()
|
||||
public static kotlin.enums.EnumEntries<Foo> getEntries() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
interface Callback {
|
||||
fun invoke(): String
|
||||
}
|
||||
|
||||
enum class Foo(val callback: Callback) {
|
||||
FOO(
|
||||
object : Callback {
|
||||
override fun invoke(): String = "OK"
|
||||
}
|
||||
)
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
@kotlin.Metadata()
|
||||
public abstract interface Callback {
|
||||
|
||||
@org.jetbrains.annotations.NotNull()
|
||||
public abstract java.lang.String invoke();
|
||||
}
|
||||
|
||||
////////////////////
|
||||
|
||||
|
||||
@kotlin.Metadata()
|
||||
public enum Foo {
|
||||
/*public static final*/ FOO /* = new Foo() */;
|
||||
@org.jetbrains.annotations.NotNull()
|
||||
private final Callback callback = null;
|
||||
|
||||
Foo(Callback callback) {
|
||||
}
|
||||
|
||||
@org.jetbrains.annotations.NotNull()
|
||||
public final Callback getCallback() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+6
@@ -91,6 +91,12 @@ public class ClassFileToSourceStubConverterTestGenerated extends AbstractClassFi
|
||||
runTest("plugins/kapt3/kapt3-compiler/testData/converter/anonymousInitializer.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("anonymousObjectInEnumSuperConstructor.kt")
|
||||
public void testAnonymousObjectInEnumSuperConstructor() throws Exception {
|
||||
runTest("plugins/kapt3/kapt3-compiler/testData/converter/anonymousObjectInEnumSuperConstructor.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("comments.kt")
|
||||
public void testComments() throws Exception {
|
||||
|
||||
+6
@@ -91,6 +91,12 @@ public class IrClassFileToSourceStubConverterTestGenerated extends AbstractIrCla
|
||||
runTest("plugins/kapt3/kapt3-compiler/testData/converter/anonymousInitializer.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("anonymousObjectInEnumSuperConstructor.kt")
|
||||
public void testAnonymousObjectInEnumSuperConstructor() throws Exception {
|
||||
runTest("plugins/kapt3/kapt3-compiler/testData/converter/anonymousObjectInEnumSuperConstructor.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("comments.kt")
|
||||
public void testComments() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user