class object field access

This commit is contained in:
Alex Tkachman
2011-12-15 17:21:56 +02:00
committed by Nikolay Krasko
parent 55c11d0f44
commit c90a6263a1
2 changed files with 15 additions and 1 deletions
@@ -1254,7 +1254,15 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
if(descriptor instanceof ClassReceiver) {
Type exprType = asmType(descriptor.getType());
ClassReceiver classReceiver = (ClassReceiver) descriptor;
generateThisOrOuter((ClassDescriptor) classReceiver.getDeclarationDescriptor()).put(exprType, v);
ClassDescriptor classReceiverDeclarationDescriptor = (ClassDescriptor) classReceiver.getDeclarationDescriptor();
if(CodegenUtil.isClassObject(classReceiverDeclarationDescriptor)) {
ClassDescriptor containingDeclaration = (ClassDescriptor) classReceiverDeclarationDescriptor.getContainingDeclaration();
Type classObjType = typeMapper.mapType(containingDeclaration.getDefaultType());
v.getstatic(classObjType.getInternalName(), "$classobj", exprType.getDescriptor());
}
else {
generateThisOrOuter(classReceiverDeclarationDescriptor).put(exprType, v);
}
if(type != null)
StackValue.onStack(exprType).put(type, v);
}
@@ -166,6 +166,12 @@ public class ClassGenTest extends CodegenTestCase {
assertEquals(0xFF0000, rgbMethod.invoke(redValue));
}
public void testClassObjFields() throws Exception {
loadText("class A() { class object { val value = 10 } }\n" +
"fun box() = if(A.value == 10) \"OK\" else \"fail\"");
blackBox();
}
public void testKt249() throws Exception {
blackBoxFile("regressions/kt249.jet");
}