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
getElementNamenull20     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 
hashCodenull30     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 }
34