Hello. I am owner of <TelegramBotAPI library> and ...
# serialization
o
Hello. I am owner of TelegramBotAPI library and currently I am working on a new update related to new Kotlin and other dependencies versions. I have faced with an issue after upgrade of my project up to Kotlin 1.4.0 and Serialization up to 1.0.0-RC. It is look like currently code for JS serializer is generating incorrectly due to the fact that the test which normally must correctly work is failing. I have created a small bot for that and found the things you will see in attached screenshot. In two words:
tmp0_subject
was set up from
this._file_3
on line 98291 on screenshot. This value is absent, but there is value
value._file_3
which is look like something what must be on place of
tmp0_subject
I have launched test from previous message and capture screenshot with the same (or at least similar): we have calling of
this.file
which is absent, but target value is stored in in
value.file_gskrkt$_0
field
b
Simplified example:
Copy code
import kotlinx.serialization.*
import kotlinx.serialization.json.Json

@Serializable
class A(val prop: String) {
    val prop2: String = when(prop) {
        "aaa" -> "222"
        else -> {
            println("AAA") // Side effect
            "333"
        }
    }
    val prop3 = prop.length // unexpected TypeError
}

fun test() {
    val a = A("aaa")
    println(JSON.stringify(a))
    println(Json.encodeToString(a))
}

fun main() {
    test()
}
On both JS BEs it leads to crash with
TypeError
while serializing. I didn’t check it on other BEs. Also, it looks strange to observe side effects from prop2 initializer during serialization, is it intended? cc @sandwwraith @Vsevolod Tolstopyatov [JB]
In the original code it was
NoWhenBranchMatchedException
, but root of a problem is the same as in the simplified version.
v
b
@Vsevolod Tolstopyatov [JB] what about second part?
Also, it looks strange to observe side effects from prop2 initializer during serialization, is it intended?