Allow serialization plugin to work with inline types which are primitives (e.g. Char in JS IR)

This commit is contained in:
Leonid Startsev
2019-08-15 16:11:18 +03:00
parent ed786c4daf
commit 19c28c55c5
@@ -6,6 +6,7 @@
package org.jetbrains.kotlinx.serialization.compiler.diagnostic package org.jetbrains.kotlinx.serialization.compiler.diagnostic
import com.intellij.psi.PsiElement import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.diagnostics.DiagnosticFactory0 import org.jetbrains.kotlin.diagnostics.DiagnosticFactory0
import org.jetbrains.kotlin.diagnostics.reportFromPlugin import org.jetbrains.kotlin.diagnostics.reportFromPlugin
@@ -190,6 +191,8 @@ open class SerializationPluginDeclarationChecker : DeclarationChecker {
} }
} }
private fun KotlinType.isUnsupportedInlineType() = isInlineClassType() && !KotlinBuiltIns.isPrimitiveTypeOrNullablePrimitiveType(this)
private fun AbstractSerialGenerator.checkType( private fun AbstractSerialGenerator.checkType(
module: ModuleDescriptor, module: ModuleDescriptor,
type: KotlinType, type: KotlinType,
@@ -199,7 +202,7 @@ open class SerializationPluginDeclarationChecker : DeclarationChecker {
) { ) {
if (type.genericIndex != null) return // type arguments always have serializer stored in class' field if (type.genericIndex != null) return // type arguments always have serializer stored in class' field
val element = ktType?.typeElement val element = ktType?.typeElement
if (type.isInlineClassType()) { if (type.isUnsupportedInlineType()) {
trace.reportFromPlugin( trace.reportFromPlugin(
SerializationErrors.INLINE_CLASSES_NOT_SUPPORTED.on(element ?: fallbackElement), SerializationErrors.INLINE_CLASSES_NOT_SUPPORTED.on(element ?: fallbackElement),
SerializationPluginErrorsRendering SerializationPluginErrorsRendering