Skip to content

Commit

Permalink
Fix misuse of reified type parameters (#981)
Browse files Browse the repository at this point in the history
KT-52469 [1] issues warnings for Kord.getGlobalApplicationCommandOf,
Kord.getGlobalApplicationCommandOfOrNull and VoiceState.getChannelOrNull
since Kotlin 2.1.0-dev-7621.

[1] https://youtrack.jetbrains.com/issue/KT-52469
  • Loading branch information
lukellmann authored Sep 21, 2024
1 parent 12f3249 commit 59630f2
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 3 deletions.
4 changes: 2 additions & 2 deletions core/api/core.api
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ public final class dev/kord/core/Kord : kotlinx/coroutines/CoroutineScope {
public final fun getEvents ()Lkotlinx/coroutines/flow/SharedFlow;
public final fun getGateway ()Ldev/kord/core/gateway/MasterGateway;
public final fun getGlobalApplicationCommand (Ldev/kord/common/entity/Snowflake;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public final fun getGlobalApplicationCommandOf (Ldev/kord/common/entity/Snowflake;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public final fun getGlobalApplicationCommandOfOrNull (Ldev/kord/common/entity/Snowflake;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public final synthetic fun getGlobalApplicationCommandOf (Ldev/kord/common/entity/Snowflake;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public final synthetic fun getGlobalApplicationCommandOfOrNull (Ldev/kord/common/entity/Snowflake;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public final fun getGlobalApplicationCommandOrNull (Ldev/kord/common/entity/Snowflake;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public final fun getGlobalApplicationCommands (Ljava/lang/Boolean;)Lkotlinx/coroutines/flow/Flow;
public static synthetic fun getGlobalApplicationCommands$default (Ldev/kord/core/Kord;Ljava/lang/Boolean;ILjava/lang/Object;)Lkotlinx/coroutines/flow/Flow;
Expand Down
2 changes: 2 additions & 0 deletions core/api/core.klib.api
Original file line number Diff line number Diff line change
Expand Up @@ -11732,6 +11732,8 @@ final class dev.kord.core/Kord : kotlinx.coroutines/CoroutineScope { // dev.kord
final suspend fun getWebhookWithTokenOrNull(dev.kord.common.entity/Snowflake, kotlin/String, dev.kord.core.supplier/EntitySupplyStrategy<*> = ...): dev.kord.core.entity/Webhook? // dev.kord.core/Kord.getWebhookWithTokenOrNull|getWebhookWithTokenOrNull(dev.kord.common.entity.Snowflake;kotlin.String;dev.kord.core.supplier.EntitySupplyStrategy<*>){}[0]
final suspend fun logout() // dev.kord.core/Kord.logout|logout(){}[0]
final suspend fun shutdown() // dev.kord.core/Kord.shutdown|shutdown(){}[0]
final suspend inline fun <#A1: reified dev.kord.core.entity.application/GlobalApplicationCommand> getGlobalApplicationCommandOf(dev.kord.common.entity/Snowflake): #A1 // dev.kord.core/Kord.getGlobalApplicationCommandOf|getGlobalApplicationCommandOf(dev.kord.common.entity.Snowflake){0§<dev.kord.core.entity.application.GlobalApplicationCommand>}[0]
final suspend inline fun <#A1: reified dev.kord.core.entity.application/GlobalApplicationCommand> getGlobalApplicationCommandOfOrNull(dev.kord.common.entity/Snowflake): #A1? // dev.kord.core/Kord.getGlobalApplicationCommandOfOrNull|getGlobalApplicationCommandOfOrNull(dev.kord.common.entity.Snowflake){0§<dev.kord.core.entity.application.GlobalApplicationCommand>}[0]
final suspend inline fun <#A1: reified dev.kord.core.entity.application/GuildApplicationCommand> getGuildApplicationCommandOf(dev.kord.common.entity/Snowflake, dev.kord.common.entity/Snowflake): #A1 // dev.kord.core/Kord.getGuildApplicationCommandOf|getGuildApplicationCommandOf(dev.kord.common.entity.Snowflake;dev.kord.common.entity.Snowflake){0§<dev.kord.core.entity.application.GuildApplicationCommand>}[0]
final suspend inline fun <#A1: reified dev.kord.core.entity.application/GuildApplicationCommand> getGuildApplicationCommandOfOrNull(dev.kord.common.entity/Snowflake, dev.kord.common.entity/Snowflake): #A1? // dev.kord.core/Kord.getGuildApplicationCommandOfOrNull|getGuildApplicationCommandOfOrNull(dev.kord.common.entity.Snowflake;dev.kord.common.entity.Snowflake){0§<dev.kord.core.entity.application.GuildApplicationCommand>}[0]
final suspend inline fun <#A1: reified dev.kord.core.entity.channel/Channel> getChannelOf(dev.kord.common.entity/Snowflake, dev.kord.core.supplier/EntitySupplyStrategy<*> = ...): #A1? // dev.kord.core/Kord.getChannelOf|getChannelOf(dev.kord.common.entity.Snowflake;dev.kord.core.supplier.EntitySupplyStrategy<*>){0§<dev.kord.core.entity.channel.Channel>}[0]
Expand Down
31 changes: 31 additions & 0 deletions core/src/commonMain/kotlin/Kord.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import kotlinx.coroutines.flow.*
import kotlin.contracts.InvocationKind
import kotlin.contracts.contract
import kotlin.coroutines.CoroutineContext
import kotlin.jvm.JvmName
import kotlinx.coroutines.channels.Channel as CoroutineChannel

@Deprecated("Use your own logger instead. This declaration will be removed in 0.16.0.", level = DeprecationLevel.HIDDEN)
Expand Down Expand Up @@ -501,11 +502,41 @@ public class Kord(
}


@JvmName("getGlobalApplicationCommandOfJvmInlineReplacement")
public suspend inline fun <reified T : GlobalApplicationCommand> getGlobalApplicationCommandOf(
commandId: Snowflake,
): T = defaultSupplier.getGlobalApplicationCommandOf(resources.applicationId, commandId)


@JvmName("getGlobalApplicationCommandOfOrNullJvmInlineReplacement")
public suspend inline fun <reified T : GlobalApplicationCommand> getGlobalApplicationCommandOfOrNull(
commandId: Snowflake,
): T? = defaultSupplier.getGlobalApplicationCommandOfOrNull(resources.applicationId, commandId)


@Suppress("TYPE_INTERSECTION_AS_REIFIED_WARNING")
@Deprecated(
"This function has bad semantics: the type argument for T is effectively ignored. It no longer compiles " +
"without a 'TYPE_INTERSECTION_AS_REIFIED_WARNING' since Kotlin 2.1.0 " +
"(https://youtrack.jetbrains.com/issue/KT-52469). The replacement function has a proper bounded reified " +
"type parameter that is actually used. This declaration is kept for binary compatibility, it will be " +
"removed in 0.18.0. The replacement function should then be migrated away from using @JvmName.",
level = DeprecationLevel.HIDDEN,
)
public suspend fun <T> getGlobalApplicationCommandOf(commandId: Snowflake): T {
return defaultSupplier.getGlobalApplicationCommandOf(resources.applicationId, commandId)
}


@Suppress("TYPE_INTERSECTION_AS_REIFIED_WARNING")
@Deprecated(
"This function has bad semantics: the type argument for T is effectively ignored. It no longer compiles " +
"without a 'TYPE_INTERSECTION_AS_REIFIED_WARNING' since Kotlin 2.1.0 " +
"(https://youtrack.jetbrains.com/issue/KT-52469). The replacement function has a proper bounded reified " +
"type parameter that is actually used. This declaration is kept for binary compatibility, it will be " +
"removed in 0.18.0. The replacement function should then be migrated away from using @JvmName.",
level = DeprecationLevel.HIDDEN,
)
public suspend fun <T> getGlobalApplicationCommandOfOrNull(commandId: Snowflake): T? {
return defaultSupplier.getGlobalApplicationCommandOfOrNull(resources.applicationId, commandId)
}
Expand Down
3 changes: 2 additions & 1 deletion core/src/commonMain/kotlin/entity/VoiceState.kt
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ public class VoiceState(
*
* @throws [RequestException] if anything went wrong during the request.
*/
public suspend fun getChannelOrNull(): BaseVoiceChannelBehavior? = channelId?.let { supplier.getChannelOfOrNull(it) }
public suspend fun getChannelOrNull(): BaseVoiceChannelBehavior? =
channelId?.let { supplier.getChannelOrNull(it) as? BaseVoiceChannelBehavior }


/**
Expand Down

0 comments on commit 59630f2

Please sign in to comment.