提交 f64980a5 编写于 作者: D Denis.Zharkov

Add check for bytecode target when @JvmRecord is used

^KT-43677 In Progress
上级 b860a0c6
......@@ -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)
......
$TESTDATA_DIR$/jvmRecordWrongTarget.kt
-d
$TEMP_DIR$
-jdk-home
$JDK_15$
-XXLanguage:+JvmRecordSupport
-jvm-target
15_PREVIEW
@JvmRecord
data class MyRec(val name: String)
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
$TESTDATA_DIR$/jvmRecordWrongTarget.kt
-d
$TEMP_DIR$
-cp
$JDK_15$
-XXLanguage:+JvmRecordSupport
-jvm-target
9
@JvmRecord
data class MyRec(val name: String)
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
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
......@@ -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()
);
}
......
......@@ -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");
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册