Added support serialization of local classes in IR backend
Resolves Kotlin/kotlinx.serialization#1427
This commit is contained in:
plugins/kotlin-serialization/kotlin-serialization-compiler/testData/diagnostics/LocalAndAnonymous.kt
Vendored
+31
-6
@@ -1,17 +1,42 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER,-UNUSED_VARIABLE
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER,-UNUSED_VARIABLE,-EXPERIMENTAL_API_USAGE_ERROR,-EXPERIMENTAL_API_USAGE
|
||||
// WITH_RUNTIME
|
||||
// SKIP_TXT
|
||||
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.descriptors.*
|
||||
import kotlinx.serialization.encoding.*
|
||||
|
||||
fun container() {
|
||||
<!LOCAL_CLASSES_NOT_SUPPORTED!>@Serializable<!>
|
||||
class X
|
||||
@Serializable
|
||||
class X // local classes are allowed
|
||||
|
||||
val y = <!LOCAL_CLASSES_NOT_SUPPORTED!>@Serializable<!> object {}
|
||||
val y = <!ANONYMOUS_OBJECTS_NOT_SUPPORTED!>@Serializable<!> object {
|
||||
fun inObjectFun() {
|
||||
<!ANONYMOUS_OBJECTS_NOT_SUPPORTED!>@Serializable<!>
|
||||
class X // local classes in anonymous object functions are not allowed
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class LocalSerializer : KSerializer<Any?> {
|
||||
override val descriptor: SerialDescriptor = buildSerialDescriptor("tmp", PrimitiveKind.INT)
|
||||
override fun serialize(encoder: Encoder, value: Any?) {
|
||||
encoder.encodeNull()
|
||||
}
|
||||
|
||||
override fun deserialize(decoder: Decoder): Any? {
|
||||
return decoder.decodeNull()
|
||||
}
|
||||
}
|
||||
|
||||
@Serializable
|
||||
class WithLocalSerializerInProperty(<!LOCAL_SERIALIZER_USAGE!>@Serializable(with = LocalSerializer::class)<!> val x: Any?)
|
||||
|
||||
<!LOCAL_SERIALIZER_USAGE, SERIALIZER_TYPE_INCOMPATIBLE!>@Serializable(with = LocalSerializer::class)<!>
|
||||
data class WithLocalSerializer(val i: Int)
|
||||
}
|
||||
|
||||
val topLevelAnon = <!LOCAL_CLASSES_NOT_SUPPORTED!>@Serializable<!> object {}
|
||||
val topLevelAnon = <!ANONYMOUS_OBJECTS_NOT_SUPPORTED!>@Serializable<!> object {}
|
||||
|
||||
@Serializable class A {
|
||||
@Serializable class B // nested classes are allowed
|
||||
@@ -19,4 +44,4 @@ val topLevelAnon = <!LOCAL_CLASSES_NOT_SUPPORTED!>@Serializable<!> object {}
|
||||
<!INNER_CLASSES_NOT_SUPPORTED!>@Serializable<!> inner class C // inner classes are not
|
||||
|
||||
@Serializable object F {} // regular named object, OK
|
||||
}
|
||||
}
|
||||
|
||||
+3
@@ -14,6 +14,9 @@ object BazSerializer: KSerializer<Baz>
|
||||
@Serializer(forClass = Baz::class)
|
||||
object NullableBazSerializer: KSerializer<Baz?>
|
||||
|
||||
<!SERIALIZER_TYPE_INCOMPATIBLE!>@Serializable(with = BazSerializer::class)<!>
|
||||
class Biz(val i: Int)
|
||||
|
||||
@Serializable
|
||||
class Foo(@Serializable(with = BazSerializer::class) val i: <!SERIALIZER_TYPE_INCOMPATIBLE!>Bar<!>)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user