Support :: references to Java instance fields in codegen
#KT-1183 In Progress
This commit is contained in:
@@ -50,6 +50,7 @@ import org.jetbrains.jet.lang.resolve.constants.IntegerValueTypeConstant;
|
||||
import org.jetbrains.jet.lang.resolve.java.AsmTypeConstants;
|
||||
import org.jetbrains.jet.lang.resolve.java.JvmAbi;
|
||||
import org.jetbrains.jet.lang.resolve.java.PackageClassUtils;
|
||||
import org.jetbrains.jet.lang.resolve.java.descriptor.JavaClassDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.java.descriptor.SamConstructorDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.java.jvmSignature.JvmMethodSignature;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
@@ -2461,7 +2462,16 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
||||
v.anew(propertyType);
|
||||
v.dup();
|
||||
v.visitLdcInsn(descriptor.getName().asString());
|
||||
v.getstatic(reflectionFieldOwner, reflectionFieldName, ownerType.getDescriptor());
|
||||
|
||||
if (containingDeclaration instanceof JavaClassDescriptor) {
|
||||
v.aconst(Type.getObjectType(reflectionFieldOwner));
|
||||
v.invokestatic("kotlin/reflect/jvm/internal/InternalPackage", "foreignKotlinClass",
|
||||
Type.getMethodDescriptor(K_CLASS_IMPL_TYPE, getType(Class.class)), false);
|
||||
}
|
||||
else {
|
||||
// TODO: built-in classes
|
||||
v.getstatic(reflectionFieldOwner, reflectionFieldName, ownerType.getDescriptor());
|
||||
}
|
||||
|
||||
String constructorDesc;
|
||||
if (receiverParameter != null) {
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
public class publicFinalField {
|
||||
public final String field = "OK";
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
fun box() = (publicFinalField::field).get(publicFinalField())
|
||||
@@ -0,0 +1,3 @@
|
||||
public class publicMutableField {
|
||||
public int field = 239;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
import publicMutableField as A
|
||||
|
||||
fun box(): String {
|
||||
val a = A()
|
||||
val f = A::field
|
||||
if (f.get(a) != 239) return "Fail 1: ${f.get(a)}"
|
||||
f[a] = 42
|
||||
if (f.get(a) != 42) return "Fail 2: ${f.get(a)}"
|
||||
if (f.get(a) != 42) return "Fail 2: ${f.get(a)}"
|
||||
return "OK"
|
||||
}
|
||||
+10
@@ -86,6 +86,16 @@ public class BlackBoxAgainstJavaCodegenTestGenerated extends AbstractBlackBoxCod
|
||||
doTestAgainstJava("compiler/testData/codegen/boxAgainstJava/callableReference/constructor.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("publicFinalField.kt")
|
||||
public void testPublicFinalField() throws Exception {
|
||||
doTestAgainstJava("compiler/testData/codegen/boxAgainstJava/callableReference/publicFinalField.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("publicMutableField.kt")
|
||||
public void testPublicMutableField() throws Exception {
|
||||
doTestAgainstJava("compiler/testData/codegen/boxAgainstJava/callableReference/publicMutableField.kt");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/boxAgainstJava/constructor")
|
||||
|
||||
Reference in New Issue
Block a user