Extension properties in class: don't put receiver on stack for GETFIELD/PUTFIELD instruction
#KT-3031 Fixed
This commit is contained in:
@@ -1409,6 +1409,9 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
||||
}
|
||||
}
|
||||
}
|
||||
if (directToField) {
|
||||
receiver = StackValue.receiverWithoutReceiverArgument(receiver);
|
||||
}
|
||||
JetType receiverType = bindingContext.get(BindingContext.EXPRESSION_TYPE, r);
|
||||
receiver.put(receiverType != null && !isSuper ? asmType(receiverType) : OBJECT_TYPE, v);
|
||||
if (receiverType != null) {
|
||||
@@ -1535,11 +1538,13 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
||||
PropertyDescriptor initialDescriptor = propertyDescriptor;
|
||||
propertyDescriptor = initialDescriptor.getOriginal();
|
||||
boolean isInsideClass = isCallInsideSameClassAsDeclared(propertyDescriptor, context);
|
||||
boolean isExtensionProperty = propertyDescriptor.getReceiverParameter() != null;
|
||||
Method getter = null;
|
||||
Method setter = null;
|
||||
if (!forceField) {
|
||||
//noinspection ConstantConditions
|
||||
if (isInsideClass &&
|
||||
!isExtensionProperty &&
|
||||
(propertyDescriptor.getGetter() == null ||
|
||||
!DescriptorUtils.isExternallyAccessible(propertyDescriptor) ||
|
||||
propertyDescriptor.getGetter().isDefault() && propertyDescriptor.getGetter().getModality() == Modality.FINAL)) {
|
||||
@@ -1576,7 +1581,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
||||
}
|
||||
}
|
||||
//noinspection ConstantConditions
|
||||
if (!propertyDescriptor.isVar() || isInsideClass &&
|
||||
if (!propertyDescriptor.isVar() || isInsideClass && !isExtensionProperty &&
|
||||
(propertyDescriptor.getSetter() == null ||
|
||||
!DescriptorUtils.isExternallyAccessible(propertyDescriptor) ||
|
||||
propertyDescriptor.getSetter().isDefault() &&
|
||||
|
||||
@@ -336,11 +336,20 @@ public abstract class StackValue {
|
||||
@Nullable CallableMethod callableMethod
|
||||
) {
|
||||
if (resolvedCall.getThisObject().exists() || resolvedCall.getReceiverArgument().exists()) {
|
||||
return new CallReceiver(resolvedCall, receiver, codegen, callableMethod);
|
||||
return new CallReceiver(resolvedCall, receiver, codegen, callableMethod, true);
|
||||
}
|
||||
return receiver;
|
||||
}
|
||||
|
||||
public static StackValue receiverWithoutReceiverArgument(StackValue receiverWithParameter) {
|
||||
if (receiverWithParameter instanceof CallReceiver) {
|
||||
CallReceiver callReceiver = (CallReceiver) receiverWithParameter;
|
||||
return new CallReceiver(callReceiver.resolvedCall, callReceiver.receiver,
|
||||
callReceiver.codegen, callReceiver.callableMethod, false);
|
||||
}
|
||||
return receiverWithParameter;
|
||||
}
|
||||
|
||||
public static StackValue singleton(ClassDescriptor classDescriptor, JetTypeMapper typeMapper) {
|
||||
final Type type = typeMapper.mapType(classDescriptor.getDefaultType());
|
||||
|
||||
@@ -1228,18 +1237,21 @@ public abstract class StackValue {
|
||||
final StackValue receiver;
|
||||
private final ExpressionCodegen codegen;
|
||||
private final CallableMethod callableMethod;
|
||||
private final boolean putReceiverArgumentOnStack;
|
||||
|
||||
public CallReceiver(
|
||||
ResolvedCall<? extends CallableDescriptor> resolvedCall,
|
||||
StackValue receiver,
|
||||
ExpressionCodegen codegen,
|
||||
CallableMethod callableMethod
|
||||
CallableMethod callableMethod,
|
||||
boolean putReceiverArgumentOnStack
|
||||
) {
|
||||
super(calcType(resolvedCall, codegen, callableMethod));
|
||||
this.resolvedCall = resolvedCall;
|
||||
this.receiver = receiver;
|
||||
this.codegen = codegen;
|
||||
this.callableMethod = callableMethod;
|
||||
this.putReceiverArgumentOnStack = putReceiverArgumentOnStack;
|
||||
}
|
||||
|
||||
private static Type calcType(
|
||||
@@ -1301,14 +1313,16 @@ public abstract class StackValue {
|
||||
codegen.generateFromResolvedCall(thisObject, codegen.typeMapper
|
||||
.mapType(descriptor.getExpectedThisObject().getType()));
|
||||
}
|
||||
genReceiver(v, receiverArgument, type, descriptor.getReceiverParameter(), 1);
|
||||
if (putReceiverArgumentOnStack) {
|
||||
genReceiver(v, receiverArgument, type, descriptor.getReceiverParameter(), 1);
|
||||
}
|
||||
}
|
||||
else {
|
||||
genReceiver(v, thisObject, type, null, 0);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (receiverArgument.exists()) {
|
||||
if (putReceiverArgumentOnStack && receiverArgument.exists()) {
|
||||
genReceiver(v, receiverArgument, type, descriptor.getReceiverParameter(), 0);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user