Fix initialization order of KClass field and class object fields
This commit is contained in:
@@ -208,6 +208,8 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
writeInnerClasses();
|
writeInnerClasses();
|
||||||
|
|
||||||
AnnotationCodegen.forClass(v.getVisitor(), typeMapper).genAnnotations(descriptor, null);
|
AnnotationCodegen.forClass(v.getVisitor(), typeMapper).genAnnotations(descriptor, null);
|
||||||
|
|
||||||
|
generateReflectionObjectFieldIfNeeded();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -428,7 +430,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void generateSyntheticParts() {
|
protected void generateSyntheticParts() {
|
||||||
generateStaticSyntheticFields();
|
generatePropertyMetadataArrayFieldIfNeeded(classAsmType);
|
||||||
|
|
||||||
generateFieldForSingleton();
|
generateFieldForSingleton();
|
||||||
|
|
||||||
@@ -465,7 +467,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
genClosureFields(context.closure, v, typeMapper);
|
genClosureFields(context.closure, v, typeMapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void generateStaticSyntheticFields() {
|
private void generateReflectionObjectFieldIfNeeded() {
|
||||||
if (isAnnotationClass(descriptor)) {
|
if (isAnnotationClass(descriptor)) {
|
||||||
// There's a bug in JDK 6 and 7 that prevents us from generating a static field in an annotation class:
|
// 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
|
// 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)),
|
generateReflectionObjectField(state, classAsmType, v, method("kClass", K_CLASS_IMPL_TYPE, getType(Class.class)),
|
||||||
JvmAbi.KOTLIN_CLASS_FIELD_NAME, createOrGetClInitCodegen().v);
|
JvmAbi.KOTLIN_CLASS_FIELD_NAME, createOrGetClInitCodegen().v);
|
||||||
|
|
||||||
generatePropertyMetadataArrayFieldIfNeeded(classAsmType);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isGenericToArrayPresent() {
|
private boolean isGenericToArrayPresent() {
|
||||||
|
|||||||
+11
@@ -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())
|
||||||
|
}
|
||||||
+5
@@ -444,6 +444,11 @@ public class BlackBoxWithStdlibCodegenTestGenerated extends AbstractBlackBoxCode
|
|||||||
doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/callableReference/property/javaBeanConvention.kt");
|
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")
|
@TestMetadata("localClassVar.kt")
|
||||||
public void testLocalClassVar() throws Exception {
|
public void testLocalClassVar() throws Exception {
|
||||||
doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/callableReference/property/localClassVar.kt");
|
doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/callableReference/property/localClassVar.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user