Skip empty string entries when generating string template expression

#KT-19738 Fixed Target versions 1.2.50
This commit is contained in:
Dmitry Petrov
2018-03-14 14:15:28 +03:00
parent 22c2d8b563
commit 54cf11fd0a
3 changed files with 13 additions and 1 deletions
@@ -875,7 +875,10 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
constantValue.append(String.valueOf(compileTimeConstant.getValue()));
}
else {
result.add(new StringTemplateEntry.Constant(constantValue.toString()));
String accumulatedConstantValue = constantValue.toString();
if (accumulatedConstantValue.length() > 0) {
result.add(new StringTemplateEntry.Constant(accumulatedConstantValue));
}
constantValue.setLength(0);
result.add(new StringTemplateEntry.Expression(entryExpression));
@@ -0,0 +1,3 @@
fun test(foo: Int) = "${foo}bar"
// 0 LDC ""
@@ -2557,6 +2557,12 @@ public class BytecodeTextTestGenerated extends AbstractBytecodeTextTest {
runTest("compiler/testData/codegen/bytecodeText/stringOperations/concat.kt");
}
@TestMetadata("doNotAppendEmptyString.kt")
public void testDoNotAppendEmptyString() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeText/stringOperations/doNotAppendEmptyString.kt");
doTest(fileName);
}
@TestMetadata("interpolation.kt")
public void testInterpolation() throws Exception {
runTest("compiler/testData/codegen/bytecodeText/stringOperations/interpolation.kt");