Kotlinx.serialization rounds longs on deserialization when using Kotlin/JS's IR compiler
Describe the bug
When trying to deserialize a object that has a long when using the new IR compiler, kotlinx.serialization rounds the long instead of keeping it as is.
This does not happen with the legacy compiler!
And yes, I know, the IR compiler is still experimental... (I'm using it because the IR compiler has some very nice size gains compared to the legacy compiler!) but it is still a very nasty bug!
To Reproduce
import kotlinx.browser.document
import kotlinx.serialization.Serializable
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
fun main() {
document.write("Hello, world!")
val data = DataWithId(236167700777271297L)
val json = Json.encodeToString(data)
println("Serialized Data: $json")
val dataDeserialized = Json.decodeFromString<DataWithId>(json)
println("Deserialized Data: $dataDeserialized")
}
@Serializable
data class DataWithId(val id: Long)
Expected behavior
That the id would be 236167700777271297, not 236167700777271300
With the IR compiler:

With the Legacy compiler:

Environment
- Kotlin version: 1.4.20
- Library version: 1.1.0
- Kotlin platforms: JavaScript (with the IR compiler)
- Gradle version: 6.7
- IDE version (if bug is related to the IDE) [e.g. IntellijIDEA 2019.1, Android Studio 3.4]
- Other relevant context [e.g. OS version, JRE version, ... ]
Still happening in Kotlin 1.5.31 + kotlinx.serialization 1.3.1, however I think I'm going to shift the blame to Kotlin itself, not kotlinx.serialization!
println("Test: ${"197308318119755776".toLong()}")
Prints Test: 197308318119755780 😭
Created YouTrack for this compiler bug: https://youtrack.jetbrains.com/issue/KT-49913
Fixed in Kotlin 1.6.20-M1