From beb3759f5a8e04b7dfc5fafd2166ae3cdbc03162 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Fri, 11 Nov 2022 12:52:40 +0100 Subject: [PATCH] Add jvm-abi-gen test on inline class with private ctor KT-54897 --- .../org/jetbrains/kotlin/jvm/abi/BaseJvmAbiTest.kt | 6 +++--- .../jvm/abi/CompileAgainstJvmAbiTestGenerated.java | 10 ++++++++++ .../abi/LegacyCompileAgainstJvmAbiTestGenerated.java | 10 ++++++++++ .../inlineClassWithPrivateConstructor/app/app.kt | 6 ++++++ .../inlineClassWithPrivateConstructor/lib/lib.kt | 8 ++++++++ .../inlineClassWithPrivateConstructorK2/app/app.kt | 6 ++++++ .../inlineClassWithPrivateConstructorK2/directives.txt | 2 ++ .../inlineClassWithPrivateConstructorK2/lib/lib.kt | 8 ++++++++ 8 files changed, 53 insertions(+), 3 deletions(-) create mode 100644 plugins/jvm-abi-gen/testData/compile/inlineClassWithPrivateConstructor/app/app.kt create mode 100644 plugins/jvm-abi-gen/testData/compile/inlineClassWithPrivateConstructor/lib/lib.kt create mode 100644 plugins/jvm-abi-gen/testData/compile/inlineClassWithPrivateConstructorK2/app/app.kt create mode 100644 plugins/jvm-abi-gen/testData/compile/inlineClassWithPrivateConstructorK2/directives.txt create mode 100644 plugins/jvm-abi-gen/testData/compile/inlineClassWithPrivateConstructorK2/lib/lib.kt diff --git a/plugins/jvm-abi-gen/test/org/jetbrains/kotlin/jvm/abi/BaseJvmAbiTest.kt b/plugins/jvm-abi-gen/test/org/jetbrains/kotlin/jvm/abi/BaseJvmAbiTest.kt index 83729ea90ae..5a4c03f2abf 100644 --- a/plugins/jvm-abi-gen/test/org/jetbrains/kotlin/jvm/abi/BaseJvmAbiTest.kt +++ b/plugins/jvm-abi-gen/test/org/jetbrains/kotlin/jvm/abi/BaseJvmAbiTest.kt @@ -67,7 +67,7 @@ abstract class BaseJvmAbiTest : TestCase() { dep.abiDir } - val directives = if (compilation.directives.exists()) compilation.directives.readText() else null + val directives = if (compilation.directives.exists()) compilation.directives.readText() else "" val messageCollector = LocationReportingTestMessageCollector() val compiler = K2JVMCompiler() @@ -80,8 +80,8 @@ abstract class BaseJvmAbiTest : TestCase() { if (useLegacyAbiGen) abiOption("useLegacyAbiGen", "true") else null ).toTypedArray() destination = compilation.destinationDir.canonicalPath - noSourceDebugExtension = - directives != null && InTextDirectivesUtils.findStringWithPrefixes(directives, "// NO_SOURCE_DEBUG_EXTENSION") != null + noSourceDebugExtension = InTextDirectivesUtils.findStringWithPrefixes(directives, "// NO_SOURCE_DEBUG_EXTENSION") != null + useK2 = InTextDirectivesUtils.findStringWithPrefixes(directives, "// USE_K2") != null } val exitCode = compiler.exec(messageCollector, Services.EMPTY, args) if (exitCode != ExitCode.OK || messageCollector.errors.isNotEmpty()) { diff --git a/plugins/jvm-abi-gen/test/org/jetbrains/kotlin/jvm/abi/CompileAgainstJvmAbiTestGenerated.java b/plugins/jvm-abi-gen/test/org/jetbrains/kotlin/jvm/abi/CompileAgainstJvmAbiTestGenerated.java index 74393528ec2..10cfbf11b3f 100644 --- a/plugins/jvm-abi-gen/test/org/jetbrains/kotlin/jvm/abi/CompileAgainstJvmAbiTestGenerated.java +++ b/plugins/jvm-abi-gen/test/org/jetbrains/kotlin/jvm/abi/CompileAgainstJvmAbiTestGenerated.java @@ -60,6 +60,16 @@ public class CompileAgainstJvmAbiTestGenerated extends AbstractCompileAgainstJvm runTest("plugins/jvm-abi-gen/testData/compile/inlineCapture/"); } + @TestMetadata("inlineClassWithPrivateConstructor") + public void testInlineClassWithPrivateConstructor() throws Exception { + runTest("plugins/jvm-abi-gen/testData/compile/inlineClassWithPrivateConstructor/"); + } + + @TestMetadata("inlineClassWithPrivateConstructorK2") + public void testInlineClassWithPrivateConstructorK2() throws Exception { + runTest("plugins/jvm-abi-gen/testData/compile/inlineClassWithPrivateConstructorK2/"); + } + @TestMetadata("inlineNoRegeneration") public void testInlineNoRegeneration() throws Exception { runTest("plugins/jvm-abi-gen/testData/compile/inlineNoRegeneration/"); diff --git a/plugins/jvm-abi-gen/test/org/jetbrains/kotlin/jvm/abi/LegacyCompileAgainstJvmAbiTestGenerated.java b/plugins/jvm-abi-gen/test/org/jetbrains/kotlin/jvm/abi/LegacyCompileAgainstJvmAbiTestGenerated.java index 85f4aacecb3..9e57d2bc0a1 100644 --- a/plugins/jvm-abi-gen/test/org/jetbrains/kotlin/jvm/abi/LegacyCompileAgainstJvmAbiTestGenerated.java +++ b/plugins/jvm-abi-gen/test/org/jetbrains/kotlin/jvm/abi/LegacyCompileAgainstJvmAbiTestGenerated.java @@ -60,6 +60,16 @@ public class LegacyCompileAgainstJvmAbiTestGenerated extends AbstractLegacyCompi runTest("plugins/jvm-abi-gen/testData/compile/inlineCapture/"); } + @TestMetadata("inlineClassWithPrivateConstructor") + public void testInlineClassWithPrivateConstructor() throws Exception { + runTest("plugins/jvm-abi-gen/testData/compile/inlineClassWithPrivateConstructor/"); + } + + @TestMetadata("inlineClassWithPrivateConstructorK2") + public void testInlineClassWithPrivateConstructorK2() throws Exception { + runTest("plugins/jvm-abi-gen/testData/compile/inlineClassWithPrivateConstructorK2/"); + } + @TestMetadata("inlineNoRegeneration") public void testInlineNoRegeneration() throws Exception { runTest("plugins/jvm-abi-gen/testData/compile/inlineNoRegeneration/"); diff --git a/plugins/jvm-abi-gen/testData/compile/inlineClassWithPrivateConstructor/app/app.kt b/plugins/jvm-abi-gen/testData/compile/inlineClassWithPrivateConstructor/app/app.kt new file mode 100644 index 00000000000..03748edc717 --- /dev/null +++ b/plugins/jvm-abi-gen/testData/compile/inlineClassWithPrivateConstructor/app/app.kt @@ -0,0 +1,6 @@ +package app + +import lib.* + +fun runAppAndReturnOk(): String = + IC.of("OK").value diff --git a/plugins/jvm-abi-gen/testData/compile/inlineClassWithPrivateConstructor/lib/lib.kt b/plugins/jvm-abi-gen/testData/compile/inlineClassWithPrivateConstructor/lib/lib.kt new file mode 100644 index 00000000000..5815c8842e5 --- /dev/null +++ b/plugins/jvm-abi-gen/testData/compile/inlineClassWithPrivateConstructor/lib/lib.kt @@ -0,0 +1,8 @@ +package lib + +@JvmInline +value class IC private constructor(val value: String) { + companion object { + fun of(value: String) = IC(value) + } +} diff --git a/plugins/jvm-abi-gen/testData/compile/inlineClassWithPrivateConstructorK2/app/app.kt b/plugins/jvm-abi-gen/testData/compile/inlineClassWithPrivateConstructorK2/app/app.kt new file mode 100644 index 00000000000..03748edc717 --- /dev/null +++ b/plugins/jvm-abi-gen/testData/compile/inlineClassWithPrivateConstructorK2/app/app.kt @@ -0,0 +1,6 @@ +package app + +import lib.* + +fun runAppAndReturnOk(): String = + IC.of("OK").value diff --git a/plugins/jvm-abi-gen/testData/compile/inlineClassWithPrivateConstructorK2/directives.txt b/plugins/jvm-abi-gen/testData/compile/inlineClassWithPrivateConstructorK2/directives.txt new file mode 100644 index 00000000000..50ffd8d8730 --- /dev/null +++ b/plugins/jvm-abi-gen/testData/compile/inlineClassWithPrivateConstructorK2/directives.txt @@ -0,0 +1,2 @@ +// USE_K2 +// IGNORE_BACKEND_LEGACY: JVM_IR diff --git a/plugins/jvm-abi-gen/testData/compile/inlineClassWithPrivateConstructorK2/lib/lib.kt b/plugins/jvm-abi-gen/testData/compile/inlineClassWithPrivateConstructorK2/lib/lib.kt new file mode 100644 index 00000000000..5815c8842e5 --- /dev/null +++ b/plugins/jvm-abi-gen/testData/compile/inlineClassWithPrivateConstructorK2/lib/lib.kt @@ -0,0 +1,8 @@ +package lib + +@JvmInline +value class IC private constructor(val value: String) { + companion object { + fun of(value: String) = IC(value) + } +}