From 3f0d12342180376ca684f911639cb19414eb185c Mon Sep 17 00:00:00 2001 From: Him188 Date: Mon, 26 Oct 2020 08:14:32 +0800 Subject: [PATCH] Check receiver type in init --- .../mirai/console/command/descriptor/CommandDescriptor.kt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/descriptor/CommandDescriptor.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/descriptor/CommandDescriptor.kt index b83e6907a..562cc9b40 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/descriptor/CommandDescriptor.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/descriptor/CommandDescriptor.kt @@ -22,6 +22,7 @@ import net.mamoe.mirai.console.util.ConsoleExperimentalApi import kotlin.reflect.KClass import kotlin.reflect.KFunction import kotlin.reflect.KType +import kotlin.reflect.full.isSubclassOf import kotlin.reflect.full.isSubtypeOf import kotlin.reflect.typeOf @@ -183,9 +184,13 @@ public class CommandReceiverParameter( override val name: String get() = PARAMETER_NAME init { - check(type.classifier is KClass<*>) { + val classifier = type.classifier + require(classifier is KClass<*>) { "CommandReceiverParameter.type.classifier must be KClass." } + require(classifier.isSubclassOf(CommandSender::class)) { + "CommandReceiverParameter.type.classifier must be subclass of CommandSender." + } } public companion object {