Use proper KotlinType for prefix increment/decrement
Otherwise inline class values (such as UByte) are boxed incorrectly, see KT-26219.
This commit is contained in:
@@ -698,8 +698,8 @@ public abstract class StackValue {
|
||||
return new PostIncrement(index, increment);
|
||||
}
|
||||
|
||||
public static StackValue preIncrementForLocalVar(int index, int increment) {
|
||||
return new PreIncrementForLocalVar(index, increment);
|
||||
public static StackValue preIncrementForLocalVar(int index, int increment, @Nullable KotlinType kotlinType) {
|
||||
return new PreIncrementForLocalVar(index, increment, kotlinType);
|
||||
}
|
||||
|
||||
public static StackValue preIncrement(
|
||||
@@ -710,7 +710,7 @@ public abstract class StackValue {
|
||||
@NotNull ExpressionCodegen codegen
|
||||
) {
|
||||
if (stackValue instanceof StackValue.Local && Type.INT_TYPE == stackValue.type) {
|
||||
return preIncrementForLocalVar(((StackValue.Local) stackValue).index, delta);
|
||||
return preIncrementForLocalVar(((StackValue.Local) stackValue).index, delta, stackValue.kotlinType);
|
||||
}
|
||||
return new PrefixIncrement(type, stackValue, resolvedCall, codegen);
|
||||
}
|
||||
@@ -1834,8 +1834,8 @@ public abstract class StackValue {
|
||||
private final int index;
|
||||
private final int increment;
|
||||
|
||||
public PreIncrementForLocalVar(int index, int increment) {
|
||||
super(Type.INT_TYPE);
|
||||
public PreIncrementForLocalVar(int index, int increment, @Nullable KotlinType kotlinType) {
|
||||
super(Type.INT_TYPE, kotlinType);
|
||||
this.index = index;
|
||||
this.increment = increment;
|
||||
}
|
||||
@@ -1861,7 +1861,7 @@ public abstract class StackValue {
|
||||
ResolvedCall resolvedCall,
|
||||
@NotNull ExpressionCodegen codegen
|
||||
) {
|
||||
super(type);
|
||||
super(type, value.kotlinType);
|
||||
this.value = value;
|
||||
this.resolvedCall = resolvedCall;
|
||||
this.codegen = codegen;
|
||||
|
||||
+117
@@ -0,0 +1,117 @@
|
||||
// WITH_UNSIGNED
|
||||
// IGNORE_BACKEND: JS_IR, JVM_IR, JS
|
||||
|
||||
fun prefixDecrementUByteLocal(): Any? {
|
||||
var a: UByte = 0u
|
||||
return --a
|
||||
}
|
||||
|
||||
fun prefixDecrementUShortLocal(): Any? {
|
||||
var a: UShort = 0u
|
||||
return --a
|
||||
}
|
||||
|
||||
fun prefixDecrementUIntLocal(): Any? {
|
||||
var a: UInt = 0u
|
||||
return --a
|
||||
}
|
||||
|
||||
fun prefixDecrementULongLocal(): Any? {
|
||||
var a: ULong = 0u
|
||||
return --a
|
||||
}
|
||||
|
||||
fun prefixIncrementUByteLocal(): Any? {
|
||||
var a: UByte = 0u
|
||||
return ++a
|
||||
}
|
||||
|
||||
fun prefixIncrementUShortLocal(): Any? {
|
||||
var a: UShort = 0u
|
||||
return ++a
|
||||
}
|
||||
|
||||
fun prefixIncrementUIntLocal(): Any? {
|
||||
var a: UInt = 0u
|
||||
return ++a
|
||||
}
|
||||
|
||||
fun prefixIncrementULongLocal(): Any? {
|
||||
var a: ULong = 0u
|
||||
return ++a
|
||||
}
|
||||
|
||||
var gb: UByte = 0u
|
||||
var gs: UShort = 0u
|
||||
var gi: UInt = 0u
|
||||
var gl: ULong = 0UL
|
||||
|
||||
fun prefixDecrementUByteProperty(): Any? {
|
||||
gb = 0u
|
||||
return --gb
|
||||
}
|
||||
|
||||
fun prefixDecrementUShortProperty(): Any? {
|
||||
gs = 0u
|
||||
return --gs
|
||||
}
|
||||
|
||||
fun prefixDecrementUIntProperty(): Any? {
|
||||
gi = 0u
|
||||
return --gi
|
||||
}
|
||||
|
||||
fun prefixDecrementULongProperty(): Any? {
|
||||
gl = 0u
|
||||
return --gl
|
||||
}
|
||||
|
||||
fun prefixIncrementUByteProperty(): Any? {
|
||||
gb = 0u
|
||||
return ++gb
|
||||
}
|
||||
|
||||
fun prefixIncrementUShortProperty(): Any? {
|
||||
gs = 0u
|
||||
return ++gs
|
||||
}
|
||||
|
||||
fun prefixIncrementUIntProperty(): Any? {
|
||||
gi = 0u
|
||||
return ++gi
|
||||
}
|
||||
|
||||
fun prefixIncrementULongProperty(): Any? {
|
||||
gl = 0u
|
||||
return ++gl
|
||||
}
|
||||
|
||||
fun check(u: Any?, ts: String, className: String) {
|
||||
u!!
|
||||
if (u.toString() != ts) throw AssertionError(u.toString())
|
||||
if (u.javaClass.name != className) throw AssertionError(u.javaClass.name)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
check(prefixDecrementUByteLocal(), 0xFFu.toString(), "kotlin.UByte")
|
||||
check(prefixDecrementUShortLocal(), 0xFFFFu.toString(), "kotlin.UShort")
|
||||
check(prefixDecrementUIntLocal(), 0xFFFF_FFFFu.toString(), "kotlin.UInt")
|
||||
check(prefixDecrementULongLocal(), 0xFFFF_FFFF_FFFF_FFFFUL.toString(), "kotlin.ULong")
|
||||
|
||||
check(prefixIncrementUByteLocal(), "1", "kotlin.UByte")
|
||||
check(prefixIncrementUShortLocal(), "1", "kotlin.UShort")
|
||||
check(prefixIncrementUIntLocal(), "1", "kotlin.UInt")
|
||||
check(prefixIncrementULongLocal(), "1", "kotlin.ULong")
|
||||
|
||||
check(prefixDecrementUByteProperty(), 0xFFu.toString(), "kotlin.UByte")
|
||||
check(prefixDecrementUShortProperty(), 0xFFFFu.toString(), "kotlin.UShort")
|
||||
check(prefixDecrementUIntProperty(), 0xFFFF_FFFFu.toString(), "kotlin.UInt")
|
||||
check(prefixDecrementULongProperty(), 0xFFFF_FFFF_FFFF_FFFFUL.toString(), "kotlin.ULong")
|
||||
|
||||
check(prefixIncrementUByteProperty(), "1", "kotlin.UByte")
|
||||
check(prefixIncrementUShortProperty(), "1", "kotlin.UShort")
|
||||
check(prefixIncrementUIntProperty(), "1", "kotlin.UInt")
|
||||
check(prefixIncrementULongProperty(), "1", "kotlin.ULong")
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+5
@@ -22020,6 +22020,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
runTest("compiler/testData/codegen/box/unsignedTypes/unsignedLiteralsWithSignedOverflow.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("unsignedTypePrefixIncrementDecrementBoxing.kt")
|
||||
public void testUnsignedTypePrefixIncrementDecrementBoxing() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/unsignedTypes/unsignedTypePrefixIncrementDecrementBoxing.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("unsignedTypeValuesInsideStringTemplates.kt")
|
||||
public void testUnsignedTypeValuesInsideStringTemplates() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/unsignedTypes/unsignedTypeValuesInsideStringTemplates.kt");
|
||||
|
||||
+5
@@ -22020,6 +22020,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
runTest("compiler/testData/codegen/box/unsignedTypes/unsignedLiteralsWithSignedOverflow.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("unsignedTypePrefixIncrementDecrementBoxing.kt")
|
||||
public void testUnsignedTypePrefixIncrementDecrementBoxing() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/unsignedTypes/unsignedTypePrefixIncrementDecrementBoxing.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("unsignedTypeValuesInsideStringTemplates.kt")
|
||||
public void testUnsignedTypeValuesInsideStringTemplates() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/unsignedTypes/unsignedTypeValuesInsideStringTemplates.kt");
|
||||
|
||||
+5
@@ -22020,6 +22020,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
runTest("compiler/testData/codegen/box/unsignedTypes/unsignedLiteralsWithSignedOverflow.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("unsignedTypePrefixIncrementDecrementBoxing.kt")
|
||||
public void testUnsignedTypePrefixIncrementDecrementBoxing() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/unsignedTypes/unsignedTypePrefixIncrementDecrementBoxing.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("unsignedTypeValuesInsideStringTemplates.kt")
|
||||
public void testUnsignedTypeValuesInsideStringTemplates() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/unsignedTypes/unsignedTypeValuesInsideStringTemplates.kt");
|
||||
|
||||
+5
@@ -19865,6 +19865,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
|
||||
runTest("compiler/testData/codegen/box/unsignedTypes/signedToUnsignedLiteralConversion.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("unsignedTypePrefixIncrementDecrementBoxing.kt")
|
||||
public void testUnsignedTypePrefixIncrementDecrementBoxing() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/unsignedTypes/unsignedTypePrefixIncrementDecrementBoxing.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("unsignedTypeValuesInsideStringTemplates.kt")
|
||||
public void testUnsignedTypeValuesInsideStringTemplates() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/unsignedTypes/unsignedTypeValuesInsideStringTemplates.kt");
|
||||
|
||||
+5
@@ -20925,6 +20925,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
||||
runTest("compiler/testData/codegen/box/unsignedTypes/signedToUnsignedLiteralConversion.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("unsignedTypePrefixIncrementDecrementBoxing.kt")
|
||||
public void testUnsignedTypePrefixIncrementDecrementBoxing() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/unsignedTypes/unsignedTypePrefixIncrementDecrementBoxing.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("unsignedTypeValuesInsideStringTemplates.kt")
|
||||
public void testUnsignedTypeValuesInsideStringTemplates() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/unsignedTypes/unsignedTypeValuesInsideStringTemplates.kt");
|
||||
|
||||
Reference in New Issue
Block a user