@@ -1600,11 +1600,13 @@ open class KotlinFileExtractor(
16001600 return result
16011601 }
16021602
1603- private fun findTopLevelFunctionOrWarn (functionFilter : String , type : String , warnAgainstElement : IrElement ): IrFunction ? {
1603+ private fun findTopLevelFunctionOrWarn (functionFilter : String , type : String , parameterTypes : Array < String >, warnAgainstElement : IrElement ): IrFunction ? {
16041604
16051605 val fn = pluginContext.referenceFunctions(FqName (functionFilter))
1606- .firstOrNull { it.owner.parentClassOrNull?.fqNameWhenAvailable?.asString() == type }
1607- ?.owner
1606+ .firstOrNull { fnSymbol ->
1607+ fnSymbol.owner.parentClassOrNull?.fqNameWhenAvailable?.asString() == type &&
1608+ fnSymbol.owner.valueParameters.map { it.type.classFqName?.asString() }.toTypedArray() contentEquals parameterTypes
1609+ }?.owner
16081610
16091611 if (fn != null ) {
16101612 if (fn.parentClassOrNull != null ) {
@@ -1756,6 +1758,12 @@ open class KotlinFileExtractor(
17561758 else -> false
17571759 }
17581760
1761+ private fun isGenericArrayType (typeName : String ) =
1762+ when (typeName) {
1763+ " Array" -> true
1764+ else -> false
1765+ }
1766+
17591767 private fun extractCall (c : IrCall , callable : Label <out DbCallable >, stmtExprParent : StmtExprParent ) {
17601768 with (" call" , c) {
17611769 val target = tryReplaceSyntheticFunction(c.symbol.owner)
@@ -2178,7 +2186,19 @@ open class KotlinFileExtractor(
21782186 }
21792187 }
21802188 isFunction(target, " kotlin" , " (some array type)" , { isArrayType(it) }, " iterator" ) -> {
2181- findTopLevelFunctionOrWarn(" kotlin.jvm.internal.iterator" , " kotlin.jvm.internal.ArrayIteratorKt" , c)?.let { iteratorFn ->
2189+ val parentClass = target.parent
2190+ if (parentClass !is IrClass ) {
2191+ logger.errorElement(" Iterator parent is not a class" , c)
2192+ return
2193+ }
2194+
2195+ var typeFilter = if (isGenericArrayType(parentClass.name.asString())) {
2196+ " kotlin.jvm.internal.ArrayIteratorKt"
2197+ } else {
2198+ " kotlin.jvm.internal.ArrayIteratorsKt"
2199+ }
2200+
2201+ findTopLevelFunctionOrWarn(" kotlin.jvm.internal.iterator" , typeFilter, arrayOf(parentClass.kotlinFqName.asString()), c)?.let { iteratorFn ->
21822202 val dispatchReceiver = c.dispatchReceiver
21832203 if (dispatchReceiver == null ) {
21842204 logger.errorElement(" No dispatch receiver found for array iterator call" , c)
0 commit comments