diff --git a/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/FirCompileKotlinAgainstKotlinTestGenerated.java b/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/FirCompileKotlinAgainstKotlinTestGenerated.java index ff6351c8d34..a70fd85ae8c 100644 --- a/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/FirCompileKotlinAgainstKotlinTestGenerated.java +++ b/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/FirCompileKotlinAgainstKotlinTestGenerated.java @@ -178,6 +178,11 @@ public class FirCompileKotlinAgainstKotlinTestGenerated extends AbstractFirCompi runTest("compiler/testData/compileKotlinAgainstKotlin/internalSetterOverridden.kt"); } + @TestMetadata("internalWithDefaultArgs.kt") + public void testInternalWithDefaultArgs() throws Exception { + runTest("compiler/testData/compileKotlinAgainstKotlin/internalWithDefaultArgs.kt"); + } + @TestMetadata("internalWithOtherModuleName.kt") public void testInternalWithOtherModuleName() throws Exception { runTest("compiler/testData/compileKotlinAgainstKotlin/internalWithOtherModuleName.kt"); diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/MethodSignatureMapper.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/MethodSignatureMapper.kt index 5e44d7baca2..a9c36b9988b 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/MethodSignatureMapper.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/MethodSignatureMapper.kt @@ -105,12 +105,12 @@ class MethodSignatureMapper(private val context: JvmBackendContext) { private fun mangleMemberNameIfRequired(name: String, function: IrSimpleFunction): String { val newName = JvmCodegenUtil.sanitizeNameIfNeeded(name, context.state.languageVersionSettings) - val suffix = when { - function.isTopLevel -> - if (function.isInvisibleInMultifilePart()) function.parentAsClass.name.asString() else null - function.shouldMangleAsInternal() -> - NameUtils.sanitizeAsJavaIdentifier(getModuleName(function)) - else -> null + val suffix = if (function.isTopLevel) { + if (function.isInvisibleInMultifilePart()) function.parentAsClass.name.asString() else null + } else { + function.getInternalFunctionForManglingIfNeeded()?.let { + NameUtils.sanitizeAsJavaIdentifier(getModuleName(it)) + } } ?: return newName if (function.origin == IrDeclarationOrigin.FUNCTION_FOR_DEFAULT_PARAMETER) { @@ -127,15 +127,20 @@ class MethodSignatureMapper(private val context: JvmBackendContext) { (DescriptorVisibilities.isPrivate(suspendFunctionOriginal().visibility) || originalForDefaultAdapter?.isInvisibleInMultifilePart() == true) - private fun IrSimpleFunction.shouldMangleAsInternal(): Boolean = - (origin != JvmLoweredDeclarationOrigin.STATIC_INLINE_CLASS_CONSTRUCTOR && - visibility == DescriptorVisibilities.INTERNAL && - !isPublishedApi()) - || originalForDefaultAdapter?.shouldMangleAsInternal() == true + private fun IrSimpleFunction.getInternalFunctionForManglingIfNeeded(): IrSimpleFunction? { + if (origin != JvmLoweredDeclarationOrigin.STATIC_INLINE_CLASS_CONSTRUCTOR && + visibility == DescriptorVisibilities.INTERNAL && + !isPublishedApi() + ) { + return this + } + originalForDefaultAdapter?.getInternalFunctionForManglingIfNeeded()?.let { return it } + return null + } private val IrSimpleFunction.originalForDefaultAdapter: IrSimpleFunction? get() = if (origin == IrDeclarationOrigin.FUNCTION_FOR_DEFAULT_PARAMETER) { - ((body?.statements?.lastOrNull() as? IrReturn)?.value as? IrCall)?.symbol?.owner + (attributeOwnerId as IrFunction).symbol.owner as IrSimpleFunction } else null private fun getModuleName(function: IrSimpleFunction): String = diff --git a/compiler/testData/compileKotlinAgainstKotlin/internalWithDefaultArgs.kt b/compiler/testData/compileKotlinAgainstKotlin/internalWithDefaultArgs.kt new file mode 100644 index 00000000000..224667f963f --- /dev/null +++ b/compiler/testData/compileKotlinAgainstKotlin/internalWithDefaultArgs.kt @@ -0,0 +1,15 @@ +// IGNORE_BACKEND_FIR: JVM_IR +// IGNORE_BACKEND: NATIVE +// FILE: A.kt + +package a + +class Box() { + internal fun result(value: String = "OK"): String = value +} + +// FILE: B.kt + +fun box(): String { + return a.Box().result() +} diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstKotlinTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstKotlinTestGenerated.java index e937dc2640c..ca782f86282 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstKotlinTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstKotlinTestGenerated.java @@ -183,6 +183,11 @@ public class CompileKotlinAgainstKotlinTestGenerated extends AbstractCompileKotl runTest("compiler/testData/compileKotlinAgainstKotlin/internalSetterOverridden.kt"); } + @TestMetadata("internalWithDefaultArgs.kt") + public void testInternalWithDefaultArgs() throws Exception { + runTest("compiler/testData/compileKotlinAgainstKotlin/internalWithDefaultArgs.kt"); + } + @TestMetadata("internalWithOtherModuleName.kt") public void testInternalWithOtherModuleName() throws Exception { runTest("compiler/testData/compileKotlinAgainstKotlin/internalWithOtherModuleName.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrCompileKotlinAgainstKotlinTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrCompileKotlinAgainstKotlinTestGenerated.java index 8b8fbfc8ce6..934a3e50494 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrCompileKotlinAgainstKotlinTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrCompileKotlinAgainstKotlinTestGenerated.java @@ -178,6 +178,11 @@ public class IrCompileKotlinAgainstKotlinTestGenerated extends AbstractIrCompile runTest("compiler/testData/compileKotlinAgainstKotlin/internalSetterOverridden.kt"); } + @TestMetadata("internalWithDefaultArgs.kt") + public void testInternalWithDefaultArgs() throws Exception { + runTest("compiler/testData/compileKotlinAgainstKotlin/internalWithDefaultArgs.kt"); + } + @TestMetadata("internalWithOtherModuleName.kt") public void testInternalWithOtherModuleName() throws Exception { runTest("compiler/testData/compileKotlinAgainstKotlin/internalWithOtherModuleName.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/JvmIrAgainstOldBoxTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/JvmIrAgainstOldBoxTestGenerated.java index a9883877546..2a67be36af2 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/JvmIrAgainstOldBoxTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/JvmIrAgainstOldBoxTestGenerated.java @@ -178,6 +178,11 @@ public class JvmIrAgainstOldBoxTestGenerated extends AbstractJvmIrAgainstOldBoxT runTest("compiler/testData/compileKotlinAgainstKotlin/internalSetterOverridden.kt"); } + @TestMetadata("internalWithDefaultArgs.kt") + public void testInternalWithDefaultArgs() throws Exception { + runTest("compiler/testData/compileKotlinAgainstKotlin/internalWithDefaultArgs.kt"); + } + @TestMetadata("internalWithOtherModuleName.kt") public void testInternalWithOtherModuleName() throws Exception { runTest("compiler/testData/compileKotlinAgainstKotlin/internalWithOtherModuleName.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/JvmOldAgainstIrBoxTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/JvmOldAgainstIrBoxTestGenerated.java index 501027b170e..5004645338e 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/JvmOldAgainstIrBoxTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/JvmOldAgainstIrBoxTestGenerated.java @@ -178,6 +178,11 @@ public class JvmOldAgainstIrBoxTestGenerated extends AbstractJvmOldAgainstIrBoxT runTest("compiler/testData/compileKotlinAgainstKotlin/internalSetterOverridden.kt"); } + @TestMetadata("internalWithDefaultArgs.kt") + public void testInternalWithDefaultArgs() throws Exception { + runTest("compiler/testData/compileKotlinAgainstKotlin/internalWithDefaultArgs.kt"); + } + @TestMetadata("internalWithOtherModuleName.kt") public void testInternalWithOtherModuleName() throws Exception { runTest("compiler/testData/compileKotlinAgainstKotlin/internalWithOtherModuleName.kt");