Skip to content

Commit

Permalink
Get rid of @ExperimentalUnsignedTypes on our declarations that levera… (
Browse files Browse the repository at this point in the history
#1962)

* Get rid of @ExperimentalUnsignedTypes on our declarations that leverage non-experimental unsigned types
  • Loading branch information
qwwdfsad committed Jun 24, 2022
1 parent 3e8331c commit 605a35f
Show file tree
Hide file tree
Showing 13 changed files with 5 additions and 30 deletions.
3 changes: 1 addition & 2 deletions build.gradle
Expand Up @@ -20,8 +20,7 @@ buildscript {
ext.experimentalsInTestEnabled = ["-progressive", "-opt-in=kotlin.Experimental",
"-opt-in=kotlin.ExperimentalMultiplatform",
"-opt-in=kotlinx.serialization.ExperimentalSerializationApi",
"-opt-in=kotlinx.serialization.InternalSerializationApi",
"-opt-in=kotlin.ExperimentalUnsignedTypes"
"-opt-in=kotlinx.serialization.InternalSerializationApi"
]
ext.koverEnabled = property('kover.enabled') ?: true

Expand Down
Expand Up @@ -194,25 +194,21 @@ public fun <K, V> MapSerializer(
/**
* Returns serializer for [UInt].
*/
@ExperimentalUnsignedTypes
public fun UInt.Companion.serializer(): KSerializer<UInt> = UIntSerializer

/**
* Returns serializer for [ULong].
*/
@ExperimentalUnsignedTypes
public fun ULong.Companion.serializer(): KSerializer<ULong> = ULongSerializer

/**
* Returns serializer for [UByte].
*/
@ExperimentalUnsignedTypes
public fun UByte.Companion.serializer(): KSerializer<UByte> = UByteSerializer

/**
* Returns serializer for [UShort].
*/
@ExperimentalUnsignedTypes
public fun UShort.Companion.serializer(): KSerializer<UShort> = UShortSerializer

/**
Expand Down
Expand Up @@ -10,7 +10,6 @@ import kotlinx.serialization.descriptors.*
import kotlinx.serialization.encoding.*

@PublishedApi
@ExperimentalUnsignedTypes
internal object UIntSerializer : KSerializer<UInt> {
override val descriptor: SerialDescriptor = InlinePrimitiveDescriptor("kotlin.UInt", Int.serializer())

Expand All @@ -24,7 +23,6 @@ internal object UIntSerializer : KSerializer<UInt> {
}

@PublishedApi
@ExperimentalUnsignedTypes
internal object ULongSerializer : KSerializer<ULong> {
override val descriptor: SerialDescriptor = InlinePrimitiveDescriptor("kotlin.ULong", Long.serializer())

Expand All @@ -38,7 +36,6 @@ internal object ULongSerializer : KSerializer<ULong> {
}

@PublishedApi
@ExperimentalUnsignedTypes
internal object UByteSerializer : KSerializer<UByte> {
override val descriptor: SerialDescriptor = InlinePrimitiveDescriptor("kotlin.UByte", Byte.serializer())

Expand All @@ -52,7 +49,6 @@ internal object UByteSerializer : KSerializer<UByte> {
}

@PublishedApi
@ExperimentalUnsignedTypes
internal object UShortSerializer : KSerializer<UShort> {
override val descriptor: SerialDescriptor = InlinePrimitiveDescriptor("kotlin.UShort", Short.serializer())

Expand Down
2 changes: 0 additions & 2 deletions docs/builtin-classes.md
Expand Up @@ -68,8 +68,6 @@ Their natural representation in JSON is used.

<!--- TEST -->

> Experimental unsigned numbers as well as other experimental inline classes are not supported by Kotlin Serialization yet.

### Long numbers

Expand Down
Expand Up @@ -109,7 +109,7 @@ private object JsonLiteralSerializer : KSerializer<JsonLiteral> {
override val descriptor: SerialDescriptor =
PrimitiveSerialDescriptor("kotlinx.serialization.json.JsonLiteral", PrimitiveKind.STRING)

@OptIn(ExperimentalUnsignedTypes::class, ExperimentalSerializationApi::class)
@OptIn(ExperimentalSerializationApi::class)
override fun serialize(encoder: Encoder, value: JsonLiteral) {
verify(encoder)
if (value.isString) {
Expand Down
Expand Up @@ -41,7 +41,6 @@ internal open class Composer(@JvmField internal val sb: JsonStringBuilder) {
fun printQuoted(value: String): Unit = sb.appendQuoted(value)
}

@ExperimentalUnsignedTypes
internal class ComposerForUnsignedNumbers(sb: JsonStringBuilder, private val forceQuoting: Boolean) : Composer(sb) {
override fun print(v: Int) {
if (forceQuoting) printQuoted(v.toUInt().toString()) else print(v.toUInt().toString())
Expand Down
Expand Up @@ -17,7 +17,7 @@ import kotlin.jvm.*
/**
* [JsonDecoder] which reads given JSON from [AbstractJsonLexer] field by field.
*/
@OptIn(ExperimentalSerializationApi::class, ExperimentalUnsignedTypes::class)
@OptIn(ExperimentalSerializationApi::class)
internal open class StreamingJsonDecoder(
final override val json: Json,
private val mode: WriteMode,
Expand Down Expand Up @@ -354,7 +354,6 @@ internal open class StreamingJsonDecoder(
}

@OptIn(ExperimentalSerializationApi::class)
@ExperimentalUnsignedTypes
internal class JsonDecoderForUnsignedTypes(
private val lexer: AbstractJsonLexer,
json: Json
Expand Down
Expand Up @@ -12,7 +12,6 @@ import kotlinx.serialization.json.*
import kotlinx.serialization.modules.*
import kotlin.native.concurrent.*

@OptIn(ExperimentalUnsignedTypes::class)
@SharedImmutable
private val unsignedNumberDescriptors = setOf(
UInt.serializer().descriptor,
Expand All @@ -24,7 +23,7 @@ private val unsignedNumberDescriptors = setOf(
internal val SerialDescriptor.isUnsignedNumber: Boolean
get() = this.isInline && this in unsignedNumberDescriptors

@OptIn(ExperimentalSerializationApi::class, ExperimentalUnsignedTypes::class)
@OptIn(ExperimentalSerializationApi::class)
internal class StreamingJsonEncoder(
private val composer: Composer,
override val json: Json,
Expand Down
Expand Up @@ -161,7 +161,6 @@ private sealed class AbstractJsonTreeDecoder(
return this as? JsonLiteral ?: throw JsonDecodingException(-1, "Unexpected 'null' when $type was expected")
}

@OptIn(ExperimentalUnsignedTypes::class)
override fun decodeTaggedInline(tag: String, inlineDescriptor: SerialDescriptor): Decoder =
if (inlineDescriptor.isUnsignedNumber) JsonDecoderForUnsignedTypes(StringJsonLexer(getPrimitiveValue(tag).content), json)
else super.decodeTaggedInline(tag, inlineDescriptor)
Expand Down
Expand Up @@ -101,7 +101,6 @@ private sealed class AbstractJsonTreeEncoder(
putElement(tag, JsonPrimitive(value.toString()))
}

@OptIn(ExperimentalUnsignedTypes::class)
override fun encodeTaggedInline(tag: String, inlineDescriptor: SerialDescriptor): Encoder =
if (inlineDescriptor.isUnsignedNumber) object : AbstractEncoder() {
override val serializersModule: SerializersModule = json.serializersModule
Expand Down
Expand Up @@ -2,8 +2,6 @@
* Copyright 2017-2022 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/

@file:OptIn(ExperimentalUnsignedTypes::class)

package kotlinx.serialization.features.inline

import kotlinx.serialization.*
Expand Down
Expand Up @@ -3,11 +3,6 @@
*/

@file:Suppress("INLINE_CLASSES_NOT_SUPPORTED", "SERIALIZER_NOT_FOUND")
@file:OptIn(ExperimentalUnsignedTypes::class)

/*
* Copyright 2017-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/

package kotlinx.serialization.features.inline

Expand Down
@@ -1,7 +1,5 @@
@file:Suppress("INLINE_CLASSES_NOT_SUPPORTED", "SERIALIZER_NOT_FOUND")
@file:OptIn(ExperimentalUnsignedTypes::class)
/*
* Copyright 2017-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
* Copyright 2017-2022 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/

package kotlinx.serialization.features.inline
Expand Down

0 comments on commit 605a35f

Please sign in to comment.