INSTANCE field deprecated in companion object

Fix for KT-9692: Deadlock between <clinit> of a class (KtSimpleNameExpressionImpl) and <clinit> of its companion object

 #KT-9692 Fixed
This commit is contained in:
Michael Bogdanov
2015-10-23 12:27:41 +03:00
parent 7927185cc7
commit 18f3eb87e4
13 changed files with 120 additions and 26 deletions

View File

@@ -0,0 +1,7 @@
public class CompanionInitialization {
public static Object getCompanion() {
return ConcreteWithStatic.Companion;
}
}

View File

@@ -0,0 +1,20 @@
interface IStatic
open class Static(x: IStatic) {
fun doSth() {
}
}
class ConcreteWithStatic : IStatic {
companion object : Static(ConcreteWithStatic())
}
fun box(): String {
ConcreteWithStatic.doSth()
val companion: Any? = CompanionInitialization.getCompanion()
if (companion == null) return "fail 1"
if (companion != ConcreteWithStatic) return "fail 2"
return "OK"
}

View File

@@ -0,0 +1,7 @@
public class CompanionInitialization {
public static Object getCompanion() {
return IStatic.Companion;
}
}

View File

@@ -0,0 +1,22 @@
open class Static(): IStatic {
val p = IStatic::class.java.getDeclaredField("const").get(null)
}
interface IStatic {
fun doSth() {
}
companion object : Static() {
const val const = 1;
}
}
fun box(): String {
IStatic.doSth()
val companion: Any? = CompanionInitialization.getCompanion()
if (companion == null) return "fail 1"
if (companion != IStatic) return "fail 2"
return "OK"
}