From 134fda8bad8d8e1cd6da49e3d298a9f6e11a6104 Mon Sep 17 00:00:00 2001 From: Mikhael Bogdanov Date: Wed, 17 Feb 2021 11:07:28 +0100 Subject: [PATCH] Support Unit/V types in string-concat indy calls unitComponent.kt test fails with JVM target 9+ --- .../codegen/FirBytecodeTextTestGenerated.java | 6 ++++ .../backend/jvm/codegen/ExpressionCodegen.kt | 5 ++-- .../stringOperations/concatDynamicUnit.kt | 28 +++++++++++++++++++ .../codegen/BytecodeTextTestGenerated.java | 6 ++++ .../codegen/IrBytecodeTextTestGenerated.java | 6 ++++ 5 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 compiler/testData/codegen/bytecodeText/stringOperations/concatDynamicUnit.kt diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBytecodeTextTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBytecodeTextTestGenerated.java index 2c1a4d39e5c..85754daa4a0 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBytecodeTextTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBytecodeTextTestGenerated.java @@ -5080,6 +5080,12 @@ public class FirBytecodeTextTestGenerated extends AbstractFirBytecodeTextTest { runTest("compiler/testData/codegen/bytecodeText/stringOperations/concatDynamicIndyDataClass.kt"); } + @Test + @TestMetadata("concatDynamicUnit.kt") + public void testConcatDynamicUnit() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/stringOperations/concatDynamicUnit.kt"); + } + @Test @TestMetadata("concatNotDynamic.kt") public void testConcatNotDynamic() throws Exception { diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/ExpressionCodegen.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/ExpressionCodegen.kt index 1ae7b43c724..11790f03c22 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/ExpressionCodegen.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/ExpressionCodegen.kt @@ -1283,8 +1283,9 @@ class ExpressionCodegen( generator.putValueOrProcessConstant(StackValue.constant(arg.value, type, null)) } else { val value = arg.accept(this, data) - value.materializeAt(value.type, value.irType) - generator.invokeAppend(value.type) + val generatingType = if (value.type == Type.VOID_TYPE) AsmTypes.UNIT_TYPE else value.type + value.materializeAt(generatingType, value.irType) + generator.invokeAppend(generatingType) } } generator.genToString() diff --git a/compiler/testData/codegen/bytecodeText/stringOperations/concatDynamicUnit.kt b/compiler/testData/codegen/bytecodeText/stringOperations/concatDynamicUnit.kt new file mode 100644 index 00000000000..1d2a5d39a42 --- /dev/null +++ b/compiler/testData/codegen/bytecodeText/stringOperations/concatDynamicUnit.kt @@ -0,0 +1,28 @@ +// JVM_TARGET: 9 +data class A(val x: Unit) + +fun test(): Unit {} + +interface B { + fun test() : T { + return null!! + } +} + +class Foo : B { + +} + +fun box(): String { + val a = A(Unit) + + val test = "Test ${a.component1()} ${test()} ${Foo().test()}" + return "OK" +} +// one in data class `toString` and one in `box` method +// 2 INVOKEDYNAMIC makeConcatWithConstants +// 1 makeConcatWithConstants\(Lkotlin/Unit;\) +// 1 makeConcatWithConstants\(Lkotlin/Unit;Lkotlin/Unit;Lkotlin/Unit;\) +// 0 append +// 0 stringPlus + diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BytecodeTextTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BytecodeTextTestGenerated.java index ae3c56d5cfd..8129e3d2031 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BytecodeTextTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BytecodeTextTestGenerated.java @@ -4948,6 +4948,12 @@ public class BytecodeTextTestGenerated extends AbstractBytecodeTextTest { runTest("compiler/testData/codegen/bytecodeText/stringOperations/concatDynamicIndyDataClass.kt"); } + @Test + @TestMetadata("concatDynamicUnit.kt") + public void testConcatDynamicUnit() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/stringOperations/concatDynamicUnit.kt"); + } + @Test @TestMetadata("concatNotDynamic.kt") public void testConcatNotDynamic() throws Exception { diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBytecodeTextTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBytecodeTextTestGenerated.java index 05696042ddd..e2bc8b6d9f3 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBytecodeTextTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBytecodeTextTestGenerated.java @@ -5080,6 +5080,12 @@ public class IrBytecodeTextTestGenerated extends AbstractIrBytecodeTextTest { runTest("compiler/testData/codegen/bytecodeText/stringOperations/concatDynamicIndyDataClass.kt"); } + @Test + @TestMetadata("concatDynamicUnit.kt") + public void testConcatDynamicUnit() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/stringOperations/concatDynamicUnit.kt"); + } + @Test @TestMetadata("concatNotDynamic.kt") public void testConcatNotDynamic() throws Exception {