Move object initialization from <init> to <clinit>

Codegen generates static backing fields for object properties.
  They are initialized in class constructor but some of them are final static
  and such access is prohibited in specification but it's allowed in
  java bytecode <= 1.8. Such access in 1.9 bytecode cause
  "IllegalAccessError: Update to static final field Object.INSTANCE
  attempted from a different method (<init>) than the initializer method <clinit>"

  Added additional hidden field in interface companion to pass out
  companion instance from <clinit>.

 #KT-15894 Fixed
This commit is contained in:
Mikhael Bogdanov
2017-03-14 13:52:07 +01:00
committed by Ilya Gorbunov
parent de004337a2
commit b73be50e5b
13 changed files with 223 additions and 47 deletions
@@ -14,7 +14,7 @@ fun box(): String {
if (enclosingMethod != null) return "method: $enclosingMethod"
val enclosingConstructor = javaClass.getEnclosingConstructor()
if (enclosingConstructor == null) return "no enclosing constructor"
if (enclosingConstructor != null) return "field should be initialized in clInit"
val enclosingClass = javaClass.getEnclosingClass()
if (enclosingClass?.getName() != "O") return "enclosing class: $enclosingClass"