[JVM_IR] Fix mangling of default argument stubs for internal methods.
The MethodSignatureMapper expected to be able to look at the body of the default argument stub. That is of course not possible when it is from an external dependency. Instead, we go through the attribute owner to get to the method the stub is a default argument adapter for.
This commit is contained in:
committed by
Alexander Udalov
parent
8c88670185
commit
afd710292a
+5
@@ -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");
|
||||
|
||||
+17
-12
@@ -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 =
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
+5
@@ -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");
|
||||
|
||||
Generated
+5
@@ -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");
|
||||
|
||||
+5
@@ -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");
|
||||
|
||||
+5
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user