Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8c50e85

Browse files
tamasvajkigfoo
authored andcommitted
Add comments to clarify JVM type substitution for invoke methods
1 parent 1317d2d commit 8c50e85

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

java/kotlin-extractor/src/main/kotlin/KotlinFileExtractor.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1151,6 +1151,8 @@ open class KotlinFileExtractor(
11511151
if (drType != null && extractClassTypeArguments && drType is IrSimpleType && !isUnspecialised(drType)) {
11521152

11531153
val extractionMethod = if (isFunctionInvoke) {
1154+
// For `kotlin.FunctionX` and `kotlin.reflect.KFunctionX` interfaces, we're making sure that we
1155+
// extract the call to the `invoke` method that does exist, `kotlin.jvm.functions.FunctionX::invoke`.
11541156
val interfaceType = getFunctionalInterfaceTypeWithTypeArgs(drType.arguments).classOrNull!!.owner
11551157
val substituted = getJavaEquivalentClass(interfaceType) ?: interfaceType
11561158
findFunction(substituted, OperatorNameConventions.INVOKE.asString())!!
@@ -1159,6 +1161,9 @@ open class KotlinFileExtractor(
11591161
}
11601162

11611163
if (isBigArityFunctionInvoke) {
1164+
// Big arity `invoke` methods have a special implementation on JVM, they are transformed to a call to
1165+
// `kotlin.jvm.functions.FunctionN<out R>::invoke(vararg args: Any?)`, so we only need to pass the type
1166+
// argument for the return type. Additionally, the arguments are extracted inside an array literal below.
11621167
useFunction<DbCallable>(extractionMethod, listOf(drType.arguments.last()))
11631168
} else {
11641169
useFunction<DbCallable>(extractionMethod, getDeclaringTypeArguments(callTarget, drType))

0 commit comments

Comments
 (0)