diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/jvmArguments.kt b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/jvmArguments.kt index 992bf036778000aba2a352c7e2196ff6ac657325..87cd60448087e7f699490f095dcc26529ecb2f14 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/jvmArguments.kt +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/jvmArguments.kt @@ -67,9 +67,21 @@ fun CompilerConfiguration.setupJvmSpecificArguments(arguments: K2JVMCompilerArgu } } + if (languageVersionSettings.supportsFeature(LanguageFeature.JvmRecordSupport) && !jvmTarget.isRecordsAllowed()) { + messageCollector.report( + ERROR, + "-XXLanguage:+${LanguageFeature.JvmRecordSupport} feature is only supported with JVM target ${JvmTarget.JVM_15_PREVIEW.description} or later" + ) + } + addAll(JVMConfigurationKeys.ADDITIONAL_JAVA_MODULES, arguments.additionalJavaModules?.asList()) } +private fun JvmTarget.isRecordsAllowed(): Boolean { + if (majorVersion < JvmTarget.JVM_15_PREVIEW.majorVersion) return false + return isPreview || majorVersion > JvmTarget.JVM_15_PREVIEW.majorVersion +} + fun CompilerConfiguration.configureJdkHome(arguments: K2JVMCompilerArguments): Boolean { val messageCollector = getNotNull(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY) diff --git a/compiler/testData/cli/jvm/jvmRecordOk.args b/compiler/testData/cli/jvm/jvmRecordOk.args new file mode 100644 index 0000000000000000000000000000000000000000..f8aa7b4e60718408f4c45c2df7a149de3dab151d --- /dev/null +++ b/compiler/testData/cli/jvm/jvmRecordOk.args @@ -0,0 +1,8 @@ +$TESTDATA_DIR$/jvmRecordWrongTarget.kt +-d +$TEMP_DIR$ +-jdk-home +$JDK_15$ +-XXLanguage:+JvmRecordSupport +-jvm-target +15_PREVIEW diff --git a/compiler/testData/cli/jvm/jvmRecordOk.kt b/compiler/testData/cli/jvm/jvmRecordOk.kt new file mode 100644 index 0000000000000000000000000000000000000000..429d606052c530eb47475af399d1dd436d025c4d --- /dev/null +++ b/compiler/testData/cli/jvm/jvmRecordOk.kt @@ -0,0 +1,2 @@ +@JvmRecord +data class MyRec(val name: String) diff --git a/compiler/testData/cli/jvm/jvmRecordOk.out b/compiler/testData/cli/jvm/jvmRecordOk.out new file mode 100644 index 0000000000000000000000000000000000000000..ade09bd2ec2c2c32e9a786e10d2ff4fda62e38b8 --- /dev/null +++ b/compiler/testData/cli/jvm/jvmRecordOk.out @@ -0,0 +1,10 @@ +warning: ATTENTION! +This build uses unsafe internal compiler arguments: + +-XXLanguage:+JvmRecordSupport + +This mode is not recommended for production use, +as no stability/compatibility guarantees are given on +compiler or generated code. Use it at your own risk! + +OK diff --git a/compiler/testData/cli/jvm/jvmRecordWrongTarget.args b/compiler/testData/cli/jvm/jvmRecordWrongTarget.args new file mode 100644 index 0000000000000000000000000000000000000000..86dc212f348e57af72b5044422ceb6b09ea8a68a --- /dev/null +++ b/compiler/testData/cli/jvm/jvmRecordWrongTarget.args @@ -0,0 +1,8 @@ +$TESTDATA_DIR$/jvmRecordWrongTarget.kt +-d +$TEMP_DIR$ +-cp +$JDK_15$ +-XXLanguage:+JvmRecordSupport +-jvm-target +9 diff --git a/compiler/testData/cli/jvm/jvmRecordWrongTarget.kt b/compiler/testData/cli/jvm/jvmRecordWrongTarget.kt new file mode 100644 index 0000000000000000000000000000000000000000..429d606052c530eb47475af399d1dd436d025c4d --- /dev/null +++ b/compiler/testData/cli/jvm/jvmRecordWrongTarget.kt @@ -0,0 +1,2 @@ +@JvmRecord +data class MyRec(val name: String) diff --git a/compiler/testData/cli/jvm/jvmRecordWrongTarget.out b/compiler/testData/cli/jvm/jvmRecordWrongTarget.out new file mode 100644 index 0000000000000000000000000000000000000000..f4989fec672c4ecb639d9282ef353d8313b5353d --- /dev/null +++ b/compiler/testData/cli/jvm/jvmRecordWrongTarget.out @@ -0,0 +1,11 @@ +warning: ATTENTION! +This build uses unsafe internal compiler arguments: + +-XXLanguage:+JvmRecordSupport + +This mode is not recommended for production use, +as no stability/compatibility guarantees are given on +compiler or generated code. Use it at your own risk! + +error: -XXLanguage:+JvmRecordSupport feature is only supported with JVM target 15_PREVIEW or later +COMPILATION_ERROR diff --git a/compiler/testData/cli/jvm/wrongJvmTargetVersion.out b/compiler/testData/cli/jvm/wrongJvmTargetVersion.out index 7afaea0c1de5b42083f8ee1de20ce841a8112874..a7a87090cff26bf26bb7fe814af6f6a01658a5fe 100644 --- a/compiler/testData/cli/jvm/wrongJvmTargetVersion.out +++ b/compiler/testData/cli/jvm/wrongJvmTargetVersion.out @@ -1,3 +1,3 @@ error: unknown JVM target version: 1.5 -Supported versions: 1.6, 1.8, 9, 10, 11, 12, 13, 14, 15 +Supported versions: 1.6, 1.8, 9, 10, 11, 12, 13, 14, 15, 15_PREVIEW COMPILATION_ERROR diff --git a/compiler/tests-common/tests/org/jetbrains/kotlin/cli/AbstractCliTest.java b/compiler/tests-common/tests/org/jetbrains/kotlin/cli/AbstractCliTest.java index 43f98edda4c540043c54949407f5075571d5d887..088dabfa2bf72d365f3810133805080a0369f041 100644 --- a/compiler/tests-common/tests/org/jetbrains/kotlin/cli/AbstractCliTest.java +++ b/compiler/tests-common/tests/org/jetbrains/kotlin/cli/AbstractCliTest.java @@ -261,6 +261,9 @@ public abstract class AbstractCliTest extends TestCaseWithTmpdir { .replace( "$FOREIGN_ANNOTATIONS_DIR$", new File(AbstractForeignAnnotationsTestKt.getFOREIGN_ANNOTATIONS_SOURCES_PATH()).getPath() + ).replace( + "$JDK_15$", + KotlinTestUtils.getJdk15Home().getPath() ); } diff --git a/compiler/tests-gen/org/jetbrains/kotlin/cli/CliTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/cli/CliTestGenerated.java index 9c8ee054464f479e10f3221e1d87bc41d8d5be0e..0887e77bfdd3339fca9ebfb59832ae997768a785 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/cli/CliTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/cli/CliTestGenerated.java @@ -530,6 +530,16 @@ public class CliTestGenerated extends AbstractCliTest { runTest("compiler/testData/cli/jvm/jvmDefaultAll.args"); } + @TestMetadata("jvmRecordOk.args") + public void testJvmRecordOk() throws Exception { + runTest("compiler/testData/cli/jvm/jvmRecordOk.args"); + } + + @TestMetadata("jvmRecordWrongTarget.args") + public void testJvmRecordWrongTarget() throws Exception { + runTest("compiler/testData/cli/jvm/jvmRecordWrongTarget.args"); + } + @TestMetadata("kotlinHomeWithoutStdlib.args") public void testKotlinHomeWithoutStdlib() throws Exception { runTest("compiler/testData/cli/jvm/kotlinHomeWithoutStdlib.args");