From 820d168607ea8ffce13d13c32d7899dc2d444a6d Mon Sep 17 00:00:00 2001 From: Mikhail Zarechenskiy Date: Fri, 13 Jul 2018 11:58:41 +0300 Subject: [PATCH] First, check for inline class type before boxing The problem was that if `type` is of primitive type, but `KotlinType` is actually an inline class type, then anyway we boxed this type as primitive --- .../src/org/jetbrains/kotlin/codegen/AsmUtil.java | 9 +++------ .../iterateOverArrayOfInlineClassValues.kt | 12 +++++++++++- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/AsmUtil.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/AsmUtil.java index 740b350155d..4f29a54c326 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/AsmUtil.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/AsmUtil.java @@ -120,15 +120,12 @@ public class AsmUtil { @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; - } + + Type boxedPrimitiveType = boxPrimitiveType(type); + return boxedPrimitiveType != null ? boxedPrimitiveType : type; } @Nullable diff --git a/compiler/testData/codegen/box/inlineClasses/iterateOverArrayOfInlineClassValues.kt b/compiler/testData/codegen/box/inlineClasses/iterateOverArrayOfInlineClassValues.kt index ba6b33c3ccb..cbcd74c6717 100644 --- a/compiler/testData/codegen/box/inlineClasses/iterateOverArrayOfInlineClassValues.kt +++ b/compiler/testData/codegen/box/inlineClasses/iterateOverArrayOfInlineClassValues.kt @@ -4,6 +4,7 @@ // IGNORE_BACKEND: JS_IR inline class Foo(val arg: Int) +inline class AsAny(val arg: Any) fun box(): String { val arr = arrayOf(Foo(1), Foo(2)) @@ -12,5 +13,14 @@ fun box(): String { sum += el.arg } - return if (sum != 3) "Fail" else "OK" + if (sum != 3) return "Fail 1" + + sum = 0 + for (el in arrayOf(AsAny(42), AsAny(1))) { + sum += el.arg as Int + } + + if (sum != 43) return "Fail 2" + + return "OK" }