diff --git a/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java b/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java index f33c7fbec65..76ad6058507 100644 --- a/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java @@ -30208,6 +30208,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT runTest("compiler/testData/codegen/box/strings/kt3652.kt"); } + @TestMetadata("kt42457_old.kt") + public void testKt42457_old() throws Exception { + runTest("compiler/testData/codegen/box/strings/kt42457_old.kt"); + } + @TestMetadata("kt5389_stringBuilderGet.kt") public void testKt5389_stringBuilderGet() throws Exception { runTest("compiler/testData/codegen/box/strings/kt5389_stringBuilderGet.kt"); diff --git a/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBytecodeTextTestGenerated.java b/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBytecodeTextTestGenerated.java index ca755f534a0..9be9c38a36a 100644 --- a/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBytecodeTextTestGenerated.java +++ b/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBytecodeTextTestGenerated.java @@ -4551,6 +4551,11 @@ public class FirBytecodeTextTestGenerated extends AbstractFirBytecodeTextTest { runTest("compiler/testData/codegen/bytecodeText/stringOperations/kt19037.kt"); } + @TestMetadata("kt42457_old.kt") + public void testKt42457_old() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/stringOperations/kt42457_old.kt"); + } + @TestMetadata("multipleNestedConcat.kt") public void testMultipleNestedConcat() throws Exception { runTest("compiler/testData/codegen/bytecodeText/stringOperations/multipleNestedConcat.kt"); diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/JvmStringConcatenationLowering.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/JvmStringConcatenationLowering.kt index 08103946c82..0033b7f068d 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/JvmStringConcatenationLowering.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/JvmStringConcatenationLowering.kt @@ -193,6 +193,9 @@ private class JvmDynamicStringConcatenationLowering(val context: JvmBackendConte arguments.isEmpty() -> irString("") + arguments.size == 1 -> + lowerInlineClassArgument(arguments[0]) ?: callToString(arguments[0].unwrapImplicitNotNull()) + else -> { IrStringConcatenationImpl( expression.startOffset, diff --git a/compiler/testData/codegen/box/strings/kt42457_old.kt b/compiler/testData/codegen/box/strings/kt42457_old.kt new file mode 100644 index 00000000000..c789403af6f --- /dev/null +++ b/compiler/testData/codegen/box/strings/kt42457_old.kt @@ -0,0 +1,17 @@ +// TARGET_BACKEND: JVM +// FILE: JavaClass.java + +public class JavaClass { + public String toString() { + return null; + } +} + +// FILE: Kotlin.kt +fun box(): String { + val toString: String? = JavaClass().toString() + if (toString != null) return "fail 1: $toString" + val template: String? = "${JavaClass()}" + if (template != null) return "fail 2: $template" + return "OK" +} \ No newline at end of file diff --git a/compiler/testData/codegen/bytecodeText/stringOperations/kt42457_old.kt b/compiler/testData/codegen/bytecodeText/stringOperations/kt42457_old.kt new file mode 100644 index 00000000000..e68d1e1070a --- /dev/null +++ b/compiler/testData/codegen/bytecodeText/stringOperations/kt42457_old.kt @@ -0,0 +1,20 @@ +// IGNORE_BACKEND_FIR: JVM_IR +// KOTLIN_CONFIGURATION_FLAGS: STRING_CONCAT=indy-with-constants +// JVM_TARGET: 9 +// FILE: JavaClass.java + +public class JavaClass { + public String toString() { + return null; + } +} + +// FILE: Kotlin.kt +fun box() { + val toString: String? = JavaClass().toString() + val template: String = "${JavaClass()}" +} +// 0 INVOKEDYNAMIC makeConcat +// 1 JavaClass.toString +// 1 String.valueOf +// 0 append \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index 05364dafe47..05c48befa66 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -31974,6 +31974,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/strings/kt3652.kt"); } + @TestMetadata("kt42457_old.kt") + public void testKt42457_old() throws Exception { + runTest("compiler/testData/codegen/box/strings/kt42457_old.kt"); + } + @TestMetadata("kt5389_stringBuilderGet.kt") public void testKt5389_stringBuilderGet() throws Exception { runTest("compiler/testData/codegen/box/strings/kt5389_stringBuilderGet.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java index d8e508499f3..37ec2ef2a38 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java @@ -4583,6 +4583,11 @@ public class BytecodeTextTestGenerated extends AbstractBytecodeTextTest { runTest("compiler/testData/codegen/bytecodeText/stringOperations/kt19037.kt"); } + @TestMetadata("kt42457_old.kt") + public void testKt42457_old() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/stringOperations/kt42457_old.kt"); + } + @TestMetadata("multipleNestedConcat.kt") public void testMultipleNestedConcat() throws Exception { runTest("compiler/testData/codegen/bytecodeText/stringOperations/multipleNestedConcat.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index 9370cc7962b..22a216d5722 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -29608,6 +29608,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/strings/kt3652.kt"); } + @TestMetadata("kt42457_old.kt") + public void testKt42457_old() throws Exception { + runTest("compiler/testData/codegen/box/strings/kt42457_old.kt"); + } + @TestMetadata("kt5389_stringBuilderGet.kt") public void testKt5389_stringBuilderGet() throws Exception { runTest("compiler/testData/codegen/box/strings/kt5389_stringBuilderGet.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java index ce703a9799c..0becd10427b 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java @@ -30208,6 +30208,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/strings/kt3652.kt"); } + @TestMetadata("kt42457_old.kt") + public void testKt42457_old() throws Exception { + runTest("compiler/testData/codegen/box/strings/kt42457_old.kt"); + } + @TestMetadata("kt5389_stringBuilderGet.kt") public void testKt5389_stringBuilderGet() throws Exception { runTest("compiler/testData/codegen/box/strings/kt5389_stringBuilderGet.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBytecodeTextTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBytecodeTextTestGenerated.java index e1de45453b3..ae776490f81 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBytecodeTextTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBytecodeTextTestGenerated.java @@ -4551,6 +4551,11 @@ public class IrBytecodeTextTestGenerated extends AbstractIrBytecodeTextTest { runTest("compiler/testData/codegen/bytecodeText/stringOperations/kt19037.kt"); } + @TestMetadata("kt42457_old.kt") + public void testKt42457_old() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/stringOperations/kt42457_old.kt"); + } + @TestMetadata("multipleNestedConcat.kt") public void testMultipleNestedConcat() throws Exception { runTest("compiler/testData/codegen/bytecodeText/stringOperations/multipleNestedConcat.kt");