You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
The serializer returned should be KSerializer<List> but the expected type is KSerializer<List<String?>>.
In other words, it doesn't honor the nullability of the first generic type of the list.
It happens only on jvm/1.8.20.
Workaround attached.
To Reproduce This repository reproduces the issue.
Btw all the code needed is this:
import kotlinx.serialization.KSerializer
import kotlinx.serialization.descriptors.elementDescriptors
import kotlinx.serialization.serializer
import kotlin.reflect.typeOf
import kotlin.test.Test
import kotlin.test.assertTrue
class IssueTest {
/** This fails with jvm/1.8.20 */
@Test
fun test_issue() {
assertTrue(listOfNullable<String>().descriptor.elementDescriptors.first().isNullable)
}
/** This works with all the combinations mentioned, i.e., js/jvm/1.8.20 and js/jvm/1.8.10 */
@Test
fun test_workaround() {
assertTrue(workaround<String>().descriptor.elementDescriptors.first().isNullable)
}
}
inline fun <reified T> listOfNullable(): KSerializer<List<Any?>> = serializer<List<T?>>() as KSerializer<List<Any?>>
inline fun <reified T> workaround(): KSerializer<List<Any?>> = serializer(typeOf<List<T?>>()) as KSerializer<List<Any?>>
Expected behavior
It should return a KSerializer<List<String?>>
Describe the bug
The serializer returned should be KSerializer<List> but the expected type is KSerializer<List<String?>>.
In other words, it doesn't honor the nullability of the first generic type of the list.
It happens only on jvm/1.8.20.
Workaround attached.
To Reproduce
This repository reproduces the issue.
Btw all the code needed is this:
Expected behavior
It should return a
KSerializer<List<String?>>
Environment
The text was updated successfully, but these errors were encountered: