Davide Giuseppe Farella
03/28/2019, 11:22 PMbdawg.io
03/28/2019, 11:23 PMThird
instance, so nobdawg.io
03/28/2019, 11:24 PMbdawg.io
03/28/2019, 11:25 PMval third = Third()
third.print(third)
Davide Giuseppe Farella
03/28/2019, 11:26 PMstreetsofboston
03/29/2019, 12:26 AMfun 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… 🙂Davide Giuseppe Farella
03/29/2019, 7:55 AMfun Third.print() = print()
🤯streetsofboston
03/29/2019, 11:49 AMfun print(receiver: First) = ...
Davide Giuseppe Farella
03/29/2019, 11:54 AM