I believe I've discovered a bug in the Kotlin/JS I...
# javascript
d
I believe I've discovered a bug in the Kotlin/JS IR compiler (or at least some undefined or problematic behavior). If you have the following class (first code block), generate the javascript from the class, and then use that Javascript in the browser (second code block) the result is that despite there not being a reference to SingletonWithCoroutine it is instantiated nonetheless. An object singleton that does not use a CompleteableDeferred does not have this problem and will only instantiate the first time the singleton is referenced. Any thoughts?
Copy code
import kotlinx.coroutines.*
import kotlin.coroutines.CoroutineContext
import kotlin.js.JsExport

sealed class DeferredClass(val successful: Boolean)

@JsExport
object SingletonWithCoroutine : CoroutineScope {

    @JsExport.Ignore
    internal val job = Job()

    @JsExport.Ignore
    private const val NUM_LOAD_WORKERS = 8


    @JsExport.Ignore
    override val coroutineContext: CoroutineContext
        get() = job

    @JsExport.Ignore
    suspend fun testSuspend(assetPath: String): Unit {
        val deferred = Deferred()
        val loaded = deferred.awaiting.await()
    }

    @JsExport.Ignore
    private class Deferred(val awaiting: CompletableDeferred<DeferredClass> = CompletableDeferred(job))

    @JsExport.Ignore
    var test = myFun()

    private fun myFun() {
        throw Exception("This should only be thrown the first time this is referenced")
    }
}
Copy code
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="node_modules/singleton/kotlin-kotlin-stdlib-js-ir.js"></script>
    <script src="node_modules/singleton/88b0986a7186d029-atomicfu-js-ir.js"></script>
    <script src="node_modules/singleton/kotlinx.coroutines-kotlinx-coroutines-core-js-ir.js"></script>
    <script src="node_modules/singleton/singleton.js"></script>
</head>
<body>

</body>
</html>
a
Hey 👋 What is the module system you use?
Could you also, if it's possible, share the generated code?
d
Module system?
Where do you want me to share the project? I can zip it up.
Here or in the ticket?
initialization-test.zip
Trying to upload to Youtrack but it says it's in read-only mode.
a
I will take a look
d
Let me know if you need instructions on how to build.
👌 1
a
I reproduced the problem. Will try to fix it to add it into 1.9.20, sorry. The problem really exists in case when you declare a nested/inner class (enum, object, etc) in export object
d
No need to be sorry! Totally understand the complexity of what your team is trying to accomplish. I am amazed by how responsive you all are! Is there a ticket I can follow?
a
Thank you for such words, I didn't create any ticket, but, if you would create it, I will be a little bit happier 😄
d
KT-60425. It wouldn't let me attach a project to it though.
thank you color 1
👀 1
🙏 1
Just to set expectations, is there a target for when 1.9.20 will be released?
a
I'm not 100% sure, but it should be somewhen in October.
👍 1