How to get the receiver of a method reference?

I have a method reference (represented by the kotlin.reflect.KFunction0 interface). What I would like to do is to get the receiver object of the method reference.

For example:

data class MyClass(val name: String)

val john = MyClass("John")
val methodReference = john::toString

methodReference.receiver // doesn't work!

The receiver of methodReference is the object john. If I look into the IntelliJ debugger, methodReference has a receiver field which indeed points to john. But I cannot find a way to actually access it in my code.

Is there some sort of workaround for this?

Answered on StackOverflow.

Yes. What we can discuss here: I’d like to have a kotlin-only way to do this via a public API. Any chance we can get something like this in the future?