From 936ed3fff9fff9b852b08e3ac3446fb14d38b1f9 Mon Sep 17 00:00:00 2001 From: Him188 Date: Tue, 24 Mar 2020 14:44:07 +0800 Subject: [PATCH] Fix compilation error --- .../kotlin/net.mamoe.mirai/event/select.kt | 29 ++++-- .../event/subscribeMessages.kt | 98 +------------------ 2 files changed, 23 insertions(+), 104 deletions(-) diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/select.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/select.kt index 2fb90a21a..a556fdb3f 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/select.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/select.kt @@ -386,12 +386,15 @@ internal suspend inline fun , R> T.selectMessage val defaultListeners: MutableList> = mutableListOf() if (isUnit) { + // https://youtrack.jetbrains.com/issue/KT-37716 + val outside = { filter: T.(String) -> Boolean, listener: MessageListener -> + listeners += filter to listener + } object : MessageSelectBuilderUnit( this@selectMessagesImpl, SELECT_MESSAGE_STUB, - { filter: T.(String) -> Boolean, listener: MessageListener -> - listeners += filter to listener - }) { + outside + ) { override fun obtainCurrentCoroutineScope(): CoroutineScope = this@withTimeoutOrCoroutineScope override fun obtainCurrentDeferred(): CompletableDeferred? = deferred override fun default(onEvent: MessageListener) { @@ -399,12 +402,15 @@ internal suspend inline fun , R> T.selectMessage } } } else { + // https://youtrack.jetbrains.com/issue/KT-37716 + val outside = { filter: T.(String) -> Boolean, listener: MessageListener -> + listeners += filter to listener + } object : MessageSelectBuilder( this@selectMessagesImpl, SELECT_MESSAGE_STUB, - { filter: T.(String) -> Boolean, listener: MessageListener -> - listeners += filter to listener - }) { + outside + ) { override fun obtainCurrentCoroutineScope(): CoroutineScope = this@withTimeoutOrCoroutineScope override fun obtainCurrentDeferred(): CompletableDeferred? = deferred override fun default(onEvent: MessageListener) { @@ -414,7 +420,7 @@ internal suspend inline fun , R> T.selectMessage }.apply(selectBuilder) // we don't have any way to reduce duplication yet, - // until local functions is supported in inline functions + // until local functions are supported in inline functions @Suppress("DuplicatedCode") subscribeAlways { event -> if (!this.isContextIdenticalWith(this@selectMessagesImpl)) @@ -470,12 +476,15 @@ internal suspend inline fun > T.whileSelectMessa val listeners: MutableList Boolean, MessageListener>> = mutableListOf() val defaltListeners: MutableList> = mutableListOf() + // https://youtrack.jetbrains.com/issue/KT-37716 + val outside = { filter: T.(String) -> Boolean, listener: MessageListener -> + listeners += filter to listener + } object : MessageSelectBuilder( this@whileSelectMessagesImpl, SELECT_MESSAGE_STUB, - { filter: T.(String) -> Boolean, listener: MessageListener -> - listeners += filter to listener - }) { + outside + ) { override fun obtainCurrentCoroutineScope(): CoroutineScope = this@withTimeoutOrCoroutineScope override fun obtainCurrentDeferred(): CompletableDeferred? = deferred override fun default(onEvent: MessageListener) { diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/subscribeMessages.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/subscribeMessages.kt index c143eea8d..40404eb14 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/subscribeMessages.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/subscribeMessages.kt @@ -33,7 +33,6 @@ import kotlin.coroutines.CoroutineContext import kotlin.coroutines.EmptyCoroutineContext import kotlin.js.JsName import kotlin.jvm.JvmName -import kotlin.jvm.JvmSynthetic typealias MessagePacketSubscribersBuilder = MessageSubscribersBuilder, Listener>, Unit, Unit> @@ -260,7 +259,6 @@ typealias MessageListener = @MessageDsl suspend T.(String) -> R * @param Ret 每个 DSL 函数创建监听器之后的返回值 * * @see subscribeFriendMessages - * @sample demo.subscribe.messageDSL */ @Suppress("unused", "DSL_SCOPE_VIOLATION_WARNING") @MessageDsl @@ -277,7 +275,7 @@ open class MessageSubscribersBuilder, out Ret, R : RR, R /** * 监听的条件 */ - open inner class ListeningFilter @Deprecated( + open inner class ListeningFilter @Deprecated( // keep it for development warning "use newListeningFilter instead", ReplaceWith("newListeningFilter(filter)"), level = DeprecationLevel.ERROR @@ -314,93 +312,42 @@ open class MessageSubscribersBuilder, out Ret, R : RR, R fun not(): ListeningFilter = newListeningFilter { !filter.invoke(this, it) } - - @Deprecated("for binary compatibility", level = DeprecationLevel.HIDDEN) - internal open infix fun reply(toReply: String): Ret { - return content(filter) { reply(toReply);this@MessageSubscribersBuilder.stub } - } - - @Deprecated("for binary compatibility", level = DeprecationLevel.HIDDEN) - internal open infix fun reply(message: Message): Ret { - return content(filter) { reply(message);this@MessageSubscribersBuilder.stub } - } - - @Deprecated("for binary compatibility", level = DeprecationLevel.HIDDEN) - internal open infix fun reply(replier: (@MessageDsl suspend M.(String) -> Any?)): Ret { - return content(filter) { - this@MessageSubscribersBuilder.executeAndReply(this, replier) - } - } - - @Deprecated("for binary compatibility", level = DeprecationLevel.HIDDEN) - internal open infix fun quoteReply(toReply: String): Ret { - return content(filter) { quoteReply(toReply);this@MessageSubscribersBuilder.stub } - } - - @Deprecated("for binary compatibility", level = DeprecationLevel.HIDDEN) - internal open infix fun quoteReply(message: Message): Ret { - return content(filter) { quoteReply(message);this@MessageSubscribersBuilder.stub } - } - - @Deprecated("for binary compatibility", level = DeprecationLevel.HIDDEN) - internal open infix fun quoteReply(replier: (@MessageDsl suspend M.(String) -> Any?)): Ret { - return content(filter) { - @Suppress("DSL_SCOPE_VIOLATION_WARNING") - this@MessageSubscribersBuilder.executeAndQuoteReply(this, replier) - } - } - - @JvmSynthetic - @Deprecated("for binary compatibility", level = DeprecationLevel.HIDDEN) - @JvmName("invoke") - internal fun invoke0(onEvent: MessageListener): Listener<*> { - return content(filter, onEvent) as Listener<*> - } - /** * 启动事件监听. */ - @JvmName("invoke1") // do not inline due to kotlin (1.3.61) bug: java.lang.IllegalAccessError operator fun invoke(onEvent: MessageListener): Ret { return content(filter, onEvent) } } - @Suppress("EXTENSION_SHADOWED_BY_MEMBER") // binary compatibility @SinceMirai("0.29.0") open infix fun ListeningFilter.reply(toReply: String): Ret { return content(filter) { reply(toReply);this@MessageSubscribersBuilder.stub } } - @Suppress("EXTENSION_SHADOWED_BY_MEMBER") // binary compatibility @SinceMirai("0.29.0") open infix fun ListeningFilter.reply(message: Message): Ret { return content(filter) { reply(message);this@MessageSubscribersBuilder.stub } } - @Suppress("EXTENSION_SHADOWED_BY_MEMBER") // binary compatibility @SinceMirai("0.29.0") open infix fun ListeningFilter.reply(replier: (@MessageDsl suspend M.(String) -> Any?)): Ret { return content(filter) { - @Suppress("DSL_SCOPE_VIOLATION_WARNING") this@MessageSubscribersBuilder.executeAndReply(this, replier) } } - @Suppress("EXTENSION_SHADOWED_BY_MEMBER") // binary compatibility @SinceMirai("0.29.0") open infix fun ListeningFilter.quoteReply(toReply: String): Ret { return content(filter) { quoteReply(toReply);this@MessageSubscribersBuilder.stub } } - @Suppress("EXTENSION_SHADOWED_BY_MEMBER") // binary compatibility @SinceMirai("0.29.0") open infix fun ListeningFilter.quoteReply(message: Message): Ret { return content(filter) { quoteReply(message);this@MessageSubscribersBuilder.stub } } - @Suppress("EXTENSION_SHADOWED_BY_MEMBER") // binary compatibility @SinceMirai("0.29.0") open infix fun ListeningFilter.quoteReply(replier: (@MessageDsl suspend M.(String) -> Any?)): Ret { return content(filter) { @@ -440,7 +387,7 @@ open class MessageSubscribersBuilder, out Ret, R : RR, R @JvmName("case1") @JsName("case1") @SinceMirai("0.29.0") - @Suppress("INVALID_CHARACTERS", "NAME_CONTAINS_ILLEGAL_CHARS") + @Suppress("INVALID_CHARACTERS", "NAME_CONTAINS_ILLEGAL_CHARS", "FunctionName") infix fun String.`->`(block: MessageListener): Ret { return case(this, onEvent = block) } @@ -739,7 +686,7 @@ open class MessageSubscribersBuilder, out Ret, R : RR, R @MessageDsl @SinceMirai("0.30.0") inline fun has(noinline onEvent: @MessageDsl suspend M.(N) -> R): Ret = - content({ message.any { it is N } }, { onEvent.invoke(this, message.first()) }) + content({ message.any { it is N } }, { onEvent.invoke(this, message.first()) }) /** * 如果 [mapper] 返回值非空, 就执行 [onEvent] @@ -973,41 +920,4 @@ open class MessageSubscribersBuilder, out Ret, R : RR, R @Retention(AnnotationRetention.SOURCE) @Target(AnnotationTarget.FUNCTION, AnnotationTarget.CLASS, AnnotationTarget.TYPE) @DslMarker -annotation class MessageDsl - - -@Deprecated("for binary compatibility", level = DeprecationLevel.HIDDEN) -fun CoroutineScope.subscribeMessages( - coroutineContext: CoroutineContext = EmptyCoroutineContext, - listeners: MessagePacketSubscribersBuilder.() -> R -): R = subscribeMessages(coroutineContext, listeners = listeners) - -@Deprecated("for binary compatibility", level = DeprecationLevel.HIDDEN) -fun CoroutineScope.subscribeGroupMessages( - coroutineContext: CoroutineContext = EmptyCoroutineContext, - listeners: GroupMessageSubscribersBuilder.() -> R -): R = subscribeGroupMessages(coroutineContext, listeners = listeners) - -@Deprecated("for binary compatibility", level = DeprecationLevel.HIDDEN) -fun CoroutineScope.subscribeFriendMessages( - coroutineContext: CoroutineContext = EmptyCoroutineContext, - listeners: FriendMessageSubscribersBuilder.() -> R -): R = subscribeFriendMessages(coroutineContext, listeners = listeners) - -@Deprecated("for binary compatibility", level = DeprecationLevel.HIDDEN) -fun Bot.subscribeMessages( - coroutineContext: CoroutineContext = EmptyCoroutineContext, - listeners: MessagePacketSubscribersBuilder.() -> R -): R = subscribeMessages(coroutineContext, listeners = listeners) - -@Deprecated("for binary compatibility", level = DeprecationLevel.HIDDEN) -fun Bot.subscribeGroupMessages( - coroutineContext: CoroutineContext = EmptyCoroutineContext, - listeners: GroupMessageSubscribersBuilder.() -> R -): R = subscribeGroupMessages(coroutineContext, listeners = listeners) - -@Deprecated("for binary compatibility", level = DeprecationLevel.HIDDEN) -fun Bot.subscribeFriendMessages( - coroutineContext: CoroutineContext = EmptyCoroutineContext, - listeners: FriendMessageSubscribersBuilder.() -> R -): R = subscribeFriendMessages(coroutineContext, listeners = listeners) +annotation class MessageDsl \ No newline at end of file