diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/StackValue.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/StackValue.java index c3f46b0a4eb..21678617508 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/StackValue.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/StackValue.java @@ -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.CodegenBinding; import org.jetbrains.kotlin.codegen.coroutines.CoroutineCodegenUtilKt; import org.jetbrains.kotlin.codegen.intrinsics.IntrinsicMethods; @@ -794,8 +795,11 @@ public abstract class StackValue { ResolvedCall resolvedCall, @NotNull ExpressionCodegen codegen ) { - if (stackValue instanceof StackValue.Local && Type.INT_TYPE == stackValue.type) { - return preIncrementForLocalVar(((StackValue.Local) stackValue).index, delta, stackValue.kotlinType); + KotlinType kotlinType = stackValue.kotlinType; + if (stackValue instanceof StackValue.Local && Type.INT_TYPE == stackValue.type && + kotlinType != null && KotlinBuiltIns.isPrimitiveType(kotlinType) + ) { + return preIncrementForLocalVar(((StackValue.Local) stackValue).index, delta, kotlinType); } return new PrefixIncrement(type, stackValue, resolvedCall, codegen); } diff --git a/compiler/testData/codegen/box/inlineClasses/kt33119.kt b/compiler/testData/codegen/box/inlineClasses/kt33119.kt new file mode 100644 index 00000000000..0eff331a2f7 --- /dev/null +++ b/compiler/testData/codegen/box/inlineClasses/kt33119.kt @@ -0,0 +1,18 @@ +// IGNORE_BACKEND_FIR: JVM_IR + +inline class WrappingInt(val value: Int) { + operator fun inc(): WrappingInt = plus(1) + operator fun plus(num: Int): WrappingInt = WrappingInt((value + num) and 0xFFFF) +} + +fun box(): String { + var x = WrappingInt(65535) + x++ + if (x.value != 0) throw AssertionError("x++: ${x.value}") + + var y = WrappingInt(65535) + ++y + if (y.value != 0) throw AssertionError("++y: ${y.value}") + + return "OK" +} \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index 0e0680ff86e..8c20e8e2916 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -13408,6 +13408,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/inlineClasses/kt28920_javaPrimitiveType.kt"); } + @TestMetadata("kt33119.kt") + public void testKt33119() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/kt33119.kt"); + } + @TestMetadata("kt34268.kt") public void testKt34268() throws Exception { runTest("compiler/testData/codegen/box/inlineClasses/kt34268.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index 175102424c8..5835c3e82ff 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -13413,6 +13413,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/inlineClasses/kt28920_javaPrimitiveType.kt"); } + @TestMetadata("kt33119.kt") + public void testKt33119() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/kt33119.kt"); + } + @TestMetadata("kt34268.kt") public void testKt34268() throws Exception { runTest("compiler/testData/codegen/box/inlineClasses/kt34268.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java index a382e58376e..7aeeaff7e41 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java @@ -12278,6 +12278,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT runTest("compiler/testData/codegen/box/inlineClasses/kt28920_javaPrimitiveType.kt"); } + @TestMetadata("kt33119.kt") + public void testKt33119() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/kt33119.kt"); + } + @TestMetadata("kt34268.kt") public void testKt34268() throws Exception { runTest("compiler/testData/codegen/box/inlineClasses/kt34268.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java index 1006c1a1f24..12c88141820 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java @@ -12278,6 +12278,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/inlineClasses/kt28920_javaPrimitiveType.kt"); } + @TestMetadata("kt33119.kt") + public void testKt33119() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/kt33119.kt"); + } + @TestMetadata("kt34268.kt") public void testKt34268() throws Exception { runTest("compiler/testData/codegen/box/inlineClasses/kt34268.kt"); diff --git a/core/descriptors/src/org/jetbrains/kotlin/builtins/UnsignedType.kt b/core/descriptors/src/org/jetbrains/kotlin/builtins/UnsignedType.kt index b1fd28c86c2..d25c932f4f4 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/builtins/UnsignedType.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/builtins/UnsignedType.kt @@ -43,6 +43,7 @@ object UnsignedTypes { fun getUnsignedClassIdByArrayClassId(arrayClassId: ClassId): ClassId? = arrayClassIdToUnsignedClassId[arrayClassId] fun getUnsignedArrayClassIdByUnsignedClassId(arrayClassId: ClassId): ClassId? = unsignedClassIdToArrayClassId[arrayClassId] + @JvmStatic fun isUnsignedType(type: KotlinType): Boolean { if (TypeUtils.noExpectedType(type)) return false diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java index 824c0bf0b6f..c7cdb8db0da 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java @@ -10558,6 +10558,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest { runTest("compiler/testData/codegen/box/inlineClasses/kt28585.kt"); } + @TestMetadata("kt33119.kt") + public void testKt33119() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/kt33119.kt"); + } + @TestMetadata("kt34268.kt") public void testKt34268() throws Exception { runTest("compiler/testData/codegen/box/inlineClasses/kt34268.kt"); diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java index cde042485a7..7fe2cecd323 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java @@ -10623,6 +10623,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { runTest("compiler/testData/codegen/box/inlineClasses/kt28585.kt"); } + @TestMetadata("kt33119.kt") + public void testKt33119() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/kt33119.kt"); + } + @TestMetadata("kt34268.kt") public void testKt34268() throws Exception { runTest("compiler/testData/codegen/box/inlineClasses/kt34268.kt");