Skip to content

Commit 16af811

Browse files
committed
Allow imprecise matching for Kotlin -> Java method translation
This allows the particular case of Collection.toArray(IntFunction<T>) to match, since both Java and Kotlin functions take an IntFunction<T> but they use different function-local type variables. This would also allow toArray(Array<T>) to work similarly.
1 parent 77056c9 commit 16af811

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -911,7 +911,10 @@ open class KotlinUsesExtractor(
911911
decl is IrFunction &&
912912
decl.name == f.name &&
913913
decl.valueParameters.size == f.valueParameters.size &&
914-
decl.valueParameters.zip(f.valueParameters).all { p -> p.first.type == p.second.type }
914+
// Note matching by classifier not the whole type so that generic arguments are allowed to differ,
915+
// as they always will for method type parameters occurring in parameter types (e.g. <T> toArray(T[] array)
916+
// Differing only by nullability would also be insignificant if it came up.
917+
decl.valueParameters.zip(f.valueParameters).all { p -> p.first.type.classifierOrNull == p.second.type.classifierOrNull }
915918
} ?:
916919
// Or if there is none, look for the only viable overload
917920
javaClass.declarations.singleOrNull { decl ->

0 commit comments

Comments
 (0)