[KxSerialization] Fix SERIALIZER_NOT_FOUND diagnostic for enums

If enum class from dependencies is used, which was compiled by a new version of the plugin, which uses a factory and does not create a nested `$serializer` class, then an `SERIALIZER_NOT_FOUND` diagnostic error is thrown for such an enumeration.
This happens if the old serialization runtime is used for the current project - in this case, the serializer is taken from the nested class `$serializer`. Since it is missing, the diagnostics does not work correctly.
It is acceptable for enumerations to ignore this error, because we know that enumerations are always serializable.

Merge-request: KT-MR-8818
Merged-by: Sergey Shanshin <Sergey.Shanshin@jetbrains.com>
This commit is contained in:
Sergey.Shanshin
2023-02-14 22:10:30 +00:00
committed by Space Team
parent c9b8160f1e
commit 498c1abbc6
3 changed files with 10 additions and 3 deletions
@@ -160,7 +160,7 @@ class SerializationJvmIrIntrinsicSupport(
}
override val runtimeHasEnumSerializerFactoryFunctions: Boolean
get() = currentVersion != null && currentVersion!! > ApiVersion.parse("1.4.0")!!
get() = currentVersion != null && currentVersion!! >= ApiVersion.parse("1.5.0")!!
private val hasNewContextSerializerSignature: Boolean
get() = currentVersion != null && currentVersion!! >= ApiVersion.parse("1.2.0")!!
@@ -25,6 +25,7 @@ import org.jetbrains.kotlin.resolve.descriptorUtil.*
import org.jetbrains.kotlin.resolve.lazy.descriptors.LazyAnnotationDescriptor
import org.jetbrains.kotlin.resolve.source.getPsi
import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.types.typeUtil.isEnum
import org.jetbrains.kotlin.types.typeUtil.supertypes
import org.jetbrains.kotlin.util.slicedMap.Slices
import org.jetbrains.kotlin.util.slicedMap.WritableSlice
@@ -501,7 +502,10 @@ open class SerializationPluginDeclarationChecker : DeclarationChecker {
checkSerializerNullability(type, serializer.defaultType, element, trace, fallbackElement)
checkTypeArguments(module, type, element, trace, fallbackElement)
} else {
trace.report(SerializationErrors.SERIALIZER_NOT_FOUND.on(element ?: fallbackElement, type))
if (!type.isEnum()) {
// enums are always serializable
trace.report(SerializationErrors.SERIALIZER_NOT_FOUND.on(element ?: fallbackElement, type))
}
}
}
@@ -539,7 +539,10 @@ object FirSerializationPluginClassChecker : FirClassChecker() {
}
checkTypeArguments(type, source, reporter)
} else {
reporter.reportOn(source, FirSerializationErrors.SERIALIZER_NOT_FOUND, type)
if (!type.isEnum) {
// enums are always serializable
reporter.reportOn(source, FirSerializationErrors.SERIALIZER_NOT_FOUND, type)
}
}
}