JVM IR: fix behavior of Enum.entries for unlowered enums
#KT-57671 Fixed
This commit is contained in:
committed by
Space Team
parent
449c866c7a
commit
f04d01cf21
+12
@@ -2253,6 +2253,18 @@ public class FirLightTreeBytecodeTextTestGenerated extends AbstractFirLightTreeB
|
|||||||
public void testKt18731_2() throws Exception {
|
public void testKt18731_2() throws Exception {
|
||||||
runTest("compiler/testData/codegen/bytecodeText/enum/kt18731_2.kt");
|
runTest("compiler/testData/codegen/bytecodeText/enum/kt18731_2.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("kt57671_1.kt")
|
||||||
|
public void testKt57671_1() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/bytecodeText/enum/kt57671_1.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("kt57671_2.kt")
|
||||||
|
public void testKt57671_2() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/bytecodeText/enum/kt57671_2.kt");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nested
|
@Nested
|
||||||
|
|||||||
+12
@@ -2253,6 +2253,18 @@ public class FirPsiBytecodeTextTestGenerated extends AbstractFirPsiBytecodeTextT
|
|||||||
public void testKt18731_2() throws Exception {
|
public void testKt18731_2() throws Exception {
|
||||||
runTest("compiler/testData/codegen/bytecodeText/enum/kt18731_2.kt");
|
runTest("compiler/testData/codegen/bytecodeText/enum/kt18731_2.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("kt57671_1.kt")
|
||||||
|
public void testKt57671_1() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/bytecodeText/enum/kt57671_1.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("kt57671_2.kt")
|
||||||
|
public void testKt57671_2() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/bytecodeText/enum/kt57671_2.kt");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nested
|
@Nested
|
||||||
|
|||||||
+13
-5
@@ -11,6 +11,7 @@ import org.jetbrains.kotlin.backend.common.lower.createIrBuilder
|
|||||||
import org.jetbrains.kotlin.backend.common.phaser.makeIrFilePhase
|
import org.jetbrains.kotlin.backend.common.phaser.makeIrFilePhase
|
||||||
import org.jetbrains.kotlin.backend.jvm.JvmBackendContext
|
import org.jetbrains.kotlin.backend.jvm.JvmBackendContext
|
||||||
import org.jetbrains.kotlin.backend.jvm.JvmLoweredDeclarationOrigin
|
import org.jetbrains.kotlin.backend.jvm.JvmLoweredDeclarationOrigin
|
||||||
|
import org.jetbrains.kotlin.backend.jvm.ir.isInCurrentModule
|
||||||
import org.jetbrains.kotlin.config.LanguageFeature
|
import org.jetbrains.kotlin.config.LanguageFeature
|
||||||
import org.jetbrains.kotlin.ir.IrStatement
|
import org.jetbrains.kotlin.ir.IrStatement
|
||||||
import org.jetbrains.kotlin.ir.builders.declarations.addField
|
import org.jetbrains.kotlin.ir.builders.declarations.addField
|
||||||
@@ -111,13 +112,20 @@ class EnumExternalEntriesLowering(private val context: JvmBackendContext) : File
|
|||||||
return IrGetFieldImpl(expression.startOffset, expression.endOffset, field.symbol, field.type)
|
return IrGetFieldImpl(expression.startOffset, expression.endOffset, field.symbol, field.type)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun IrClass.hasEnumEntriesFunction() = functions.any {
|
private fun IrClass.hasEnumEntriesFunction(): Boolean {
|
||||||
it.name.toString() == "<get-entries>"
|
// Enums from other modules are always loaded with a property `entries` which has a getter `<get-entries>`.
|
||||||
&& it.dispatchReceiverParameter == null
|
// Enums from the current module will have a property `entries` if they are unlowered yet (i.e. enum is declared in another file
|
||||||
&& it.extensionReceiverParameter == null
|
// which will be lowered after the file with the call site), or a function `<get-entries>` if they are already lowered.
|
||||||
&& it.valueParameters.isEmpty()
|
return functions.any { it.isGetEntries() }
|
||||||
|
|| (properties.any { it.getter?.isGetEntries() == true } && isInCurrentModule())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun IrSimpleFunction.isGetEntries(): Boolean =
|
||||||
|
name.toString() == "<get-entries>"
|
||||||
|
&& dispatchReceiverParameter == null
|
||||||
|
&& extensionReceiverParameter == null
|
||||||
|
&& valueParameters.isEmpty()
|
||||||
|
|
||||||
override fun visitClassNew(declaration: IrClass): IrStatement {
|
override fun visitClassNew(declaration: IrClass): IrStatement {
|
||||||
val oldState = state
|
val oldState = state
|
||||||
val mappingState = EntriesMappingState()
|
val mappingState = EntriesMappingState()
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
// TARGET_BACKEND: JVM_IR
|
||||||
|
// FILE: 1.kt
|
||||||
|
|
||||||
|
enum class E
|
||||||
|
|
||||||
|
// FILE: 2.kt
|
||||||
|
|
||||||
|
@OptIn(ExperimentalStdlibApi::class)
|
||||||
|
fun test() {
|
||||||
|
E.entries
|
||||||
|
}
|
||||||
|
|
||||||
|
// 0 EntriesMappings
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
// TARGET_BACKEND: JVM_IR
|
||||||
|
// FILE: 1.kt
|
||||||
|
|
||||||
|
@OptIn(ExperimentalStdlibApi::class)
|
||||||
|
fun test() {
|
||||||
|
E.entries
|
||||||
|
}
|
||||||
|
|
||||||
|
// FILE: 2.kt
|
||||||
|
|
||||||
|
enum class E
|
||||||
|
|
||||||
|
// 0 EntriesMappings
|
||||||
+12
@@ -2253,6 +2253,18 @@ public class IrBytecodeTextTestGenerated extends AbstractIrBytecodeTextTest {
|
|||||||
public void testKt18731_2() throws Exception {
|
public void testKt18731_2() throws Exception {
|
||||||
runTest("compiler/testData/codegen/bytecodeText/enum/kt18731_2.kt");
|
runTest("compiler/testData/codegen/bytecodeText/enum/kt18731_2.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("kt57671_1.kt")
|
||||||
|
public void testKt57671_1() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/bytecodeText/enum/kt57671_1.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("kt57671_2.kt")
|
||||||
|
public void testKt57671_2() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/bytecodeText/enum/kt57671_2.kt");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nested
|
@Nested
|
||||||
|
|||||||
Reference in New Issue
Block a user