Support @Serializable(ContextualSerializer) on class
It was fixed some time ago (https://github.com/Kotlin/kotlinx.serialization/issues/957) but for some reason only for old backend. Fixes https://github.com/Kotlin/kotlinx.serialization/issues/1776
This commit is contained in:
+1
@@ -403,6 +403,7 @@ abstract class BaseIrGenerator(private val currentClass: IrClass, final override
|
||||
// new signature of context serializer
|
||||
args = args + mutableListOf<IrExpression>().apply {
|
||||
val fallbackDefaultSerializer = findTypeSerializer(pluginContext, kType)
|
||||
.takeIf { it?.owner?.classId != contextSerializerId }
|
||||
add(instantiate(fallbackDefaultSerializer, kType) ?: irNull())
|
||||
add(
|
||||
createArrayOfExpression(
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
// TARGET_BACKEND: JVM_IR
|
||||
|
||||
// WITH_STDLIB
|
||||
|
||||
import kotlinx.serialization.*
|
||||
|
||||
@Serializable(with = ContextualSerializer::class)
|
||||
class Ref(
|
||||
val id: String,
|
||||
)
|
||||
|
||||
fun box(): String {
|
||||
val kind = Ref.serializer().descriptor.kind.toString()
|
||||
if (kind != "CONTEXTUAL") return kind
|
||||
return "OK"
|
||||
}
|
||||
+6
@@ -39,6 +39,12 @@ public class SerializationFirBlackBoxTestGenerated extends AbstractSerialization
|
||||
runTest("plugins/kotlinx-serialization/testData/boxIr/classSerializerAsObject.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("contextualByDefault.kt")
|
||||
public void testContextualByDefault() throws Exception {
|
||||
runTest("plugins/kotlinx-serialization/testData/boxIr/contextualByDefault.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("enumsAreCached.kt")
|
||||
public void testEnumsAreCached() throws Exception {
|
||||
|
||||
+6
@@ -37,6 +37,12 @@ public class SerializationIrBoxTestGenerated extends AbstractSerializationIrBoxT
|
||||
runTest("plugins/kotlinx-serialization/testData/boxIr/classSerializerAsObject.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("contextualByDefault.kt")
|
||||
public void testContextualByDefault() throws Exception {
|
||||
runTest("plugins/kotlinx-serialization/testData/boxIr/contextualByDefault.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("enumsAreCached.kt")
|
||||
public void testEnumsAreCached() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user