Skip to content

Commit

Permalink
JVM IR: Fix inline class mangling for calls to internal functions
Browse files Browse the repository at this point in the history
...in a different module, e.g., using -Xfriend-paths.
  • Loading branch information
Steven Schäfer authored and ilmirus committed Jan 29, 2021
1 parent 5a7c345 commit 4d6a1a8
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 3 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,10 @@ class MethodSignatureMapper(private val context: JvmBackendContext) {
!isPublishedApi() &&
!isSyntheticMethodForProperty
) {
return this
return originalFunction.takeIf { it != this }
?.safeAs<IrSimpleFunction>()
?.getInternalFunctionForManglingIfNeeded()
?: this
}
originalForDefaultAdapter?.getInternalFunctionForManglingIfNeeded()?.let { return it }
return null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -394,12 +394,13 @@ fun IrSimpleType.isRawType(): Boolean =
hasAnnotation(JvmGeneratorExtensions.RAW_TYPE_ANNOTATION_FQ_NAME)

internal fun classFileContainsMethod(classId: ClassId, function: IrFunction, context: JvmBackendContext): Boolean? {
val originalDescriptor = context.methodSignatureMapper.mapSignatureWithGeneric(function).asmMethod.descriptor
val originalSignature = context.methodSignatureMapper.mapSignatureWithGeneric(function).asmMethod
val originalDescriptor = originalSignature.descriptor
val descriptor = if (function.isSuspend)
listOf(*Type.getArgumentTypes(originalDescriptor), Type.getObjectType("kotlin/coroutines/Continuation"))
.joinToString(prefix = "(", postfix = ")", separator = "") + AsmTypes.OBJECT_TYPE
else originalDescriptor
return classFileContainsMethod(classId, context.state, Method(function.name.asString(), descriptor))
return classFileContainsMethod(classId, context.state, Method(originalSignature.name, descriptor))
}

val IrFunction.parentClassId: ClassId?
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// IGNORE_BACKEND_FIR: JVM_IR
// FILE: A.kt

package a

inline class Message(val value: String)

class Box {
internal fun result(msg: Message): String = msg.value
}

// FILE: B.kt

fun box(): String {
return a.Box().result(a.Message("OK"))
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4d6a1a8

Please sign in to comment.