Why is a protected var KProperty0 instead of KMutableProperty0?


#1

Given a class like so:

class Foo {
    protected var myFoo: Boolean = true
    private var myFoo2: Boolean = true

    init {
        val x = ::myFoo
        val y = ::myFoo2
    }
}

I’m wondering why the protected version is KProperty0 but the private version is KMutableProperty0?

image


#2

This is a bug: KT-24884.

As a workaround (if it’s applicable in your case), you can try using unbound references instead: the type of Foo::myFoo should be KMutableProperty1<Foo, Boolean>.