Merge pull request #96 from udalov/kt2384
load 'this' instead of $classobj if we're inside class object's constructor
This commit is contained in:
@@ -1487,11 +1487,15 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
|||||||
if (descriptor instanceof ClassReceiver) {
|
if (descriptor instanceof ClassReceiver) {
|
||||||
Type exprType = asmType(descriptor.getType());
|
Type exprType = asmType(descriptor.getType());
|
||||||
ClassReceiver classReceiver = (ClassReceiver) descriptor;
|
ClassReceiver classReceiver = (ClassReceiver) descriptor;
|
||||||
ClassDescriptor classReceiverDeclarationDescriptor = (ClassDescriptor) classReceiver.getDeclarationDescriptor();
|
ClassDescriptor classReceiverDeclarationDescriptor = classReceiver.getDeclarationDescriptor();
|
||||||
if (DescriptorUtils.isClassObject(classReceiverDeclarationDescriptor)) {
|
if (DescriptorUtils.isClassObject(classReceiverDeclarationDescriptor)) {
|
||||||
ClassDescriptor containingDeclaration = (ClassDescriptor) classReceiverDeclarationDescriptor.getContainingDeclaration();
|
ClassDescriptor containingDeclaration = (ClassDescriptor) classReceiverDeclarationDescriptor.getContainingDeclaration();
|
||||||
Type classObjType = typeMapper.mapType(containingDeclaration.getDefaultType(), MapTypeMode.IMPL);
|
Type classObjType = typeMapper.mapType(containingDeclaration.getDefaultType(), MapTypeMode.IMPL);
|
||||||
v.getstatic(classObjType.getInternalName(), "$classobj", exprType.getDescriptor());
|
if (context.getContextDescriptor() instanceof ConstructorDescriptor && classReceiverDeclarationDescriptor.getDefaultType().equals(((ConstructorDescriptor)context.getContextDescriptor()).getReturnType())) {
|
||||||
|
v.load(0, classObjType);
|
||||||
|
} else {
|
||||||
|
v.getstatic(classObjType.getInternalName(), "$classobj", exprType.getDescriptor());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
generateThisOrOuter(classReceiverDeclarationDescriptor).put(exprType, v);
|
generateThisOrOuter(classReceiverDeclarationDescriptor).put(exprType, v);
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
class A {
|
||||||
|
class object {
|
||||||
|
val b = 0
|
||||||
|
val c = b
|
||||||
|
|
||||||
|
{
|
||||||
|
val d = b
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
A()
|
||||||
|
return if (A.c == A.b) "OK" else "Fail"
|
||||||
|
}
|
||||||
@@ -451,4 +451,9 @@ public class ClassGenTest extends CodegenTestCase {
|
|||||||
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
|
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
|
||||||
blackBoxFile("regressions/kt2224.kt");
|
blackBoxFile("regressions/kt2224.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testKt2384() {
|
||||||
|
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
|
||||||
|
blackBoxFile("regressions/kt2384.kt");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user