Expand type aliases in K2 when checking if serializable class' properties

have serializers.

#KT-56594 Fixed
#KT-56480 Fixed
This commit is contained in:
Leonid Startsev
2023-03-13 16:02:37 +01:00
committed by Space Team
parent 63e27a9713
commit 5cf1c01273
5 changed files with 71 additions and 2 deletions
@@ -455,7 +455,7 @@ object FirSerializationPluginClassChecker : FirClassChecker() {
val serializerSymbol = customSerializerType?.toRegularClassSymbol(session)
val propertySymbol = property.propertySymbol
val typeRef = propertySymbol.resolvedReturnTypeRef
val propertyType = typeRef.coneType
val propertyType = typeRef.coneType.fullyExpandedType(session)
val source = typeRef.source ?: propertySymbol.source
if (customSerializerType != null && serializerSymbol != null) {
// Do not account for @Polymorphic and @Contextual, as they are serializers for T: Any
@@ -498,7 +498,7 @@ object FirSerializationPluginClassChecker : FirClassChecker() {
private fun checkTypeArguments(type: ConeKotlinType, source: KtSourceElement?, reporter: DiagnosticReporter) {
for (typeArgument in type.typeArguments) {
checkType(
typeArgument.type ?: continue,
typeArgument.type?.fullyExpandedType(session) ?: continue,
source,
reporter
)
@@ -0,0 +1,23 @@
// FIR_IDENTICAL
// FIR_DISABLE_LAZY_RESOLVE_CHECKS
// WITH_STDLIB
// SKIP_TXT
import kotlinx.serialization.*
typealias MyString = String
typealias MyLong = Long
@Serializable
class Box<T>(val t: T)
typealias MyBox<T> = Box<T>
@Serializable
class Foo(
val s: MyString,
val l: MyLong,
val b: Box<MyLong>,
val bb: MyBox<Long>,
val bbb: MyBox<MyLong>
)
@@ -0,0 +1,22 @@
// FIR_IDENTICAL
// FIR_DISABLE_LAZY_RESOLVE_CHECKS
// WITH_STDLIB
// SKIP_TXT
import kotlinx.serialization.*
import kotlinx.serialization.descriptors.*
import kotlinx.serialization.encoding.*
@Serializable(ExplicitSerializer::class)
data class Klass(val s: String)
object ExplicitSerializer : KSerializer<Klass> {
override val descriptor: SerialDescriptor get() = PrimitiveSerialDescriptor("klass", PrimitiveKind.STRING)
override fun serialize(encoder: Encoder, value: Klass) { encoder.encodeString(value.s) }
override fun deserialize(decoder: Decoder): Klass { return Klass(decoder.decodeString()) }
}
typealias KlassAlias = Klass
@Serializable
data class DataKlass(val k: KlassAlias)
@@ -151,6 +151,18 @@ public class SerializationFirPsiDiagnosticTestGenerated extends AbstractSerializ
public void testTransients() throws Exception {
runTest("plugins/kotlinx-serialization/testData/diagnostics/Transients.kt");
}
@Test
@TestMetadata("typeAliases.kt")
public void testTypeAliases() throws Exception {
runTest("plugins/kotlinx-serialization/testData/diagnostics/typeAliases.kt");
}
@Test
@TestMetadata("typeAliasesCustomized.kt")
public void testTypeAliasesCustomized() throws Exception {
runTest("plugins/kotlinx-serialization/testData/diagnostics/typeAliasesCustomized.kt");
}
}
@Nested
@@ -149,4 +149,16 @@ public class SerializationPluginDiagnosticTestGenerated extends AbstractSerializ
public void testTransients() throws Exception {
runTest("plugins/kotlinx-serialization/testData/diagnostics/Transients.kt");
}
@Test
@TestMetadata("typeAliases.kt")
public void testTypeAliases() throws Exception {
runTest("plugins/kotlinx-serialization/testData/diagnostics/typeAliases.kt");
}
@Test
@TestMetadata("typeAliasesCustomized.kt")
public void testTypeAliasesCustomized() throws Exception {
runTest("plugins/kotlinx-serialization/testData/diagnostics/typeAliasesCustomized.kt");
}
}