Depends on more context.
For example you can qualify it if it is a top-level function like
package bar
fun foo() = println("No receiver")
fun Int.foo() = println("My receiver is $this")
fun main(){
with(42) { bar.foo() }
}
Or if the
foo
is a local function it will also win:
fun Int.foo() = println("My receiver is $this")
fun main(){
fun foo() = println("No receiver")
with(42) { foo() }
}
A combination of the two:
package bar
fun foo() = println("No receiver")
fun Int.foo() = println("My receiver is $this")
fun main(){
fun foo() = bar.foo()
with(42) { foo() }
}
Or you can qualify the
this
reference if possible like
class Foo {
fun foo() = println("No receiver")
fun Int.foo() = println("My receiver is $this")
fun main(){
with(42) { this@Foo.foo() }
}
}
fun main() = Foo().main()