Fixed missing fallback serializer in contextual serializer

Fixes Kotlin/kotlinx.serialization#2158

Merge-request: KT-MR-8338
Merged-by: Sergey Shanshin <Sergey.Shanshin@jetbrains.com>
This commit is contained in:
Sergey.Shanshin
2023-01-18 15:47:26 +00:00
committed by Space Team
parent da24e5559b
commit d063db3ce0
4 changed files with 42 additions and 0 deletions
@@ -467,6 +467,14 @@ abstract class BaseIrGenerator(private val currentClass: IrClass, final override
typeArgs = listOf(kType)
}
contextSerializerId -> {
// don't create an instance if the serializer is being created for the cache
if (genericIndex == null && kType.genericIndex != null) {
// if context serializer parametrized by generic type (kType.genericIndex != null)
// and generic types are not allowed (always genericIndex == null for cache)
// then serializer can't be cached
return null
}
args = listOf(classReference(kType.classOrUpperBound()!!))
typeArgs = listOf(kType)