Is there any reason why Kotlin compiler generates ...
# announcements
v
Is there any reason why Kotlin compiler generates synthetic accessors to call private methods from inlined lambdas? For example:
Copy code
public class Main {
  public fun foo() {
    "one".apply {
      bar()
    }
  }

  private fun bar() = Unit
}
Main.foo
compiles to:
Copy code
public final foo()V
   L0
    LINENUMBER 17 L0
    LDC "one"
    ASTORE 1
    NOP
   L1
    LINENUMBER 25 L1
    ALOAD 1
    CHECKCAST java/lang/String
    ASTORE 2
   L2
    LINENUMBER 18 L2
    ALOAD 0
    INVOKESTATIC com/github/vmironov/Main.access$bar (Lcom/github/vmironov/Main;)V
   L3
   L4
    GETSTATIC kotlin/Unit.INSTANCE : Lkotlin/Unit;
    POP
    ALOAD 1
   L5
    POP
   L6
    LINENUMBER 20 L6
    RETURN
Main.bar()
can be invoked directly, so I don't understand why
Main.access$bar
is generated and used instead. Is there any particular reason for this behaviour? The same applies to private fields too.