File tree 2 files changed +34
-1
lines changed
core/commonMain/src/kotlinx/serialization/internal
2 files changed +34
-1
lines changed Original file line number Diff line number Diff line change @@ -27,7 +27,7 @@ internal object DurationSerializer : KSerializer<Duration> {
27
27
28
28
@PublishedApi
29
29
internal object NothingSerializer : KSerializer<Nothing> {
30
- override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor ( " kotlin.Nothing " , PrimitiveKind . INT )
30
+ override val descriptor: SerialDescriptor = NothingSerialDescriptor
31
31
32
32
override fun serialize (encoder : Encoder , value : Nothing ) {
33
33
throw SerializationException (" 'kotlin.Nothing' cannot be serialized" )
Original file line number Diff line number Diff line change
1
+ /*
2
+ * Copyright 2017-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3
+ */
4
+
5
+ @file:OptIn(ExperimentalSerializationApi ::class )
6
+
7
+ package kotlinx.serialization.internal
8
+
9
+ import kotlinx.serialization.ExperimentalSerializationApi
10
+ import kotlinx.serialization.descriptors.SerialDescriptor
11
+ import kotlinx.serialization.descriptors.SerialKind
12
+ import kotlinx.serialization.descriptors.StructureKind
13
+
14
+ internal object NothingSerialDescriptor : SerialDescriptor {
15
+ public override val kind: SerialKind = StructureKind .OBJECT
16
+
17
+ public override val serialName: String = " kotlin.Nothing"
18
+
19
+ override val elementsCount: Int get() = 0
20
+ override fun getElementName (index : Int ): String = error()
21
+ override fun getElementIndex (name : String ): Int = error()
22
+ override fun isElementOptional (index : Int ): Boolean = error()
23
+ override fun getElementDescriptor (index : Int ): SerialDescriptor = error()
24
+ override fun getElementAnnotations (index : Int ): List <Annotation > = error()
25
+ override fun toString (): String = " NothingSerialDescriptor"
26
+ override fun equals (other : Any? ): Boolean {
27
+ return this == = other
28
+ }
29
+
30
+ override fun hashCode (): Int = serialName.hashCode() + 31 * kind.hashCode()
31
+ private fun error (): Nothing =
32
+ throw IllegalStateException (" Descriptor for type `kotlin.Nothing` does not have elements" )
33
+ }
You can’t perform that action at this time.
0 commit comments