don't generate direct increment and similar bytecodes for variables which are captured in closure (KT-1980)
This commit is contained in:
@@ -1635,6 +1635,9 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
||||
|
||||
public int indexOfLocal(JetReferenceExpression lhs) {
|
||||
final DeclarationDescriptor declarationDescriptor = bindingContext.get(BindingContext.REFERENCE_TARGET, lhs);
|
||||
if (typeMapper.isVarCapturedInClosure(declarationDescriptor)) {
|
||||
return -1;
|
||||
}
|
||||
return lookupLocal(declarationDescriptor);
|
||||
}
|
||||
|
||||
|
||||
@@ -1033,17 +1033,17 @@ public class JetTypeMapper {
|
||||
else if (descriptor instanceof FunctionDescriptor) {
|
||||
return StackValue.sharedTypeForType(mapType(((FunctionDescriptor) descriptor).getReceiverParameter().getType(), MapTypeMode.VALUE));
|
||||
}
|
||||
else if (descriptor instanceof VariableDescriptor) {
|
||||
VariableDescriptor variableDescriptor = (VariableDescriptor) descriptor;
|
||||
Boolean aBoolean = bindingContext.get(BindingContext.CAPTURED_IN_CLOSURE, variableDescriptor);
|
||||
if (aBoolean != null && aBoolean && variableDescriptor.isVar()) {
|
||||
JetType outType = variableDescriptor.getType();
|
||||
return StackValue.sharedTypeForType(mapType(outType, MapTypeMode.VALUE));
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
else if (descriptor instanceof VariableDescriptor && isVarCapturedInClosure(descriptor)) {
|
||||
JetType outType = ((VariableDescriptor) descriptor).getType();
|
||||
return StackValue.sharedTypeForType(mapType(outType, MapTypeMode.VALUE));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isVarCapturedInClosure(DeclarationDescriptor descriptor) {
|
||||
if (!(descriptor instanceof VariableDescriptor) || descriptor instanceof PropertyDescriptor) return false;
|
||||
VariableDescriptor variableDescriptor = (VariableDescriptor) descriptor;
|
||||
Boolean aBoolean = bindingContext.get(BindingContext.CAPTURED_IN_CLOSURE, variableDescriptor);
|
||||
return aBoolean != null && aBoolean && variableDescriptor.isVar();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user