The
fun First.print()
is an extension function defined in a class/interface and therefore it has
two receivers. One must be an implicit instance-receiver (of type
Second
), the second one must be the explicit receiver that is extended (of type
First
).
The only way to call a function with multiple receivers is to be ‘in the context of the instance-receiver’ and then provide the second one.
Where you call it (
Third().print()
), you only provide
one receiver, the explicit extended receiver, and you are not in the context of any (implicit) instance-receiver.
Inside the lambda of the
with
function, you have both receivers (and they are the same instance of course).
I do agree, though, that either both statements should compile or none of them. Because in the
with
lambda, you don’t provide an explicit receiver either (the implicit
this
is used).
Interesting… 🙂