It seems that given the code, ```class Foo { v...
# compiler
l
It seems that given the code,
Copy code
class Foo {
    val suffix = "suffix"

    fun foo() {}

    inner class Bar {
        fun bar() {}
    }
}
bar()
can access
suffix
via
Foo.thisReceiver
(=
this@Foo
?) but
foo()
can't. Why not? Instead,
foo()
must use
dispatchReceiverParameter
. And, should I be using
Foo.thisReceiver
in
bar()
?
p
If you mean IR that should be generated by compiler plugin, the best option is always to check what would be generated by compiler from code. While, backend is generally flexible to slightly incorrect IR, it's not tested, and can work strangely. IrClass.thisReciver is used in scopes where there is no other options (like init blocks or inner classes), so probably we just never tried to use it from function. Typically access of thisReceiver would be replaced with something in some lowering (e.g. with access to field, where this of outer class is stored). In function it should be replaced with dispatch receiver (i.e. this parameter of function, as it's a platform way to access it), and there is no much reason to not do it initially. Here is some discussion on way to dump IR to check it.
l
Aha, thank you. It's just that when retrieving
suffix
from these two different methods I have to do different things in the transformer while the Kotlin code would be essentially the same.