Hi, I was wondering if any one has had an issue w...
# reflect
n
Hi, I was wondering if any one has had an issue where when getting the value of a value class using get on the Kproperty, get returns not null even if the property is actually null. It correctly returns null when directly grabbing the property
OuterClass::valueClass
but not when using the KProperty returned form
OuterClass::class.declaredMemberProperties
Minimum repro in thread🧵
Copy code
import kotlinx.serialization.Serializable
import kotlin.reflect.full.declaredMemberProperties
import kotlin.test.Test

class ValueClassReflectionTest {

    @JvmInline
    @Serializable
    value class SomeValueClass(val value: String)

    @Serializable
    data class OuterClass(
        var valueClass: SomeValueClass? = null,
    )

    @Test
    fun `value class `() {
        val outerClass = OuterClass()

        // works as expected
        assert(OuterClass::valueClass.get(outerClass) == null)

        val nullableMemberProperties = OuterClass::class.declaredMemberProperties.filter {
            it.returnType.isMarkedNullable
        }

        nullableMemberProperties.forEach { memberProperty ->
            // fails
            assert(memberProperty.get(outerClass) == null, { "Property ${memberProperty.name} should be null" })
        }
    }
}
u
It's a bug: KT-67026 NPE on calling toString of nullable inline class property
👍 2