Fix code generation for Array<C> element access where C is inline class

This commit is contained in:
Dmitry Petrov
2018-08-10 14:22:41 +03:00
parent 8063db5f80
commit 0af33462ef
10 changed files with 226 additions and 8 deletions
@@ -4256,21 +4256,22 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
@Override
public StackValue visitArrayAccessExpression(@NotNull KtArrayAccessExpression expression, StackValue receiver) {
KtExpression array = expression.getArrayExpression();
KotlinType type = array != null ? bindingContext.getType(array) : null;
KotlinType arrayKotlinType = array != null ? bindingContext.getType(array) : null;
Type arrayType = expressionType(array);
List<KtExpression> indices = expression.getIndexExpressions();
FunctionDescriptor operationDescriptor = (FunctionDescriptor) bindingContext.get(REFERENCE_TARGET, expression);
assert operationDescriptor != null;
boolean isInlineClassType = type != null && InlineClassesUtilsKt.isInlineClassType(type);
boolean isInlineClassType = arrayKotlinType != null && InlineClassesUtilsKt.isInlineClassType(arrayKotlinType);
if (arrayType.getSort() == Type.ARRAY &&
indices.size() == 1 &&
isInt(operationDescriptor.getValueParameters().get(0).getType()) &&
!isInlineClassType) {
assert type != null;
!isInlineClassType
) {
assert arrayKotlinType != null;
KotlinType elementKotlinType = state.getModule().getBuiltIns().getArrayElementType(arrayKotlinType);
Type elementType;
if (KotlinBuiltIns.isArray(type)) {
KotlinType jetElementType = type.getArguments().get(0).getType();
elementType = boxType(asmType(jetElementType));
if (KotlinBuiltIns.isArray(arrayKotlinType)) {
elementType = boxType(asmType(elementKotlinType), elementKotlinType, state);
}
else {
elementType = correctElementType(arrayType);
@@ -4278,7 +4279,7 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
StackValue arrayValue = genLazy(array, arrayType);
StackValue index = genLazy(indices.get(0), Type.INT_TYPE);
return StackValue.arrayElement(elementType, null, arrayValue, index);
return StackValue.arrayElement(elementType, elementKotlinType, arrayValue, index);
}
else {
ResolvedCall<FunctionDescriptor> resolvedSetCall = bindingContext.get(INDEXED_LVALUE_SET, expression);