When casting a suspending lambda to a `kotlin.refl...
# javascript
r
When casting a suspending lambda to a
kotlin.reflect.KSuspendFunction2
type with IR backend, I've got a compiler error:
Copy code
> Task :compileDevelopmentExecutableKotlinFrontend FAILED
e: java.lang.IllegalStateException: Can't find name for declaration CLASS FUNCTION_INTERFACE_CLASS INTERFACE name:KSuspendFunction2 modality:ABSTRACT visibility:public superTypes:[kotlin.reflect.KFunction<R of kotlin.reflect.KSuspendFunction2>]
        at org.jetbrains.kotlin.ir.backend.js.utils.NameTables.getNameForStaticDeclaration(NameTables.kt:315)
        at org.jetbrains.kotlin.ir.backend.js.utils.IrNamerImpl.getNameForStaticDeclaration(IrNamerImpl.kt:20)
        at org.jetbrains.kotlin.ir.backend.js.transformers.irToJs.EmptyCrossModuleReferenceInfo$withReferenceTracking$1.getNameForStaticDeclaration(MultiModuleSupport.kt)
But what's interesting not when I compile the library with such code, but when I compile an app which uses it.
I don't think I'm able to extract a simple example and I have workaround the problem by casting to base
KFunction
type, which works fine.
And why can't I cast to
KSuspendFunction
nor
KFunction
in legacy mode? 🙂 It compiles fine but throws
Illegal Cast
exception at runtime ...
Porting a library to IR is too often writing conditional code 😉