This branch adds tests for the FirSerializationTypeAliasChecker
in the Kotlin Serialization compiler plugin. The checker reports warnings when the kotlinx.serialization.Serializable
annotation is used as a typealias in Kotlin code compiled with K2 (the new Kotlin compiler).
The K2 compiler does not expand annotation typealiases on the COMPILER_REQUIRED_ANNOTATIONS
phase. This means that when the Serializable
annotation is used through a typealias, it might not be properly processed by the serialization plugin, potentially leading to unexpected behavior.
This branch adds a comprehensive test file (typeAliasedSerializable.fir.kt
) that verifies the correct behavior of the FirSerializationTypeAliasChecker
. The test file includes:
A typealias for the Serializable
annotation:
typealias MySerializable = Serializable
Normal usage of the Serializable
annotation (which should not trigger a warning):
@Serializable class NormalClass(val value: String)
Usage of the typealiased Serializable
annotation (which should trigger a warning):
@MySerializable class TypeAliasedClass(val value: String)
Usage of the typealiased Serializable
annotation with a custom serializer (which should also trigger a warning):
@MySerializable(CustomSerializer::class) class TypeAliasedClassWithCustomSerializer(val value: String)
The test file includes the expected diagnostic markers (<!TYPEALIASED_SERIALIZABLE_ANNOTATION!>
) to indicate where the warnings should be reported.
The FirSerializationTypeAliasChecker
is implemented in the Kotlin Serialization compiler plugin and is responsible for detecting and reporting warnings when the Serializable
annotation is used through a typealias. The checker:
kotlinx.serialization.Serializable
Serializable
This warning helps developers avoid potential issues when using the Serialization plugin with K2. By warning about typealiased Serializable
annotations, it guides developers toward using the annotation directly, ensuring proper processing by the compiler.
When a developer uses a typealiased Serializable
annotation, they will see the following warning:
Typealiased kotlinx.serialization.Serializable annotation is not expanded on the COMPILER_REQUIRED_ANNOTATIONS phase in K2 compiler. Consider using @MetaSerializable instead.
The warning not only explains the issue but also suggests using @MetaSerializable
as an alternative approach for creating custom serializable annotations.