diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/IrTypeMapper.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/IrTypeMapper.kt index bdc69c3d6c3..345580f68ff 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/IrTypeMapper.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/IrTypeMapper.kt @@ -46,9 +46,26 @@ class IrTypeMapper(private val context: JvmBackendContext) : KotlinTypeMapperBas error("Unknown descriptor: $classifier") } - fun classInternalName(irClass: IrClass): String = - context.getLocalClassInfo(irClass)?.internalName - ?: JvmCodegenUtil.sanitizeNameIfNeeded(computeInternalName(irClass), context.state.languageVersionSettings) + fun classInternalName(irClass: IrClass): String { + context.getLocalClassInfo(irClass)?.internalName?.let { return it } + val className = SpecialNames.safeIdentifier(irClass.name).identifier + val internalName = when (val parent = irClass.parent) { + is IrPackageFragment -> { + val fqName = parent.fqName + val prefix = if (fqName.isRoot) "" else fqName.asString().replace('.', '/') + "/" + prefix + className + } + is IrClass -> { + classInternalName(parent) + "$" + className + } + else -> error( + "Local class should have its name computed in InventNamesForLocalClasses: ${irClass.fqNameWhenAvailable}\n" + + "Ensure that any lowering that transforms elements with local class info (classes, function references) " + + "invokes `copyAttributes` on the transformed element." + ) + } + return JvmCodegenUtil.sanitizeNameIfNeeded(internalName, context.state.languageVersionSettings) + } fun writeFormalTypeParameters(irParameters: List, sw: JvmSignatureWriter) { if (sw.skipGenericSignature()) return @@ -148,25 +165,6 @@ class IrTypeMapper(private val context: JvmBackendContext) : KotlinTypeMapperBas } } - private fun computeInternalName(klass: IrClass): String { - val className = SpecialNames.safeIdentifier(klass.name).identifier - return when (val parent = klass.parent) { - is IrPackageFragment -> { - val fqName = parent.fqName - val prefix = if (fqName.isRoot) "" else fqName.asString().replace('.', '/') + "/" - prefix + className - } - is IrClass -> { - computeInternalName(parent) + "$" + className - } - else -> error( - "Local class should have its name computed in InventNamesForLocalClasses: ${klass.fqNameWhenAvailable}\n" + - "Ensure that any lowering that transforms elements with local class info (classes, function references) " + - "invokes `copyAttributes` on the transformed element." - ) - } - } - // Copied from KotlinTypeMapper.writeGenericType. private fun JvmSignatureWriter.writeGenericType(type: IrSimpleType, asmType: Type, mode: TypeMappingMode) { if (skipGenericSignature() || hasNothingInNonContravariantPosition(type) || type.arguments.isEmpty()) { diff --git a/compiler/testData/codegen/box/enum/whenInObject.kt b/compiler/testData/codegen/box/enum/whenInObject.kt new file mode 100644 index 00000000000..39234df7d84 --- /dev/null +++ b/compiler/testData/codegen/box/enum/whenInObject.kt @@ -0,0 +1,16 @@ +enum class E { + OK, NOT_OK +} + +interface I { + fun f(e: E): String +} + +val obj = object: I { + override fun f(e: E) = when(e) { + E.OK -> "OK" + E.NOT_OK -> "NOT OK" + } +} + +fun box() = obj.f(E.OK) \ No newline at end of file diff --git a/compiler/testData/codegen/boxInline/suspend/inlineOrdinaryOfNoinlineSuspend.kt b/compiler/testData/codegen/boxInline/suspend/inlineOrdinaryOfNoinlineSuspend.kt index 7dc877c9fd9..c7fc5f17467 100644 --- a/compiler/testData/codegen/boxInline/suspend/inlineOrdinaryOfNoinlineSuspend.kt +++ b/compiler/testData/codegen/boxInline/suspend/inlineOrdinaryOfNoinlineSuspend.kt @@ -1,5 +1,3 @@ -// IGNORE_BACKEND: JVM_IR -// IGNORE_BACKEND_MULTI_MODULE: JVM_IR // FILE: test.kt // COMMON_COROUTINES_TEST // WITH_RUNTIME diff --git a/compiler/testData/codegen/boxInline/suspend/receiver/inlineOrdinaryOfNoinlineSuspend.kt b/compiler/testData/codegen/boxInline/suspend/receiver/inlineOrdinaryOfNoinlineSuspend.kt index 6a89494a857..9e65cc7e552 100644 --- a/compiler/testData/codegen/boxInline/suspend/receiver/inlineOrdinaryOfNoinlineSuspend.kt +++ b/compiler/testData/codegen/boxInline/suspend/receiver/inlineOrdinaryOfNoinlineSuspend.kt @@ -1,5 +1,3 @@ -// IGNORE_BACKEND: JVM_IR -// IGNORE_BACKEND_MULTI_MODULE: JVM_IR // FILE: test.kt // COMMON_COROUTINES_TEST // WITH_RUNTIME diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index 9600473b301..0de0fadcfd8 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -10562,6 +10562,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/enum/valueof.kt"); } + @TestMetadata("whenInObject.kt") + public void testWhenInObject() throws Exception { + runTest("compiler/testData/codegen/box/enum/whenInObject.kt"); + } + @TestMetadata("compiler/testData/codegen/box/enum/defaultCtor") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index 6c33a8a5520..52fcf316ee9 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -10562,6 +10562,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/enum/valueof.kt"); } + @TestMetadata("whenInObject.kt") + public void testWhenInObject() throws Exception { + runTest("compiler/testData/codegen/box/enum/whenInObject.kt"); + } + @TestMetadata("compiler/testData/codegen/box/enum/defaultCtor") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java index 8d5d3d8b6e6..6325b35b6e4 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java @@ -9447,6 +9447,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/enum/valueof.kt"); } + @TestMetadata("whenInObject.kt") + public void testWhenInObject() throws Exception { + runTest("compiler/testData/codegen/box/enum/whenInObject.kt"); + } + @TestMetadata("compiler/testData/codegen/box/enum/defaultCtor") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java index 46f217ec046..bcab500677d 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java @@ -8187,6 +8187,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest { runTest("compiler/testData/codegen/box/enum/valueof.kt"); } + @TestMetadata("whenInObject.kt") + public void testWhenInObject() throws Exception { + runTest("compiler/testData/codegen/box/enum/whenInObject.kt"); + } + @TestMetadata("compiler/testData/codegen/box/enum/defaultCtor") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java index 64a718efc6b..d7b8add4b78 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java @@ -9272,6 +9272,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { runTest("compiler/testData/codegen/box/enum/valueof.kt"); } + @TestMetadata("whenInObject.kt") + public void testWhenInObject() throws Exception { + runTest("compiler/testData/codegen/box/enum/whenInObject.kt"); + } + @TestMetadata("compiler/testData/codegen/box/enum/defaultCtor") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class)