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 120664b1046..056412f5188 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/jvmArguments.kt +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/jvmArguments.kt @@ -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()) } diff --git a/compiler/testData/cli/jvm/jvmDefaultAll.args b/compiler/testData/cli/jvm/jvmDefaultAll.args new file mode 100644 index 00000000000..a7c934a1c3c --- /dev/null +++ b/compiler/testData/cli/jvm/jvmDefaultAll.args @@ -0,0 +1,6 @@ +$TESTDATA_DIR$/jvmDefaultAll.kt +-d +$TEMP_DIR$ +-jvm-target +1.6 +-Xjvm-default=all diff --git a/compiler/testData/cli/jvm/jvmDefaultAll.kt b/compiler/testData/cli/jvm/jvmDefaultAll.kt new file mode 100644 index 00000000000..1f5c7ebed50 --- /dev/null +++ b/compiler/testData/cli/jvm/jvmDefaultAll.kt @@ -0,0 +1,3 @@ +interface Foo { + fun test() {} +} \ No newline at end of file diff --git a/compiler/testData/cli/jvm/jvmDefaultAll.out b/compiler/testData/cli/jvm/jvmDefaultAll.out new file mode 100644 index 00000000000..9d661afc460 --- /dev/null +++ b/compiler/testData/cli/jvm/jvmDefaultAll.out @@ -0,0 +1,2 @@ +error: '-Xjvm-default=all' is only supported since JVM target 1.8. Recompile with '-jvm-target 1.8' +COMPILATION_ERROR diff --git a/compiler/tests/org/jetbrains/kotlin/cli/CliTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/cli/CliTestGenerated.java index 075d1d727a9..40cf8ebb0bf 100644 --- a/compiler/tests/org/jetbrains/kotlin/cli/CliTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/cli/CliTestGenerated.java @@ -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");