JVM IR: Handle overloaded values functions in MappedEnumWhenLowering
Fixes KT-46579.
This commit is contained in:
committed by
Alexander Udalov
parent
5d30576d28
commit
6aaff9dfb7
+18
@@ -14454,6 +14454,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
||||
runTest("compiler/testData/codegen/box/enum/javaClassWithNestedEnum.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("javaEnumValues.kt")
|
||||
public void testJavaEnumValues() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/enum/javaEnumValues.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt1119.kt")
|
||||
public void testKt1119() throws Exception {
|
||||
@@ -14628,6 +14634,18 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
||||
runTest("compiler/testData/codegen/box/enum/ordinal.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("overloadedEnumValues.kt")
|
||||
public void testOverloadedEnumValues() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/enum/overloadedEnumValues.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("overloadedEnumValuesStatic.kt")
|
||||
public void testOverloadedEnumValuesStatic() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/enum/overloadedEnumValuesStatic.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("refToThis.kt")
|
||||
public void testRefToThis() throws Exception {
|
||||
|
||||
+9
-3
@@ -21,8 +21,7 @@ import org.jetbrains.kotlin.ir.declarations.IrEnumEntry
|
||||
import org.jetbrains.kotlin.ir.declarations.IrField
|
||||
import org.jetbrains.kotlin.ir.expressions.IrExpression
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.IrGetEnumValueImpl
|
||||
import org.jetbrains.kotlin.ir.types.defaultType
|
||||
import org.jetbrains.kotlin.ir.types.getClass
|
||||
import org.jetbrains.kotlin.ir.types.*
|
||||
import org.jetbrains.kotlin.ir.util.*
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.util.OperatorNameConventions
|
||||
@@ -113,7 +112,14 @@ private class MappedEnumWhenLowering(context: CommonBackendContext) : EnumWhenLo
|
||||
for ((enum, mappingAndField) in state!!.mappings) {
|
||||
val (mapping, field) = mappingAndField
|
||||
val builder = context.createIrBuilder(state!!.mappingsClass.symbol)
|
||||
val enumValues = enum.functions.single { it.name.toString() == "values" }
|
||||
val enumValues = enum.functions.single {
|
||||
it.name.toString() == "values"
|
||||
&& it.dispatchReceiverParameter == null
|
||||
&& it.extensionReceiverParameter == null
|
||||
&& it.valueParameters.isEmpty()
|
||||
&& it.returnType.isBoxedArray
|
||||
&& it.returnType.getArrayElementType(context.irBuiltIns).classOrNull == enum.symbol
|
||||
}
|
||||
field.initializer = builder.irExprBody(builder.irBlock {
|
||||
val enumSize = irCall(refArraySize).apply { dispatchReceiver = irCall(enumValues) }
|
||||
val result = irTemporary(irCall(intArrayConstructor).apply { putValueArgument(0, enumSize) })
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// FILE: E.java
|
||||
public enum E {
|
||||
A();
|
||||
public static void values(boolean b) {
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: test.kt
|
||||
|
||||
fun f(e: E) = when (e) {
|
||||
E.A -> "OK"
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return f(E.A)
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
enum class E {
|
||||
A;
|
||||
|
||||
fun values(b: Boolean) {}
|
||||
fun E.values(): Array<E> = arrayOf(A)
|
||||
}
|
||||
|
||||
fun f(e: E) = when (e) {
|
||||
E.A -> "OK"
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return f(E.A)
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// WITH_RUNTIME
|
||||
|
||||
enum class E {
|
||||
A;
|
||||
|
||||
companion object {
|
||||
@JvmStatic
|
||||
fun values(): Array<String> = arrayOf("OK")
|
||||
|
||||
@JvmStatic
|
||||
fun E.values(): Array<E> = arrayOf(A)
|
||||
|
||||
@JvmStatic
|
||||
fun values(x: Int): Array<E> = arrayOf(A)
|
||||
}
|
||||
}
|
||||
|
||||
fun f(e: E) = when (e) {
|
||||
E.A -> "OK"
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return f(E.A)
|
||||
}
|
||||
+18
@@ -14454,6 +14454,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
runTest("compiler/testData/codegen/box/enum/javaClassWithNestedEnum.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("javaEnumValues.kt")
|
||||
public void testJavaEnumValues() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/enum/javaEnumValues.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt1119.kt")
|
||||
public void testKt1119() throws Exception {
|
||||
@@ -14628,6 +14634,18 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
runTest("compiler/testData/codegen/box/enum/ordinal.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("overloadedEnumValues.kt")
|
||||
public void testOverloadedEnumValues() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/enum/overloadedEnumValues.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("overloadedEnumValuesStatic.kt")
|
||||
public void testOverloadedEnumValuesStatic() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/enum/overloadedEnumValuesStatic.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("refToThis.kt")
|
||||
public void testRefToThis() throws Exception {
|
||||
|
||||
+18
@@ -14454,6 +14454,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
runTest("compiler/testData/codegen/box/enum/javaClassWithNestedEnum.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("javaEnumValues.kt")
|
||||
public void testJavaEnumValues() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/enum/javaEnumValues.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt1119.kt")
|
||||
public void testKt1119() throws Exception {
|
||||
@@ -14628,6 +14634,18 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
runTest("compiler/testData/codegen/box/enum/ordinal.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("overloadedEnumValues.kt")
|
||||
public void testOverloadedEnumValues() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/enum/overloadedEnumValues.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("overloadedEnumValuesStatic.kt")
|
||||
public void testOverloadedEnumValuesStatic() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/enum/overloadedEnumValuesStatic.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("refToThis.kt")
|
||||
public void testRefToThis() throws Exception {
|
||||
|
||||
+15
@@ -11839,6 +11839,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
runTest("compiler/testData/codegen/box/enum/javaClassWithNestedEnum.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("javaEnumValues.kt")
|
||||
public void testJavaEnumValues() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/enum/javaEnumValues.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt1119.kt")
|
||||
public void testKt1119() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/enum/kt1119.kt");
|
||||
@@ -11984,6 +11989,16 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
runTest("compiler/testData/codegen/box/enum/ordinal.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("overloadedEnumValues.kt")
|
||||
public void testOverloadedEnumValues() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/enum/overloadedEnumValues.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("overloadedEnumValuesStatic.kt")
|
||||
public void testOverloadedEnumValuesStatic() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/enum/overloadedEnumValuesStatic.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("refToThis.kt")
|
||||
public void testRefToThis() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/enum/refToThis.kt");
|
||||
|
||||
js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java
Generated
+5
@@ -10703,6 +10703,11 @@ public class IrJsCodegenBoxES6TestGenerated extends AbstractIrJsCodegenBoxES6Tes
|
||||
runTest("compiler/testData/codegen/box/enum/ordinal.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("overloadedEnumValues.kt")
|
||||
public void testOverloadedEnumValues() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/enum/overloadedEnumValues.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("refToThis.kt")
|
||||
public void testRefToThis() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/enum/refToThis.kt");
|
||||
|
||||
Generated
+5
@@ -10114,6 +10114,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
|
||||
runTest("compiler/testData/codegen/box/enum/ordinal.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("overloadedEnumValues.kt")
|
||||
public void testOverloadedEnumValues() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/enum/overloadedEnumValues.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("refToThis.kt")
|
||||
public void testRefToThis() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/enum/refToThis.kt");
|
||||
|
||||
Generated
+5
@@ -10114,6 +10114,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
||||
runTest("compiler/testData/codegen/box/enum/ordinal.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("overloadedEnumValues.kt")
|
||||
public void testOverloadedEnumValues() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/enum/overloadedEnumValues.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("refToThis.kt")
|
||||
public void testRefToThis() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/enum/refToThis.kt");
|
||||
|
||||
js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/wasm/semantics/IrCodegenBoxWasmTestGenerated.java
Generated
+5
@@ -4962,6 +4962,11 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest
|
||||
runTest("compiler/testData/codegen/box/enum/ordinal.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("overloadedEnumValues.kt")
|
||||
public void testOverloadedEnumValues() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/enum/overloadedEnumValues.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("refToThis.kt")
|
||||
public void testRefToThis() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/enum/refToThis.kt");
|
||||
|
||||
Reference in New Issue
Block a user