From 7e55c6f3422af3baafcd5e6379bd52d0f78f9465 Mon Sep 17 00:00:00 2001 From: Him188 Date: Mon, 25 Nov 2019 14:15:30 +0800 Subject: [PATCH] Simplify code --- .../network/protocol/tim/packet/login/LoginResult.kt | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/login/LoginResult.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/login/LoginResult.kt index 2377e103e..9a93dca29 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/login/LoginResult.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/login/LoginResult.kt @@ -90,10 +90,7 @@ inline fun LoginResult.requireSuccess(lazyMessage: (LoginResult) -> String) { * 检查 [this] 为 [LoginResult.SUCCESS]. * 失败则 [error] */ -fun LoginResult.requireSuccess() { - if (requireSuccessOrNull() === null) - error("Login failed: $this") -} +fun LoginResult.requireSuccess() = requireSuccess { "Login failed: $this" } /** * 检查 [this] 为 [LoginResult.SUCCESS]. @@ -101,10 +98,7 @@ fun LoginResult.requireSuccess() { * * @return 成功时 [Unit], 失败时 `null` */ -fun LoginResult.requireSuccessOrNull(): Unit? { - return if (this == SUCCESS) Unit else null -} - +fun LoginResult.requireSuccessOrNull(): Unit? = if (this == SUCCESS) Unit else null /** * 检查 [this] 为 [LoginResult.SUCCESS].