Fix for KT-4301: Too many StringBuilders on string concatenations

#KT-4301 Fixed
This commit is contained in:
Michael Bogdanov
2014-10-08 17:43:26 +04:00
parent 4a078c1143
commit d4307c69d2
5 changed files with 45 additions and 2 deletions
@@ -3043,9 +3043,8 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
JetExpression left = binaryExpression.getLeft();
JetExpression right = binaryExpression.getRight();
Type leftType = expressionType(left);
Type rightType = expressionType(right);
if (leftType.equals(JAVA_STRING_TYPE) && rightType.equals(JAVA_STRING_TYPE)) {
if (leftType.equals(JAVA_STRING_TYPE)) {
invokeAppend(left);
invokeAppend(right);
return;
@@ -0,0 +1,16 @@
class A() {
override fun toString(): String {
return "A"
}
}
fun box() : String {
val s = "1" + "2" + 3 + 4L + 5.0 + 6F + '7' + A()
if (s != "12345.06.07A") return "fail $s"
return "OK"
}
@@ -0,0 +1,16 @@
class A() {
override fun toString(): String {
return "A"
}
}
fun box() : String {
val s = "1" + "2" + 3 + 4L + 5.0 + 6F + '7' + A()
return s
}
// 1 NEW java/lang/StringBuilder
@@ -177,6 +177,12 @@ public class BytecodeTextTestGenerated extends AbstractBytecodeTextTest {
doTest(fileName);
}
@TestMetadata("stringBuilderAppend.kt")
public void testStringBuilderAppend() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeText/stringBuilderAppend.kt");
doTest(fileName);
}
@TestMetadata("topLevelFunWithDefaultArgs.kt")
public void testTopLevelFunWithDefaultArgs() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeText/topLevelFunWithDefaultArgs.kt");
@@ -5990,6 +5990,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
doTest(fileName);
}
@TestMetadata("stringBuilderAppend.kt")
public void testStringBuilderAppend() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/strings/stringBuilderAppend.kt");
doTest(fileName);
}
}
@TestMetadata("compiler/testData/codegen/box/super")