From 3b14d70cc5df3e4581adef758785957a6d805853 Mon Sep 17 00:00:00 2001 From: Him188 Date: Fri, 30 Oct 2020 09:48:12 +0800 Subject: [PATCH] Fix command receiverParameter, #215 --- .../mirai/console/internal/command/CommandReflector.kt | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/command/CommandReflector.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/command/CommandReflector.kt index c3cde4f47..116d5c068 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/command/CommandReflector.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/command/CommandReflector.kt @@ -256,6 +256,15 @@ internal class CommandReflector( if (instanceParameter != null) { args[instanceParameter] = command } + + val receiverParameter = function.extensionReceiverParameter + if (receiverParameter != null) { + check(receiverParameter.type.classifierAsKClass().isInstance(call.caller)) { + "Bad command call resolved. " + + "Function expects receiver parameter ${receiverParameter.type} whereas actual is ${call.caller::class}." + } + args[receiverParameter] = call.caller + } function.callSuspendBy(args) } }.toList()