Skip to content

Commit

Permalink
Update Kotlin to 2.1.0-Beta1
Browse files Browse the repository at this point in the history
KT-31799 [1] is fixed with Kotlin 2.1.0-Beta1, so most @JsName
annotations are no longer necessary.

KSP 2.0.20-1.0.24 works with Kotlin 2.1.0-Beta1, so the locally built
KSP is no longer necessary.

[1] https://youtrack.jetbrains.com/issue/KT-31799
  • Loading branch information
lukellmann committed Sep 17, 2024
1 parent 82bbcca commit 530920d
Show file tree
Hide file tree
Showing 67 changed files with 22 additions and 312 deletions.
2 changes: 0 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ plugins {

repositories {
mavenCentral()
maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/bootstrap")
mavenLocal()
}

group = Library.group
Expand Down
2 changes: 0 additions & 2 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ plugins {

repositories {
mavenCentral()
maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/bootstrap")
mavenLocal()
}

kotlin {
Expand Down
2 changes: 0 additions & 2 deletions buildSrc/src/main/kotlin/kord-internal-module.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ plugins {

repositories {
mavenCentral()
maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/bootstrap")
mavenLocal()
}

kotlin {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ plugins {

repositories {
mavenCentral()
maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/bootstrap")
mavenLocal()
}

@OptIn(ExperimentalKotlinGradlePluginApi::class)
Expand Down
2 changes: 0 additions & 2 deletions buildSrc/src/main/kotlin/kord-module.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ plugins {

repositories {
mavenCentral()
maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/bootstrap")
mavenLocal()
}

dependencies {
Expand Down
2 changes: 0 additions & 2 deletions buildSrc/src/main/kotlin/kord-multiplatform-module.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ plugins {

repositories {
mavenCentral()
maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/bootstrap")
mavenLocal()
}

dependencies {
Expand Down
4 changes: 0 additions & 4 deletions common/src/commonMain/kotlin/entity/optional/Optional.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import kotlinx.serialization.SerializationException
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
import kotlin.js.JsName
import kotlin.jvm.JvmName

/**
Expand Down Expand Up @@ -145,7 +144,6 @@ public sealed class Optional<out T> {
* Returns an [Optional] that is either [value] on a non-null [value], or [Null] on `null`.
*/
@JvmName("invokeNullable")
@JsName("invokeNullable")
public operator fun <T : Any> invoke(value: T?): Optional<T?> = when (value) {
null -> Null()
else -> Value(value)
Expand Down Expand Up @@ -265,7 +263,6 @@ public inline fun <E : Any, T : Any> Optional<E>.flatMap(mapper: (E) -> Optional

@Suppress("UNCHECKED_CAST")
@JvmName("mapNullableOptional")
@JsName("mapNullableOptional")
public inline fun <E : Any, T : Any> Optional<E?>.map(mapper: (E) -> T): Optional<T?> = when (this) {
is Missing, is Null<*> -> this as Optional<T>
is Value -> Value(mapper(value!!))
Expand Down Expand Up @@ -299,7 +296,6 @@ public inline fun <E : Any> Optional<E>.mapSnowflake(mapper: (E) -> Snowflake):
}

@JvmName("mapNullableSnowflake")
@JsName("mapNullableSnowflake")
public inline fun <E : Any> Optional<E?>.mapSnowflake(mapper: (E) -> Snowflake): OptionalSnowflake = when (this) {
is Missing, is Null<*> -> OptionalSnowflake.Missing
is Value -> OptionalSnowflake.Value(mapper(value!!))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package dev.kord.common.entity.optional.delegate

import dev.kord.common.entity.optional.Optional
import kotlin.js.JsName
import kotlin.jvm.JvmName
import kotlin.properties.ReadWriteProperty
import kotlin.reflect.KMutableProperty0
Expand Down Expand Up @@ -44,7 +43,6 @@ public fun <V : Any> KMutableProperty0<Optional<List<V>>>.delegateList(): ReadWr
}

@JvmName("provideNullableDelegate")
@JsName("provideNullableDelegate")
public fun <V : Any> KMutableProperty0<Optional<V?>>.delegate(): ReadWriteProperty<Any?, V?> =
object : ReadWriteProperty<Any?, V?> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@ package dev.kord.common.entity.optional.delegate
import dev.kord.common.entity.optional.OptionalInt
import dev.kord.common.entity.optional.optionalInt
import dev.kord.common.entity.optional.value
import kotlin.js.JsName
import kotlin.jvm.JvmName
import kotlin.properties.ReadWriteProperty
import kotlin.reflect.KMutableProperty0
import kotlin.reflect.KProperty

@JsName("intDelegate")
public fun KMutableProperty0<OptionalInt>.delegate(): ReadWriteProperty<Any?, Int?> = object : ReadWriteProperty<Any?, Int?> {

override fun getValue(thisRef: Any?, property: KProperty<*>): Int? {
Expand Down
10 changes: 0 additions & 10 deletions common/src/commonTest/kotlin/BitSetTests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@ import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.JsonPrimitive
import kotlinx.serialization.json.encodeToJsonElement
import kotlin.js.JsName
import kotlin.random.Random
import kotlin.random.nextLong
import kotlin.test.*

class BitSetTests {
@Test
@JsName("test1")
fun `a contains b and c`() {
val a = DiscordBitSet(0b111)
val b = DiscordBitSet(0b101)
Expand All @@ -21,7 +19,6 @@ class BitSetTests {
}

@Test
@JsName("test2")
fun `a and b are equal and have the same hashCode`() {
val a = DiscordBitSet(0b111, 0)
val b = DiscordBitSet(0b111)
Expand All @@ -30,15 +27,13 @@ class BitSetTests {
}

@Test
@JsName("test3")
fun `a does not equal b`() {
val a = DiscordBitSet(0b111, 0)
val b = DiscordBitSet(0b111, 0b1)
assertNotEquals(a, b)
}

@Test
@JsName("test4")
fun `get bits`() {
val a = DiscordBitSet(0b101, 0)
assertTrue(a[0])
Expand All @@ -52,7 +47,6 @@ class BitSetTests {
}

@Test
@JsName("test5")
fun `set bits`() {
val a = EmptyBitSet()
for (i in 0..64) a[i] = true
Expand All @@ -68,14 +62,12 @@ class BitSetTests {
}

@Test
@JsName("test6")
fun `get a bit out of range`() {
val a = DiscordBitSet(0b101, 0)
assertFalse(a[10000])
}

@Test
@JsName("test7")
fun `add and remove a bit`() {
val a = DiscordBitSet(0b101, 0)
a.add(DiscordBitSet(0b111))
Expand All @@ -85,15 +77,13 @@ class BitSetTests {
}

@Test
@JsName("test8")
fun `remove a bit`() {
val a = DiscordBitSet(0b101, 0)
a.remove(DiscordBitSet(0b111))
assertEquals("0", a.value)
}

@Test
@JsName("test9")
fun `binary works`() {
assertEquals("0", DiscordBitSet().binary)
assertEquals("0", DiscordBitSet(0).binary)
Expand Down
4 changes: 0 additions & 4 deletions common/src/commonTest/kotlin/ColorTests.kt
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
package dev.kord.common

import kotlin.js.JsName
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertFailsWith

class ColorTests {
@Test
@JsName("test1")
fun `Color throws if invalid rgb value is provided`() {
assertFailsWith<IllegalArgumentException> { Color(256, 256, 300) }
}

@Test
@JsName("test2")
fun `Color provides a correct value`() {
val red = Color(0xFF0000)
assertEquals(255, red.red)
Expand All @@ -28,7 +25,6 @@ class ColorTests {
}

@Test
@JsName("test3")
fun `Color implementation should drop alpha values if given`() {
val color = Color(0x1E1F2E3D)
assertEquals(0x1F2E3D, color.rgb)
Expand Down
3 changes: 0 additions & 3 deletions common/src/commonTest/kotlin/LocaleTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package dev.kord.common

import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import kotlin.js.JsName
import kotlin.test.Test
import kotlin.test.assertEquals

Expand Down Expand Up @@ -51,15 +50,13 @@ class LocaleTest {


@Test
@JsName("test1")
fun `all documented Locales can be deserialized`() {
all.forEach { (string, locale) ->
assertEquals(expected = locale, actual = Json.decodeFromString("\"$string\""))
}
}

@Test
@JsName("test2")
fun `all documented Locales can be serialized`() {
all.forEach { (string, locale) ->
assertEquals(expected = "\"$string\"", actual = Json.encodeToString(locale))
Expand Down
13 changes: 0 additions & 13 deletions common/src/commonTest/kotlin/entity/SnowflakeTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,62 +2,53 @@ package dev.kord.common.entity

import kotlinx.datetime.Clock
import kotlinx.datetime.Instant
import kotlin.js.JsName
import kotlin.test.*
import kotlin.time.Duration.Companion.milliseconds
import kotlin.time.Duration.Companion.nanoseconds

class SnowflakeTest {

@Test
@JsName("test1")
fun `min Snowflake's timestamp is equal to discordEpoch`() {
assertEquals(Snowflake.discordEpoch, Snowflake.min.timestamp)
}

@Test
@JsName("test2")
fun `max Snowflake's timestamp is equal to endOfTime`() {
assertEquals(Snowflake.endOfTime, Snowflake.max.timestamp)
}

@Test
@JsName("test3")
fun `Snowflake created from ULong MIN_VALUE has timestamp equal to discordEpoch`() {
val snowflake = Snowflake(ULong.MIN_VALUE)
assertEquals(Snowflake.discordEpoch, snowflake.timestamp)
}

@Test
@JsName("test4")
fun `Snowflake created from ULong MAX_VALUE has timestamp equal to endOfTime`() {
val snowflake = Snowflake(ULong.MAX_VALUE)
assertEquals(Snowflake.endOfTime, snowflake.timestamp)
}

@Test
@JsName("test5")
fun `Snowflake created from Long MIN_VALUE has timestamp equal to discordEpoch`() {
val snowflake = Snowflake(Long.MIN_VALUE)
assertEquals(Snowflake.discordEpoch, snowflake.timestamp)
}

@Test
@JsName("test6")
fun `Snowflake created from instant far in the past has timestamp equal to discordEpoch`() {
val snowflake = Snowflake(Instant.DISTANT_PAST)
assertEquals(Snowflake.discordEpoch, snowflake.timestamp)
}

@Test
@JsName("test7")
fun `Snowflake created from instant far in the future has timestamp equal to endOfTime`() {
val snowflake = Snowflake(Instant.DISTANT_FUTURE)
assertEquals(Snowflake.endOfTime, snowflake.timestamp)
}

@Test
@JsName("test8")
fun `Snowflake's timestamp calculates an Instant close to the Instant the Snowflake was created from`() {
val instant = Clock.System.now()
val snowflake = Snowflake(instant)
Expand All @@ -70,19 +61,16 @@ class SnowflakeTest {
}

@Test
@JsName("test9")
fun `min Snowflake's timeMark has passed`() {
assertTrue(Snowflake.min.timeMark.hasPassedNow())
}

@Test
@JsName("test10")
fun `max Snowflake's timeMark has not passed`() {
assertFalse(Snowflake.max.timeMark.hasPassedNow())
}

@Test
@JsName("test11")
fun `Snowflake can be destructured`() {
val snowflake = Snowflake(0b110010110111_10111_01101_101100111101_u)
val (timestamp, worker, process, increment) = snowflake
Expand All @@ -99,7 +87,6 @@ class SnowflakeTest {
}

@Test
@JsName("test12")
fun `Snowflakes are compared correctly`() {
// timestamp worker process increment
// vvv vvv vvv vvv
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ package dev.kord.common.entity.optional

import kotlinx.serialization.Serializable
import kotlinx.serialization.SerializationException
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.json.Json
import kotlin.js.JsName
import kotlin.test.Test
import kotlin.test.assertFailsWith
import kotlin.test.assertIs
Expand All @@ -16,7 +14,6 @@ internal class OptionalBooleanTest {
private class EmptyOptionalEntity(val value: OptionalBoolean = OptionalBoolean.Missing)

@Test
@JsName("test1")
fun `deserializing nothing in optional assigns Missing`(){
//language=json
val json = """{}"""
Expand All @@ -30,7 +27,6 @@ internal class OptionalBooleanTest {
private class NullOptionalEntity(@Suppress("unused") val value: OptionalBoolean = OptionalBoolean.Missing)

@Test
@JsName("test2")
fun `deserializing null in optional throws SerializationException`(){
//language=json
val json = """{ "value":null }"""
Expand All @@ -44,7 +40,6 @@ internal class OptionalBooleanTest {
private class ValueOptionalEntity(val value: OptionalBoolean = OptionalBoolean.Missing)

@Test
@JsName("test3")
fun `deserializing value in optional assigns Value`(){
//language=json
val json = """{ "value":true }"""
Expand Down
Loading

0 comments on commit 530920d

Please sign in to comment.