Q:

Kotlin - extension property setter for mutable subclass

Assume that I want to have a property for List and then extend this property with setter for MutableList. For example, I want to have a getter for last element in the list, and also a setter if the list is mutable. So I want the following:
val <T> List<T>.myLast
    get() = this.last()

var <T> MutableList<T>.myLast: T
    set(value) {
        this[this.size - 1] = value
    }

But this doesn't compile. Can this be achieved? The closest things I can do:

Declare another property:
val <T> List<T>.myLast
    get() = this.last()

var <T> MutableList<T>.myMutableLast: T
    get() = this.last()
    set(value) {
        this[this.size - 1] = value
    }

I don't like this because I want to have the same name.
Create getter and setter explicitly:
fun<T> List<T>.getMyLast() = this.last()

fun<T> MutableList<T>.setMyLast(value : T) {
    this[this.size - 1] = value
}

I don't like it because it doesn't have property syntax.

A:

Just add a getter to the second property which calls the first one:
val <T> List<T>.myLast
    get() = this.last()

var <T> MutableList<T>.myLast: T
    @JvmName("someName")
    get() = (this as List<T>).myLast
    set(value) {
        this[this.size - 1] = value
    }

In this case you could equally do get() = this.last(), but this way changing the first definition automatically affects the second one.
It'll get resolved like method overloading does, so e.g.
val x: List<String> = mutableListOf("")
val y: MutableList<String> = mutableListOf("")
x.myLast // calls List<T>.myLast.get()
y.myLast // calls MutableList<T>.myLast.get()

