Support local property delegation to inline class values
Also, add extra test on property delegation.
This commit is contained in:
@@ -1939,11 +1939,15 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
|
||||
|
||||
Type sharedVarType = typeMapper.getSharedVarType(descriptor);
|
||||
Type varType = getVariableTypeNoSharing(variableDescriptor);
|
||||
KotlinType delegateKotlinType =
|
||||
isDelegatedLocalVariable(descriptor)
|
||||
? JvmCodegenUtil.getPropertyDelegateType((VariableDescriptorWithAccessors) descriptor, bindingContext)
|
||||
: null;
|
||||
if (sharedVarType != null) {
|
||||
return StackValue.shared(index, varType, variableDescriptor);
|
||||
return StackValue.shared(index, varType, variableDescriptor, delegateKotlinType);
|
||||
}
|
||||
else {
|
||||
return adjustVariableValue(StackValue.local(index, varType, variableDescriptor), variableDescriptor);
|
||||
return adjustVariableValue(StackValue.local(index, varType, variableDescriptor, delegateKotlinType), variableDescriptor);
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -4124,9 +4128,10 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
|
||||
|
||||
Type varType = getVariableTypeNoSharing(variableDescriptor);
|
||||
|
||||
KotlinType delegateKotlinType = JvmCodegenUtil.getPropertyDelegateType(variableDescriptor, bindingContext);
|
||||
StackValue storeTo = sharedVarType == null ?
|
||||
StackValue.local(index, varType, variableDescriptor) :
|
||||
StackValue.shared(index, varType, variableDescriptor);
|
||||
StackValue.local(index, varType, variableDescriptor, delegateKotlinType) :
|
||||
StackValue.shared(index, varType, variableDescriptor, delegateKotlinType);
|
||||
|
||||
storeTo.putReceiver(v, false);
|
||||
if (variableDescriptor.isLateInit()) {
|
||||
@@ -4918,7 +4923,7 @@ The "returned" value of try expression with no finally is either the last expres
|
||||
@NotNull VariableDescriptorWithAccessors variableDescriptor,
|
||||
@NotNull KotlinTypeMapper typeMapper
|
||||
) {
|
||||
return StackValue.delegate(typeMapper.mapType(variableDescriptor.getType()), delegateValue, metadataValue, variableDescriptor, this);
|
||||
return StackValue.localDelegate(typeMapper.mapType(variableDescriptor.getType()), delegateValue, metadataValue, variableDescriptor, this);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -25,7 +25,10 @@ import org.jetbrains.kotlin.load.java.JvmAbi;
|
||||
import org.jetbrains.kotlin.name.Name;
|
||||
import org.jetbrains.kotlin.psi.KtExpression;
|
||||
import org.jetbrains.kotlin.psi.ValueArgument;
|
||||
import org.jetbrains.kotlin.resolve.*;
|
||||
import org.jetbrains.kotlin.resolve.BindingContext;
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils;
|
||||
import org.jetbrains.kotlin.resolve.ImportedFromObjectCallableDescriptor;
|
||||
import org.jetbrains.kotlin.resolve.InlineClassesUtilsKt;
|
||||
import org.jetbrains.kotlin.resolve.calls.model.DefaultValueArgument;
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall;
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedValueArgument;
|
||||
@@ -160,16 +163,26 @@ public abstract class StackValue {
|
||||
|
||||
@NotNull
|
||||
public static StackValue local(int index, @NotNull Type type, @NotNull VariableDescriptor descriptor) {
|
||||
return local(index, type, descriptor, null);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static StackValue local(int index, @NotNull Type type, @NotNull VariableDescriptor descriptor, @Nullable KotlinType delegateKotlinType) {
|
||||
if (descriptor.isLateInit()) {
|
||||
assert delegateKotlinType == null :
|
||||
"Delegated property can't be lateinit: " + descriptor + ", delegate type: " + delegateKotlinType;
|
||||
return new LateinitLocal(index, type, descriptor.getType(), descriptor.getName());
|
||||
}
|
||||
else {
|
||||
return new Local(index, type, descriptor.getType());
|
||||
return new Local(
|
||||
index, type,
|
||||
delegateKotlinType != null ? delegateKotlinType : descriptor.getType()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Delegate delegate(
|
||||
public static Delegate localDelegate(
|
||||
@NotNull Type type,
|
||||
@NotNull StackValue delegateValue,
|
||||
@NotNull StackValue metadataValue,
|
||||
@@ -186,7 +199,16 @@ public abstract class StackValue {
|
||||
|
||||
@NotNull
|
||||
public static StackValue shared(int index, @NotNull Type type, @NotNull VariableDescriptor descriptor) {
|
||||
return new Shared(index, type, descriptor.getType(), descriptor.isLateInit(), descriptor.getName());
|
||||
return shared(index, type, descriptor, null);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static StackValue shared(int index, @NotNull Type type, @NotNull VariableDescriptor descriptor, @Nullable KotlinType delegateKotlinType) {
|
||||
return new Shared(
|
||||
index, type,
|
||||
delegateKotlinType != null ? delegateKotlinType : descriptor.getType(),
|
||||
descriptor.isLateInit(), descriptor.getName()
|
||||
);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
Reference in New Issue
Block a user