diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java index 23dec00c143..dbc558016be 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java @@ -3184,7 +3184,9 @@ public class ExpressionCodegen extends KtVisitor impleme } public void invokeAppend(KtExpression expr) { - if (expr instanceof KtBinaryExpression) { + ConstantValue compileTimeConstant = getPrimitiveOrStringCompileTimeConstant(expr, bindingContext); + + if (compileTimeConstant == null && expr instanceof KtBinaryExpression) { KtBinaryExpression binaryExpression = (KtBinaryExpression) expr; if (binaryExpression.getOperationToken() == KtTokens.PLUS) { KtExpression left = binaryExpression.getLeft(); @@ -3198,8 +3200,13 @@ public class ExpressionCodegen extends KtVisitor impleme } } } + Type exprType = expressionType(expr); - gen(expr, exprType); + if (compileTimeConstant != null) { + StackValue.constant(compileTimeConstant.getValue(), exprType).put(exprType, v); + } else { + gen(expr, exprType); + } genInvokeAppendMethod(v, exprType.getSort() == Type.ARRAY ? OBJECT_TYPE : exprType); } diff --git a/compiler/testData/codegen/bytecodeText/constants/partialString.kt b/compiler/testData/codegen/bytecodeText/constants/partialString.kt new file mode 100644 index 00000000000..783f5870f5d --- /dev/null +++ b/compiler/testData/codegen/bytecodeText/constants/partialString.kt @@ -0,0 +1,7 @@ +fun box(): String { + val z = 1; + return "O" + "K".toString() + z +} + +// 1 LDC "OK" +// 1 LDC \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java index 62dcf8832bc..f1a1c44b137 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java @@ -625,6 +625,12 @@ public class BytecodeTextTestGenerated extends AbstractBytecodeTextTest { doTest(fileName); } + @TestMetadata("partialString.kt") + public void testPartialString() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeText/constants/partialString.kt"); + doTest(fileName); + } + @TestMetadata("short.kt") public void testShort() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeText/constants/short.kt");