Dear people! I am using Kotlin 2.3.20-Beta2 togeth...
# webassembly
j
Dear people! I am using Kotlin 2.3.20-Beta2 together with the new Koin compiler (4.2.0-RC1) in my kmp app. I am facing a problem with my current project which has a whole bunch of modules • wasm validation error: at offset 9041921: type mismatch: expression has type (ref null 11) but expected (ref null 3000) • CompileError: WebAssembly.instantiateStreaming(): Compiling function #35676:"com.myapp.core.network.module$lambda$..." failed: call[1] expected type (ref null 8656), found block of type (ref null 11) @+9041686 This error happens at runtime, compilation is okay, but at startup, before I can actually see the application, it will crash. these module$lambda... looks to me that it points to some of the generated code I have no idea how to debug this 🙂 Does anyone have any ideas what I can do? I tried also to make a simpler project with only 2 modules to reproduce it, but there I do not get this exception. If I remove the annotations (and with it the generated code), then it will just crash similarly on another module. My project did work fine with kotlin 2.3.0 and the "old-school" koin ksp version, also my project does work fine on other platforms (jvm and android) so I have a feeling it is wasm related. Also I had no luck in the koin channel, so I hope here somebody could point me in the right direction
c
Well, they said you should provide a minimal producer. 🤷‍♂️ it's most probably a compiler plugin issue with the code you write.
j
I tried to reproduce it, just no luck
I was hoping maybe somebody can give me some pointers on how to proceed, like maybe i can debug the generated code/wasm file, i just dont know how. Or maybe somebody has knowledge what this error could be based on experience
r
Sometimes adding a JS target can allow to to debug wasmJS errors.
j
I have now figured out that if I try to inject json: Json into a place, it fails, so seems to be related to using 3rd party libraries like serialization and ktor client. I think same for httpClient: HttpClient. Perhaps because if you create a Json {...} it will woefully bind to the actual implementation class instead of the Json class, same for HttpClient. I am still checking other places in my project as now different modules are failing me 🙂 no idea what is at fault, but it looks like I can reproduce it and I will put up a sample soon-ish
So here is a simple version that breaks, I will continue the conversation in the koin channel. But because I already took your time I will also write what I found here 🙂 Somehow if I pass the DefaultExampleObject it doesn't like it, however if I pass the interface it is okay. I noticed it when I passed the
@Single provideHttpClient(json: Json): HttpClient = ....
but it is also doable with simpler objects:
Copy code
interface ExampleObject {
    fun getString(): String
}

@Single(binds = [DefaultExampleObject::class, ExampleObject::class])
class DefaultExampleObject() : ExampleObject {

    override fun getString(): String {
        return "I am a string"
    }

}

@Module
@Configuration
@ComponentScan
class ExampleModule {

    @Single
    fun brokenDefaultExampleObject(exampleObject: DefaultExampleObject): Int = 5

    @Single
    fun correctExampleObject(exampleObject: ExampleObject): String = exampleObject.getString()
}
👍🏻 1
b
@Joost Klitsie could you please file an issue?
👍 1