Check target for -Xjvm-default modes

#KT-39925 Fixed
This commit is contained in:
Mikhail Bogdanov
2020-06-30 15:55:50 +02:00
parent 3e42b9d527
commit b5b5c8aebc
5 changed files with 27 additions and 0 deletions
@@ -38,6 +38,17 @@ fun CompilerConfiguration.setupJvmSpecificArguments(arguments: K2JVMCompilerArgu
}
}
val jvmTarget = get(JVMConfigurationKeys.JVM_TARGET) ?: JvmTarget.DEFAULT
if (jvmTarget.bytecodeVersion < JvmTarget.JVM_1_8.bytecodeVersion) {
val jvmDefaultMode = languageVersionSettings.getFlag(JvmAnalysisFlags.jvmDefaultMode)
if (jvmDefaultMode.forAllMethodsWithBody) {
messageCollector.report(
ERROR,
"'-Xjvm-default=${jvmDefaultMode.description}' is only supported since JVM target 1.8. Recompile with '-jvm-target 1.8'"
)
}
}
addAll(JVMConfigurationKeys.ADDITIONAL_JAVA_MODULES, arguments.additionalJavaModules?.asList())
}
+6
View File
@@ -0,0 +1,6 @@
$TESTDATA_DIR$/jvmDefaultAll.kt
-d
$TEMP_DIR$
-jvm-target
1.6
-Xjvm-default=all
+3
View File
@@ -0,0 +1,3 @@
interface Foo {
fun test() {}
}
+2
View File
@@ -0,0 +1,2 @@
error: '-Xjvm-default=all' is only supported since JVM target 1.8. Recompile with '-jvm-target 1.8'
COMPILATION_ERROR
@@ -475,6 +475,11 @@ public class CliTestGenerated extends AbstractCliTest {
runTest("compiler/testData/cli/jvm/jvm8Target.args");
}
@TestMetadata("jvmDefaultAll.args")
public void testJvmDefaultAll() throws Exception {
runTest("compiler/testData/cli/jvm/jvmDefaultAll.args");
}
@TestMetadata("kotlinHomeWithoutStdlib.args")
public void testKotlinHomeWithoutStdlib() throws Exception {
runTest("compiler/testData/cli/jvm/kotlinHomeWithoutStdlib.args");