fix for several (unlikely all) closely related problems with handling of byte/short/char on Delvik #KT-2251 fixed
This commit is contained in:
@@ -535,4 +535,33 @@ public class CodegenUtil {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Type genIncrement(Type expectedType, int myDelta, InstructionAdapter v) {
|
||||
if (expectedType == Type.LONG_TYPE) {
|
||||
//noinspection UnnecessaryBoxing
|
||||
v.lconst(myDelta);
|
||||
}
|
||||
else if (expectedType == Type.FLOAT_TYPE) {
|
||||
//noinspection UnnecessaryBoxing
|
||||
v.fconst(myDelta);
|
||||
}
|
||||
else if (expectedType == Type.DOUBLE_TYPE) {
|
||||
//noinspection UnnecessaryBoxing
|
||||
v.dconst(myDelta);
|
||||
}
|
||||
else {
|
||||
v.iconst(myDelta);
|
||||
expectedType = Type.INT_TYPE;
|
||||
}
|
||||
v.add(expectedType);
|
||||
return expectedType;
|
||||
}
|
||||
|
||||
public static Type genNegate(Type expectedType, InstructionAdapter v) {
|
||||
if (expectedType == Type.BYTE_TYPE || expectedType == Type.SHORT_TYPE || expectedType == Type.CHAR_TYPE) {
|
||||
expectedType = Type.INT_TYPE;
|
||||
}
|
||||
v.neg(expectedType);
|
||||
return expectedType;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2683,23 +2683,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
||||
StackValue value = genQualified(receiver, operand);
|
||||
value.dupReceiver(v);
|
||||
value.put(asmType, v);
|
||||
if (asmType == Type.LONG_TYPE) {
|
||||
//noinspection UnnecessaryBoxing
|
||||
v.lconst(increment);
|
||||
}
|
||||
else if (asmType == Type.FLOAT_TYPE) {
|
||||
//noinspection UnnecessaryBoxing
|
||||
v.fconst(increment);
|
||||
}
|
||||
else if (asmType == Type.DOUBLE_TYPE) {
|
||||
//noinspection UnnecessaryBoxing
|
||||
v.dconst(increment);
|
||||
}
|
||||
else {
|
||||
v.iconst(increment);
|
||||
asmType = Type.INT_TYPE;
|
||||
}
|
||||
v.add(asmType);
|
||||
asmType = genIncrement(asmType, increment, v);
|
||||
value.store(asmType, v);
|
||||
}
|
||||
|
||||
|
||||
@@ -252,7 +252,7 @@ public abstract class StackValue {
|
||||
coerce(topOfStackType, this.type, v);
|
||||
}
|
||||
|
||||
protected static void coerce(Type fromType, Type toType, InstructionAdapter v) {
|
||||
public static void coerce(Type fromType, Type toType, InstructionAdapter v) {
|
||||
if (toType.equals(fromType)) return;
|
||||
|
||||
if (toType.getSort() == Type.VOID && fromType.getSort() != Type.VOID) {
|
||||
|
||||
@@ -70,30 +70,13 @@ public class Increment implements IntrinsicMethod {
|
||||
value.dupReceiver(v);
|
||||
|
||||
value.put(expectedType, v);
|
||||
plusMinus(v, expectedType);
|
||||
value.store(expectedType, v);
|
||||
value.store(CodegenUtil.genIncrement(expectedType, myDelta, v), v);
|
||||
value.put(expectedType, v);
|
||||
}
|
||||
else {
|
||||
receiver.put(expectedType, v);
|
||||
plusMinus(v, expectedType);
|
||||
StackValue.coerce(CodegenUtil.genIncrement(expectedType, myDelta, v), expectedType, v);
|
||||
}
|
||||
return StackValue.onStack(expectedType);
|
||||
}
|
||||
|
||||
private void plusMinus(InstructionAdapter v, Type expectedType) {
|
||||
if (expectedType == Type.LONG_TYPE) {
|
||||
v.lconst(myDelta);
|
||||
}
|
||||
else if (expectedType == Type.FLOAT_TYPE) {
|
||||
v.fconst(myDelta);
|
||||
}
|
||||
else if (expectedType == Type.DOUBLE_TYPE) {
|
||||
v.dconst(myDelta);
|
||||
}
|
||||
else {
|
||||
v.iconst(myDelta);
|
||||
}
|
||||
v.add(expectedType);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ public class UnaryMinus implements IntrinsicMethod {
|
||||
else {
|
||||
receiver.put(expectedType, v);
|
||||
}
|
||||
v.neg(expectedType);
|
||||
StackValue.coerce(CodegenUtil.genNegate(expectedType, v), expectedType, v);
|
||||
return StackValue.onStack(expectedType);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,10 @@
|
||||
class A(var b: Byte) {
|
||||
fun c(d: Short) = (b + d.toByte()).toChar()
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
if(A(10.toByte()).c(20.toShort()) != 30.toByte().toChar()) return "plus failed"
|
||||
|
||||
var x = 20.toByte()
|
||||
var y = 20.toByte()
|
||||
val foo = {
|
||||
|
||||
Reference in New Issue
Block a user