Fix initialization order of KClass field and class object fields

This commit is contained in:
Alexander Udalov
2014-06-09 17:52:10 +04:00
parent c17f515d06
commit 89d6f25fb6
3 changed files with 20 additions and 4 deletions
@@ -208,6 +208,8 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
writeInnerClasses();
AnnotationCodegen.forClass(v.getVisitor(), typeMapper).genAnnotations(descriptor, null);
generateReflectionObjectFieldIfNeeded();
}
@Override
@@ -428,7 +430,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
@Override
protected void generateSyntheticParts() {
generateStaticSyntheticFields();
generatePropertyMetadataArrayFieldIfNeeded(classAsmType);
generateFieldForSingleton();
@@ -465,7 +467,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
genClosureFields(context.closure, v, typeMapper);
}
private void generateStaticSyntheticFields() {
private void generateReflectionObjectFieldIfNeeded() {
if (isAnnotationClass(descriptor)) {
// There's a bug in JDK 6 and 7 that prevents us from generating a static field in an annotation class:
// http://bugs.java.com/bugdatabase/view_bug.do?bug_id=6857918
@@ -475,8 +477,6 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
generateReflectionObjectField(state, classAsmType, v, method("kClass", K_CLASS_IMPL_TYPE, getType(Class.class)),
JvmAbi.KOTLIN_CLASS_FIELD_NAME, createOrGetClInitCodegen().v);
generatePropertyMetadataArrayFieldIfNeeded(classAsmType);
}
private boolean isGenericToArrayPresent() {
@@ -0,0 +1,11 @@
class A {
class object {
val ref: KMemberProperty<A, String> = A::foo
}
val foo: String = "OK"
}
fun box(): String {
return A.ref.get(A())
}
@@ -444,6 +444,11 @@ public class BlackBoxWithStdlibCodegenTestGenerated extends AbstractBlackBoxCode
doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/callableReference/property/javaBeanConvention.kt");
}
@TestMetadata("kClassInstanceIsInitializedFirst.kt")
public void testKClassInstanceIsInitializedFirst() throws Exception {
doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/callableReference/property/kClassInstanceIsInitializedFirst.kt");
}
@TestMetadata("localClassVar.kt")
public void testLocalClassVar() throws Exception {
doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/callableReference/property/localClassVar.kt");