call correct methods String.valueOf/StringBuilder.append in case of byte/short. #KT-2794 fixed
This commit is contained in:
@@ -28,7 +28,6 @@ import org.jetbrains.asm4.Label;
|
|||||||
import org.jetbrains.asm4.MethodVisitor;
|
import org.jetbrains.asm4.MethodVisitor;
|
||||||
import org.jetbrains.asm4.Type;
|
import org.jetbrains.asm4.Type;
|
||||||
import org.jetbrains.asm4.commons.InstructionAdapter;
|
import org.jetbrains.asm4.commons.InstructionAdapter;
|
||||||
import org.jetbrains.asm4.commons.Method;
|
|
||||||
import org.jetbrains.jet.codegen.binding.CalculatedClosure;
|
import org.jetbrains.jet.codegen.binding.CalculatedClosure;
|
||||||
import org.jetbrains.jet.codegen.signature.BothSignatureWriter;
|
import org.jetbrains.jet.codegen.signature.BothSignatureWriter;
|
||||||
import org.jetbrains.jet.codegen.signature.JvmMethodParameterKind;
|
import org.jetbrains.jet.codegen.signature.JvmMethodParameterKind;
|
||||||
@@ -51,7 +50,8 @@ import java.util.*;
|
|||||||
|
|
||||||
import static org.jetbrains.asm4.Opcodes.*;
|
import static org.jetbrains.asm4.Opcodes.*;
|
||||||
import static org.jetbrains.jet.lang.resolve.DescriptorUtils.isClassObject;
|
import static org.jetbrains.jet.lang.resolve.DescriptorUtils.isClassObject;
|
||||||
import static org.jetbrains.jet.lang.resolve.java.AsmTypeConstants.*;
|
import static org.jetbrains.jet.lang.resolve.java.AsmTypeConstants.JAVA_STRING_TYPE;
|
||||||
|
import static org.jetbrains.jet.lang.resolve.java.AsmTypeConstants.OBJECT_TYPE;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author abreslav
|
* @author abreslav
|
||||||
@@ -380,23 +380,25 @@ public class CodegenUtil {
|
|||||||
v.invokespecial("java/lang/StringBuilder", "<init>", "()V");
|
v.invokespecial("java/lang/StringBuilder", "<init>", "()V");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void invokeAppendMethod(InstructionAdapter v, Type exprType) {
|
public static void invokeAppendMethod(InstructionAdapter v, Type type) {
|
||||||
Method appendDescriptor = new Method("append", getType(StringBuilder.class),
|
type = getStringValueOfOrStringBuilderAppendType(type);
|
||||||
new Type[] {exprType.getSort() == Type.OBJECT ? (exprType.equals(JAVA_STRING_TYPE) ? JAVA_STRING_TYPE : OBJECT_TYPE) : exprType});
|
v.invokevirtual("java/lang/StringBuilder", "append", "(" + type.getDescriptor() + ")Ljava/lang/StringBuilder;");
|
||||||
v.invokevirtual("java/lang/StringBuilder", "append", appendDescriptor.getDescriptor());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static StackValue genToString(InstructionAdapter v, StackValue receiver) {
|
public static StackValue genToString(InstructionAdapter v, StackValue receiver) {
|
||||||
final int sort = receiver.type.getSort();
|
final Type type = getStringValueOfOrStringBuilderAppendType(receiver.type);
|
||||||
|
|
||||||
final Type type = sort == Type.OBJECT || sort == Type.ARRAY
|
|
||||||
? AsmTypeConstants.OBJECT_TYPE
|
|
||||||
: sort == Type.BYTE || sort == Type.SHORT ? Type.INT_TYPE : receiver.type;
|
|
||||||
receiver.put(type, v);
|
receiver.put(type, v);
|
||||||
v.invokestatic("java/lang/String", "valueOf", "(" + type.getDescriptor() + ")Ljava/lang/String;");
|
v.invokestatic("java/lang/String", "valueOf", "(" + type.getDescriptor() + ")Ljava/lang/String;");
|
||||||
return StackValue.onStack(JAVA_STRING_TYPE);
|
return StackValue.onStack(JAVA_STRING_TYPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static Type getStringValueOfOrStringBuilderAppendType(Type type) {
|
||||||
|
final int sort = type.getSort();
|
||||||
|
return sort == Type.OBJECT || sort == Type.ARRAY
|
||||||
|
? AsmTypeConstants.OBJECT_TYPE
|
||||||
|
: sort == Type.BYTE || sort == Type.SHORT ? Type.INT_TYPE : type;
|
||||||
|
}
|
||||||
|
|
||||||
static void genHashCode(MethodVisitor mv, InstructionAdapter iv, Type type) {
|
static void genHashCode(MethodVisitor mv, InstructionAdapter iv, Type type) {
|
||||||
if (type.getSort() == Type.ARRAY) {
|
if (type.getSort() == Type.ARRAY) {
|
||||||
final Type elementType = correctElementType(type);
|
final Type elementType = correctElementType(type);
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
fun box () : String {
|
||||||
|
val b = 4.toByte()
|
||||||
|
val s = 5.toShort()
|
||||||
|
val c: Char = 'A'
|
||||||
|
return if( "$b" == "4" && " $b" == " 4" && "$s" == "5" && " $s" == " 5" && "$c" == "A" && " $c" == " A") "OK" else "fail"
|
||||||
|
}
|
||||||
@@ -451,6 +451,9 @@ public class PrimitiveTypesTest extends CodegenTestCase {
|
|||||||
|
|
||||||
public void test2251() throws Exception {
|
public void test2251() throws Exception {
|
||||||
blackBoxFile("regressions/kt2251.kt");
|
blackBoxFile("regressions/kt2251.kt");
|
||||||
System.out.println(generateToText());
|
}
|
||||||
|
|
||||||
|
public void test2794() throws Exception {
|
||||||
|
blackBoxFile("regressions/kt2794.kt");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user