Let's say I have ```class A { fun B.something() ...
# announcements
j
Let's say I have
Copy code
class A {
  fun B.something() { ... }
}
something()
has two receivers, A and B, yeah? I was hoping that would let me do this:
Copy code
class B {
  init {
    val a = A()
    a.something()
  }
}
but it seems in reality I have to do this:
Copy code
class B {
  init {
    val a = A()
    with(a) {
      something()
    }
  }
}
Is there a nicer way to get something closer to the first one?
n
I assume that
something
has a good reason to be a member of
A
. Why not though simply
fun something(b: B)
, and then in
B
you can do
a.something(this)
If the reason is simply that you want both A and B to be in scope during `something`'s implementation, that is easily enough solved:
fun something(b: B) = b.run { ... }
j
I care less about having things in scope inside the function and more about not having to pass
this
in constantly when it's already in scope at the call site.
n
I guess the way you could solve this is to define a function in B
fun A.something() = this@A.run { this@B.something() }
And now you get the syntax you want
h
I only took a glimpse look, is this your issue possibly? https://youtrack.jetbrains.com/issue/KT-42626