Handle situation where KSerializer is absent from immediate supertypes
of the class used in @UseSerializers: Use methods to receive full list of supertypes. K1 supertypes() call returned all supertypes, while IrClass.supertypes and FirClassSymbol.resolvedSuperTypes return only immediate ones. This lead to a difference in behavior between K1 and K2, and regression after plugin backend was rewritten from descriptors to IR. #KT-55340 Fixed
This commit is contained in:
committed by
Space Team
parent
c011f0c374
commit
1c4614e93b
@@ -0,0 +1,48 @@
|
||||
// TARGET_BACKEND: JVM_IR
|
||||
|
||||
// WITH_STDLIB
|
||||
|
||||
// FILE: a.kt
|
||||
|
||||
package a
|
||||
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.descriptors.*
|
||||
import kotlinx.serialization.encoding.*
|
||||
|
||||
class IList<T>
|
||||
|
||||
abstract class DataSerializer<T, K>: KSerializer<T> {
|
||||
abstract fun getK(): K
|
||||
}
|
||||
|
||||
class MySerializer<T>(val elementSer: KSerializer<T>): DataSerializer<IList<T>, Int>() {
|
||||
|
||||
override fun getK(): Int = 42
|
||||
|
||||
override val descriptor: SerialDescriptor
|
||||
get() = PrimitiveSerialDescriptor("MySer<${elementSer.descriptor.serialName}>", PrimitiveKind.STRING)
|
||||
|
||||
override fun serialize(encoder: Encoder, value: IList<T>) = TODO("serialize")
|
||||
|
||||
override fun deserialize(decoder: Decoder): IList<T> = TODO("deserialize")
|
||||
}
|
||||
|
||||
// FILE: test.kt
|
||||
|
||||
@file:UseSerializers(MySerializer::class)
|
||||
|
||||
package a
|
||||
|
||||
import kotlinx.serialization.*
|
||||
|
||||
@Serializable
|
||||
class Holder(
|
||||
val i: Int,
|
||||
val c: IList<Int>
|
||||
)
|
||||
|
||||
fun box(): String {
|
||||
val d = Holder.serializer().descriptor.toString()
|
||||
return if (d == "a.Holder(i: kotlin.Int, c: MySer<kotlin.Int>)") "OK" else d
|
||||
}
|
||||
Reference in New Issue
Block a user