<https://pastes.dev/xrBzbrlsTG> I'm having this we...
# reflect
r
https://pastes.dev/xrBzbrlsTG I'm having this weird exception when getting the return type of a
KProperty<*>
in a delegate like such:
Copy code
operator fun <T : GameDataEntry> getValue(
        thisRef: Any?,
        property: KProperty<*>
    ): T {
        @Suppress("UNCHECKED_CAST")
        return requireNotNull(getData(property.returnType.classifier as KClass<T>))
    }
Using Kotlin 2.1.10, is this a bug or am I just doing something wrong? The exception happens even when just attempting to get the
returnType
This works as a workaround:
Copy code
inline fun <reified T : GameDataEntry> GameDataEntryHolder.data() = object : ReadWriteProperty<GameDataEntryHolder, T> {
            override fun getValue(
                thisRef: GameDataEntryHolder,
                property: KProperty<*>
            ): T {
                return requireNotNull(getData(T::class))
            }

            override fun setValue(
                thisRef: GameDataEntryHolder,
                property: KProperty<*>,
                value: T
            ) {
                setData(T::class, value)
            }
        }
c
what is the exception and what is “weird” about it?
r
I sent the exception as a pastebin link since it's pretty long (https://pastes.dev/xrBzbrlsTG)
There's probably some more context needed here that I forgot to provide. The operator funs are virtual members of an interface with a default implementation, with the interface being implemented by
GameContext
and my caller class here being a
GameInstance
with a delegating impl to my interface by the context