Fix for-in iterator over array of boxed inline class values

#KT-25324 Fixed
This commit is contained in:
Mikhail Zarechenskiy
2018-07-11 02:23:41 +03:00
parent 584c888e5b
commit 0308e10c11
9 changed files with 111 additions and 3 deletions
@@ -15,6 +15,7 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
import org.jetbrains.kotlin.builtins.PrimitiveType;
import org.jetbrains.kotlin.builtins.UnsignedTypes;
import org.jetbrains.kotlin.codegen.binding.CalculatedClosure;
import org.jetbrains.kotlin.codegen.context.CodegenContext;
import org.jetbrains.kotlin.codegen.intrinsics.HashCode;
@@ -113,8 +114,27 @@ public class AsmUtil {
@NotNull
public static Type boxType(@NotNull Type type) {
Type boxedType = boxPrimitiveType(type);
return boxedType != null ? boxedType : type;
}
@NotNull
public static Type boxType(@NotNull Type type, @NotNull KotlinType kotlinType, @NotNull GenerationState state) {
Type boxedPrimitiveType = boxPrimitiveType(type);
if (boxedPrimitiveType != null) return boxedPrimitiveType;
if (InlineClassesUtilsKt.isInlineClassType(kotlinType)) {
return state.getTypeMapper().mapTypeAsDeclaration(kotlinType);
}
else {
return type;
}
}
@Nullable
private static Type boxPrimitiveType(@NotNull Type type) {
JvmPrimitiveType jvmPrimitiveType = primitiveTypeByAsmSort.get(type.getSort());
return jvmPrimitiveType != null ? asmTypeByFqNameWithoutInnerClasses(jvmPrimitiveType.getWrapperFqName()) : type;
return jvmPrimitiveType != null ? asmTypeByFqNameWithoutInnerClasses(jvmPrimitiveType.getWrapperFqName()) : null;
}
@NotNull
@@ -78,12 +78,13 @@ class ForInArrayLoopGenerator(
}
override fun assignToLoopParameter() {
val arrayElParamType = if (KotlinBuiltIns.isArray(loopRangeType)) boxType(asmElementType) else asmElementType
val arrayElParamType =
if (KotlinBuiltIns.isArray(loopRangeType)) boxType(asmElementType, elementType, codegen.state) else asmElementType
v.load(arrayVar, OBJECT_TYPE)
v.load(indexVar, Type.INT_TYPE)
v.aload(arrayElParamType)
StackValue.onStack(arrayElParamType).put(asmElementType, codegen.v)
StackValue.onStack(arrayElParamType, elementType).put(asmElementType, elementType, codegen.v)
v.store(loopParameterVar, asmElementType)
}