From aebaf605a7170a846e1ef0ff4d37de991ff8bca2 Mon Sep 17 00:00:00 2001 From: Him188 Date: Fri, 17 Jan 2020 16:22:06 +0800 Subject: [PATCH] Fix weakRef --- .../commonMain/kotlin/net.mamoe.mirai/utils/WeakRef.kt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/WeakRef.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/WeakRef.kt index b2c592b8d..d6949e624 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/WeakRef.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/WeakRef.kt @@ -2,6 +2,7 @@ package net.mamoe.mirai.utils +import kotlin.properties.ReadOnlyProperty import kotlin.reflect.KProperty /** @@ -18,7 +19,13 @@ inline class UnsafeWeakRef(private val weakRef: WeakRef) { * val bot: Bot by param.unsafeWeakRef() * ``` */ - operator fun getValue(thisRef: Any?, property: KProperty<*>): T = this.get() + operator fun provideDelegate(thisRef: Any?, property: KProperty<*>): ReadOnlyProperty { + return object : ReadOnlyProperty { + override fun getValue(thisRef: Any?, property: KProperty<*>): T { + return get() + } + } + } } /**