[KxSerialization] Added inspection on abstract custom serializer
Serialization requires an instance of the serializer, which cannot be obtained with the passed interface, abstract or sealed class. Therefore, the specifying of such classes in `Serializable` annotation must be prohibited. Fixes https://github.com/Kotlin/kotlinx.serialization/issues/2173 Relates #KT-58036 Merge-request: KT-MR-10753 Merged-by: Sergey Shanshin <Sergey.Shanshin@jetbrains.com>
This commit is contained in:
committed by
Space Team
parent
8602ed2d21
commit
3629a9db30
+37
@@ -0,0 +1,37 @@
|
||||
// FIR_DISABLE_LAZY_RESOLVE_CHECKS
|
||||
// FIR_IDENTICAL
|
||||
// SKIP_TXT
|
||||
// WITH_STDLIB
|
||||
|
||||
// FILE: test.kt
|
||||
import kotlinx.serialization.*
|
||||
|
||||
|
||||
interface InterfaceSerializer: KSerializer<WithInterfaceSerializer>
|
||||
|
||||
<!ABSTRACT_SERIALIZER_TYPE!>@Serializable(InterfaceSerializer::class)<!>
|
||||
class WithInterfaceSerializer(val i: Int)
|
||||
|
||||
|
||||
abstract class AbstractSerializer: KSerializer<WithAbstract>
|
||||
|
||||
<!ABSTRACT_SERIALIZER_TYPE!>@Serializable(AbstractSerializer::class)<!>
|
||||
class WithAbstract(val i: Int)
|
||||
|
||||
|
||||
sealed class SealedSerializer: KSerializer<WithSealed>
|
||||
|
||||
<!ABSTRACT_SERIALIZER_TYPE!>@Serializable(SealedSerializer::class)<!>
|
||||
class WithSealed(val i: Int)
|
||||
|
||||
@Serializable
|
||||
class Holder (
|
||||
<!ABSTRACT_SERIALIZER_TYPE!>@Serializable(InterfaceSerializer::class)<!>
|
||||
val withInterface: WithInterfaceSerializer,
|
||||
|
||||
<!ABSTRACT_SERIALIZER_TYPE!>@Serializable(AbstractSerializer::class)<!>
|
||||
val withAbstract: WithAbstract,
|
||||
|
||||
<!ABSTRACT_SERIALIZER_TYPE!>@Serializable(SealedSerializer::class)<!>
|
||||
val withSealed: WithSealed
|
||||
)
|
||||
Reference in New Issue
Block a user