diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/ir/IrUtils.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/ir/IrUtils.kt index d9cb26bb2d2..a141f2eee9c 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/ir/IrUtils.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/ir/IrUtils.kt @@ -85,8 +85,10 @@ val IrType.erasedUpperBound: IrClass fun IrDeclaration.getJvmNameFromAnnotation(): String? { - val const = getAnnotation(DescriptorUtils.JVM_NAME)?.getValueArgument(0) as? IrConst<*> - return const?.value as? String + // TODO lower @JvmName? + val const = getAnnotation(DescriptorUtils.JVM_NAME)?.getValueArgument(0) as? IrConst<*> ?: return null + val value = const.value as? String ?: return null + return if (origin == IrDeclarationOrigin.FUNCTION_FOR_DEFAULT_PARAMETER) "$value\$default" else value } val IrFunction.propertyIfAccessor: IrDeclaration diff --git a/compiler/testData/codegen/box/jvmName/functionWithDefault.kt b/compiler/testData/codegen/box/jvmName/functionWithDefault.kt new file mode 100644 index 00000000000..6ab5ff8b77b --- /dev/null +++ b/compiler/testData/codegen/box/jvmName/functionWithDefault.kt @@ -0,0 +1,11 @@ +// TARGET_BACKEND: JVM +// WITH_RUNTIME + +@JvmName("bar") +fun foo(x: String = (object {}).javaClass.enclosingMethod.name) = x + +fun box(): String { + val f = foo() + if (f != "bar\$default") return "Fail: $f" + return "OK" +} diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index 29a2e5aa907..52aa8b30d5f 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -15091,6 +15091,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/jvmName/functionName.kt"); } + @TestMetadata("functionWithDefault.kt") + public void testFunctionWithDefault() throws Exception { + runTest("compiler/testData/codegen/box/jvmName/functionWithDefault.kt"); + } + @TestMetadata("loadJvmName.kt") public void testLoadJvmName() throws Exception { runTest("compiler/testData/codegen/box/jvmName/loadJvmName.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index cde374e7eac..32a9059c1d0 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -15091,6 +15091,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/jvmName/functionName.kt"); } + @TestMetadata("functionWithDefault.kt") + public void testFunctionWithDefault() throws Exception { + runTest("compiler/testData/codegen/box/jvmName/functionWithDefault.kt"); + } + @TestMetadata("loadJvmName.kt") public void testLoadJvmName() throws Exception { runTest("compiler/testData/codegen/box/jvmName/loadJvmName.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java index 9de13d8c864..337c3b63a0f 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java @@ -13976,6 +13976,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/jvmName/functionName.kt"); } + @TestMetadata("functionWithDefault.kt") + public void testFunctionWithDefault() throws Exception { + runTest("compiler/testData/codegen/box/jvmName/functionWithDefault.kt"); + } + @TestMetadata("loadJvmName.kt") public void testLoadJvmName() throws Exception { runTest("compiler/testData/codegen/box/jvmName/loadJvmName.kt");