-
Notifications
You must be signed in to change notification settings - Fork 628
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added SerialDescriptor object for NothingSerializer (#2150)
Improvement of #932
- Loading branch information
Showing
2 changed files
with
34 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
core/commonMain/src/kotlinx/serialization/internal/NothingSerialDescriptor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright 2017-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
|
||
@file:OptIn(ExperimentalSerializationApi::class) | ||
|
||
package kotlinx.serialization.internal | ||
|
||
import kotlinx.serialization.ExperimentalSerializationApi | ||
import kotlinx.serialization.descriptors.SerialDescriptor | ||
import kotlinx.serialization.descriptors.SerialKind | ||
import kotlinx.serialization.descriptors.StructureKind | ||
|
||
internal object NothingSerialDescriptor : SerialDescriptor { | ||
public override val kind: SerialKind = StructureKind.OBJECT | ||
|
||
public override val serialName: String = "kotlin.Nothing" | ||
|
||
override val elementsCount: Int get() = 0 | ||
override fun getElementName(index: Int): String = error() | ||
override fun getElementIndex(name: String): Int = error() | ||
override fun isElementOptional(index: Int): Boolean = error() | ||
override fun getElementDescriptor(index: Int): SerialDescriptor = error() | ||
override fun getElementAnnotations(index: Int): List<Annotation> = error() | ||
override fun toString(): String = "NothingSerialDescriptor" | ||
override fun equals(other: Any?): Boolean { | ||
return this === other | ||
} | ||
|
||
override fun hashCode(): Int = serialName.hashCode() + 31 * kind.hashCode() | ||
private fun error(): Nothing = | ||
throw IllegalStateException("Descriptor for type `kotlin.Nothing` does not have elements") | ||
} |