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() + } + } + } } /**