From 16460e582e25fe79dd5a511c0b4281befc6ee9dc Mon Sep 17 00:00:00 2001 From: Michael Rittmeister Date: Sun, 18 Jun 2023 22:01:25 +0200 Subject: [PATCH] Fix runtime error about sealed interfaces --- .../dev/schlaubi/tonbrett/bot/server/WebSocket.kt | 2 +- build.gradle.kts | 2 +- .../kotlin/dev/schlaubi/tonbrett/common/Events.kt | 12 ++++++------ 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/bot/src/main/kotlin/dev/schlaubi/tonbrett/bot/server/WebSocket.kt b/bot/src/main/kotlin/dev/schlaubi/tonbrett/bot/server/WebSocket.kt index ac9ca06..2a49a06 100644 --- a/bot/src/main/kotlin/dev/schlaubi/tonbrett/bot/server/WebSocket.kt +++ b/bot/src/main/kotlin/dev/schlaubi/tonbrett/bot/server/WebSocket.kt @@ -24,7 +24,7 @@ class WebSocketSession( val delegate: DefaultWebSocketServerSession ) : DefaultWebSocketServerSession by delegate { suspend inline fun sendEvent(event: T) { - val updatedEvent = if (event is SoundEvent && useUnicode) { + val updatedEvent = if (event is HasSound && useUnicode) { event.withSound(event.sound.convertForNonJvmPlatforms()) } else { event diff --git a/build.gradle.kts b/build.gradle.kts index d412eef..9f8150a 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -9,7 +9,7 @@ plugins { allprojects { group = "dev.schlaubi.tonbrett" - version = "1.9.9" + version = "1.9.10" repositories { mavenCentral() diff --git a/common/src/commonMain/kotlin/dev/schlaubi/tonbrett/common/Events.kt b/common/src/commonMain/kotlin/dev/schlaubi/tonbrett/common/Events.kt index fff8c8d..ce11fe2 100644 --- a/common/src/commonMain/kotlin/dev/schlaubi/tonbrett/common/Events.kt +++ b/common/src/commonMain/kotlin/dev/schlaubi/tonbrett/common/Events.kt @@ -10,10 +10,10 @@ import kotlinx.serialization.json.JsonClassDiscriminator @Serializable public sealed interface Event -public sealed interface SoundEvent : Event { +public sealed interface HasSound { public val sound: Sound - public fun withSound(sound: Sound): SoundEvent + public fun withSound(sound: Sound): Event } @Serializable @@ -26,8 +26,8 @@ public data class VoiceStateUpdateEvent(val voiceState: User.VoiceState?) : Even @Serializable @SerialName("sound_create") -public data class SoundCreatedEvent(override val sound: Sound) : SoundEvent { - override fun withSound(sound: Sound): SoundEvent = copy(sound = sound) +public data class SoundCreatedEvent(override val sound: Sound) : Event, HasSound { + override fun withSound(sound: Sound): Event = copy(sound = sound) } @Serializable @@ -36,6 +36,6 @@ public data class SoundDeletedEvent(val id: Id) : Event @Serializable @SerialName("sound_update") -public data class SoundUpdatedEvent(override val sound: Sound) : SoundEvent { - override fun withSound(sound: Sound): SoundEvent = copy(sound = sound) +public data class SoundUpdatedEvent(override val sound: Sound) : Event, HasSound { + override fun withSound(sound: Sound): Event = copy(sound = sound) }