title: Kotlin class reloading with companion objects/functions
body: <p>I'm experimenting with Kotlin class reloading, but I recently got stuck with something close to this:</p>
  
  <pre><code>package com.aurieh.reloading
  fun doSomething(): String { // a function that does not belong to the class,
      // so it gets compiled as FileName$doSomething$...
  }
  
  class FileName {
      // do things with doSomething
  }
  </code></pre>
  
  <p>And if I reload this class (with <code>ImplClassLoader.defineClass</code> and <code>ByteArray</code>), and try do invoke methods that call doSomething internally, I get an error similar to:</p>
  
  <pre><code>java.lang.IllegalAccessError: tried to access method com.aurieh.reloading.FileName.doSomething$default()Ljava/lang/String; from class com.aurieh.ares.reloading.FileName`
  </code></pre>
  
  <p>I would interpret this as if the reloaded class does not have doSomething attached..
  So my question would be, how would I resolve this error? By somehow attaching doSomething to reloading classloader?</p>
  
  <p>For reference, my class reloading code:</p>
  
  <pre><code>class Reloader : ClassLoader() {
      fun load(name: String, bytes: ByteArray, offset: Int, len: Int): Class&lt;*&gt; {
          return defineClass("com.aurieh.reloading.$name", bytes, offset, len)
      }
  }
  </code></pre>
  
  <p>And for loading:</p>
  
  <pre><code>val bytes = File("../classes/path/to/class/FileName.class").readBytes()
  Reloader().load("FileName", bytes, 0, bytes.size).newInstance()
  </code></pre>