Files
kotlin-fork/plugins/kotlinx-serialization/testData/diagnostics/ParametrizedExternalSerializers.kt
T
Sergey.Shanshin 84ad12be57 [KxSerialization] Added inspections on custom serializer parameters
Added inspections to check:
- custom serializer on class has as many parameters in primary constructor as the serializable class of type arguments
- all parameters in custom serializer has `KSerializer` type
- property in serializable class not parametrized by type parameter
- custom serializer on property of serializable class have no parameters in primary constructor
2024-02-12 15:54:11 +00:00

62 lines
2.0 KiB
Kotlin
Vendored

// FIR_IDENTICAL
import kotlinx.serialization.*
import kotlinx.serialization.descriptors.*
import kotlinx.serialization.encoding.*
class Prop1<T>(val t: T)
class Prop2<T, R>(val t: T, val r: R)
<!EXTERNAL_SERIALIZER_NO_SUITABLE_CONSTRUCTOR!>@Serializer(forClass = Prop1::class)
class ExternalSerializer0_1<!>
@Serializer(forClass = Prop1::class)
class ExternalSerializer1_1(val typeSerial0: KSerializer<Any>)
@Serializer(forClass = Prop1::class)
class ExternalSerializer1_1Secondary() {
var typeSerial0: KSerializer<Any>? = null
constructor(typeSerial0: KSerializer<Any>) : this() {
this.typeSerial0 = typeSerial0
}
}
<!EXTERNAL_SERIALIZER_NO_SUITABLE_CONSTRUCTOR!>@Serializer(forClass = Prop2::class)
class ExternalSerializer0_2<!>
<!EXTERNAL_SERIALIZER_NO_SUITABLE_CONSTRUCTOR!>@Serializer(forClass = Prop2::class)
class ExternalSerializer1_2(val typeSerial0: KSerializer<Any>)<!>
<!EXTERNAL_SERIALIZER_NO_SUITABLE_CONSTRUCTOR!>@Serializer(forClass = Prop2::class)
class ExternalSerializer1_2Secondary() {
var typeSerial0: KSerializer<Any>? = null
constructor(typeSerial0: KSerializer<Any>) : this() {
this.typeSerial0 = typeSerial0
}
}<!>
@Serializer(forClass = Prop2::class)
class ExternalSerializer2_2Secondary() {
var typeSerial0: KSerializer<Any>? = null
var typeSerial1: KSerializer<Any>? = null
constructor(typeSerial0: KSerializer<Any>) : this() {
this.typeSerial0 = typeSerial0
}
constructor(typeSerial0: KSerializer<Any>, typeSerial1: KSerializer<Any>) : this() {
this.typeSerial0 = typeSerial0
this.typeSerial1 = typeSerial1
}
}
<!EXTERNAL_SERIALIZER_NO_SUITABLE_CONSTRUCTOR!>@Serializer(forClass = Prop1Err::class)
class ExternalSerializer0_1Err<!>
// there is no error in the discrepancy between the number of constructor parameters in the serializer
// because the checks take place at the place where the serializer is declared, and if the serializer is declared correctly, there will be no error here
@Serializable(ExternalSerializer0_1Err::class)
class Prop1Err<T>(val t: T)