JVM: fix type mapping of big arity suspend function types

The code in IrTypeMapper was incorrectly translated from
KotlinTypeMapper during the development of JVM IR. The
`classDescriptor.hasBigArity` condition in KotlinTypeMapper was checking
if the class represents a function or a suspend function with big arity,
and the suspend function part was lost during conversion.

This resulted in incorrect generic signature being generated, which led
to malformed type exceptions from reflection, and compilation errors
from kapt stub generation.

Also, change a comment in irCodegenUtils to avoid confusion of numbered
function types (kotlin.jvm.functions.Function1, ...) with the big-arity
type kotlin.jvm.functions.FunctionN.

 #KT-58375 Fixed
This commit is contained in:
Alexander Udalov
2023-05-08 15:27:19 +02:00
committed by Space Team
parent f659b63aef
commit c06ec84bb1
14 changed files with 230 additions and 6 deletions
@@ -241,8 +241,8 @@ internal fun IrTypeMapper.mapClassSignature(irClass: IrClass, type: Type, genera
if (generateBodies && irClass.superTypes.any { it.isSuspendFunction() || it.isKSuspendFunction() }) {
// Do not generate this class in the kapt3 mode (generateBodies=false), because kapt3 transforms supertypes correctly in the
// "correctErrorTypes" mode only when the number of supertypes between PSI and bytecode is equal. Otherwise it tries to "correct"
// the FunctionN type and fails, because that type doesn't need an import in the Kotlin source (kotlin.FunctionN), but needs one
// in the Java source (kotlin.jvm.functions.FunctionN), and kapt3 doesn't perform any Kotlin->Java name lookup.
// the Function{n} type and fails, because that type doesn't need an import in the Kotlin source (kotlin.Function{n}), but needs one
// in the Java source (kotlin.jvm.functions.Function{n}), and kapt3 doesn't perform any Kotlin->Java name lookup.
kotlinMarkerInterfaces.add("kotlin/coroutines/jvm/internal/SuspendFunction")
}