JVM_IR: cast argument of enumValueOf to String in bytecode

Generic functions and implicit casts may return a supertype instead.

 #KT-45865 Fixed
This commit is contained in:
pyos
2021-04-12 17:51:46 +02:00
committed by Alexander Udalov
parent afaf3b5e28
commit cc7187e49b
10 changed files with 52 additions and 2 deletions
@@ -14104,6 +14104,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
runTest("compiler/testData/codegen/box/enum/enumShort.kt");
}
@Test
@TestMetadata("enumValueOf.kt")
public void testEnumValueOf() throws Exception {
runTest("compiler/testData/codegen/box/enum/enumValueOf.kt");
}
@Test
@TestMetadata("enumWithLambdaParameter.kt")
public void testEnumWithLambdaParameter() throws Exception {
@@ -8,7 +8,7 @@ package org.jetbrains.kotlin.backend.jvm.intrinsics
import org.jetbrains.kotlin.backend.jvm.codegen.BlockInfo
import org.jetbrains.kotlin.backend.jvm.codegen.ExpressionCodegen
import org.jetbrains.kotlin.backend.jvm.codegen.MaterialValue
import org.jetbrains.kotlin.backend.jvm.codegen.materialized
import org.jetbrains.kotlin.backend.jvm.codegen.materializedAt
import org.jetbrains.kotlin.codegen.AsmUtil
import org.jetbrains.kotlin.codegen.inline.ReifiedTypeInliner
import org.jetbrains.kotlin.ir.expressions.IrFunctionAccessExpression
@@ -18,7 +18,8 @@ import org.jetbrains.org.objectweb.asm.Type
object EnumValueOf : IntrinsicMethod() {
override fun invoke(expression: IrFunctionAccessExpression, codegen: ExpressionCodegen, data: BlockInfo) = with(codegen) {
val type = expression.getTypeArgument(0)!!
val result = expression.getValueArgument(0)!!.accept(this, data).materialized()
val result = expression.getValueArgument(0)!!.accept(this, data)
.materializedAt(AsmTypes.JAVA_STRING_TYPE, codegen.context.irBuiltIns.stringType)
if (type.isReifiedTypeParameter) {
// Note that the inliner expects exactly the following sequence of instructions.
// <REIFIED-OPERATIONS-MARKER>
+6
View File
@@ -0,0 +1,6 @@
// IGNORE_BACKEND: WASM
enum class E { OK }
fun <T> id(x: T) = x
fun box() = enumValueOf<E>(id("OK")).name
@@ -14104,6 +14104,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTest("compiler/testData/codegen/box/enum/enumShort.kt");
}
@Test
@TestMetadata("enumValueOf.kt")
public void testEnumValueOf() throws Exception {
runTest("compiler/testData/codegen/box/enum/enumValueOf.kt");
}
@Test
@TestMetadata("enumWithLambdaParameter.kt")
public void testEnumWithLambdaParameter() throws Exception {
@@ -14104,6 +14104,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTest("compiler/testData/codegen/box/enum/enumShort.kt");
}
@Test
@TestMetadata("enumValueOf.kt")
public void testEnumValueOf() throws Exception {
runTest("compiler/testData/codegen/box/enum/enumValueOf.kt");
}
@Test
@TestMetadata("enumWithLambdaParameter.kt")
public void testEnumWithLambdaParameter() throws Exception {
@@ -11548,6 +11548,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTest("compiler/testData/codegen/box/enum/enumShort.kt");
}
@TestMetadata("enumValueOf.kt")
public void testEnumValueOf() throws Exception {
runTest("compiler/testData/codegen/box/enum/enumValueOf.kt");
}
@TestMetadata("enumWithLambdaParameter.kt")
public void testEnumWithLambdaParameter() throws Exception {
runTest("compiler/testData/codegen/box/enum/enumWithLambdaParameter.kt");
@@ -10347,6 +10347,11 @@ public class IrJsCodegenBoxES6TestGenerated extends AbstractIrJsCodegenBoxES6Tes
runTest("compiler/testData/codegen/box/enum/enumShort.kt");
}
@TestMetadata("enumValueOf.kt")
public void testEnumValueOf() throws Exception {
runTest("compiler/testData/codegen/box/enum/enumValueOf.kt");
}
@TestMetadata("enumWithLambdaParameter.kt")
public void testEnumWithLambdaParameter() throws Exception {
runTest("compiler/testData/codegen/box/enum/enumWithLambdaParameter.kt");
@@ -9768,6 +9768,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/enum/enumShort.kt");
}
@TestMetadata("enumValueOf.kt")
public void testEnumValueOf() throws Exception {
runTest("compiler/testData/codegen/box/enum/enumValueOf.kt");
}
@TestMetadata("enumWithLambdaParameter.kt")
public void testEnumWithLambdaParameter() throws Exception {
runTest("compiler/testData/codegen/box/enum/enumWithLambdaParameter.kt");
@@ -9768,6 +9768,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/enum/enumShort.kt");
}
@TestMetadata("enumValueOf.kt")
public void testEnumValueOf() throws Exception {
runTest("compiler/testData/codegen/box/enum/enumValueOf.kt");
}
@TestMetadata("enumWithLambdaParameter.kt")
public void testEnumWithLambdaParameter() throws Exception {
runTest("compiler/testData/codegen/box/enum/enumWithLambdaParameter.kt");
@@ -4727,6 +4727,11 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest
runTest("compiler/testData/codegen/box/enum/enumShort.kt");
}
@TestMetadata("enumValueOf.kt")
public void testEnumValueOf() throws Exception {
runTest("compiler/testData/codegen/box/enum/enumValueOf.kt");
}
@TestMetadata("enumWithLambdaParameter.kt")
public void testEnumWithLambdaParameter() throws Exception {
runTest("compiler/testData/codegen/box/enum/enumWithLambdaParameter.kt");