From 8f60f73207dd08053610ca30f4f3098a007faac2 Mon Sep 17 00:00:00 2001 From: Mikhael Bogdanov Date: Thu, 2 Dec 2021 16:01:06 +0100 Subject: [PATCH] JvmDefault. Add deprecation warning for '-Xjvm-default=enable|compatibility' options #KT-46329 --- .../src/main/kotlin/common-configuration.gradle.kts | 4 ++++ .../src/org/jetbrains/kotlin/cli/jvm/jvmArguments.kt | 9 ++++++++- compiler/testData/cli/jvm/jvmDefaultCompatibility.args | 4 ++++ compiler/testData/cli/jvm/jvmDefaultCompatibility.kt | 4 ++++ compiler/testData/cli/jvm/jvmDefaultCompatibility.out | 2 ++ compiler/testData/cli/jvm/jvmDefaultEnable.args | 4 ++++ compiler/testData/cli/jvm/jvmDefaultEnable.kt | 4 ++++ compiler/testData/cli/jvm/jvmDefaultEnable.out | 2 ++ .../org/jetbrains/kotlin/cli/CliTestGenerated.java | 10 ++++++++++ 9 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 compiler/testData/cli/jvm/jvmDefaultCompatibility.args create mode 100644 compiler/testData/cli/jvm/jvmDefaultCompatibility.kt create mode 100644 compiler/testData/cli/jvm/jvmDefaultCompatibility.out create mode 100644 compiler/testData/cli/jvm/jvmDefaultEnable.args create mode 100644 compiler/testData/cli/jvm/jvmDefaultEnable.kt create mode 100644 compiler/testData/cli/jvm/jvmDefaultEnable.out diff --git a/buildSrc/src/main/kotlin/common-configuration.gradle.kts b/buildSrc/src/main/kotlin/common-configuration.gradle.kts index 2f931e000da..7d0431d5f3f 100644 --- a/buildSrc/src/main/kotlin/common-configuration.gradle.kts +++ b/buildSrc/src/main/kotlin/common-configuration.gradle.kts @@ -161,6 +161,10 @@ fun Project.configureKotlinCompilationOptions() { // TODO: fix remaining warnings and remove this property. val tasksWithWarnings = listOf( ":kotlin-gradle-plugin:compileCommonKotlin", + // Temporarily disable -Werror for the following modules because of deprecation warning for `-Xjvm-default=compatibility`. + // These modules should be removed after they are migrated to `-Xjvm-default=all/all-compatibility`. + ":compiler:frontend:compileKotlin", + ":kotlin-scripting-intellij:compileKotlin", ) val projectsWithEnabledContextReceivers: List by rootProject.extra 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 b9ab51bd4b4..0b683bc6512 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/jvmArguments.kt +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/jvmArguments.kt @@ -70,9 +70,9 @@ fun CompilerConfiguration.setupJvmSpecificArguments(arguments: K2JVMCompilerArgu } } + val jvmDefaultMode = languageVersionSettings.getFlag(JvmAnalysisFlags.jvmDefaultMode) val jvmTarget = get(JVMConfigurationKeys.JVM_TARGET) ?: JvmTarget.DEFAULT if (jvmTarget.majorVersion < JvmTarget.JVM_1_8.majorVersion) { - val jvmDefaultMode = languageVersionSettings.getFlag(JvmAnalysisFlags.jvmDefaultMode) if (jvmDefaultMode.forAllMethodsWithBody) { messageCollector.report( ERROR, @@ -81,6 +81,13 @@ fun CompilerConfiguration.setupJvmSpecificArguments(arguments: K2JVMCompilerArgu } } + if (jvmDefaultMode == JvmDefaultMode.ENABLE || jvmDefaultMode == JvmDefaultMode.ENABLE_WITH_DEFAULT_IMPLS) { + messageCollector.report( + WARNING, + "'-Xjvm-default=${jvmDefaultMode.description}' is deprecated, please use '-Xjvm-default=all|all-compatibility'" + ) + } + val stringConcat = arguments.stringConcat if (stringConcat != null) { val runtimeStringConcat = JvmStringConcat.fromString(stringConcat) diff --git a/compiler/testData/cli/jvm/jvmDefaultCompatibility.args b/compiler/testData/cli/jvm/jvmDefaultCompatibility.args new file mode 100644 index 00000000000..140dbf76a2c --- /dev/null +++ b/compiler/testData/cli/jvm/jvmDefaultCompatibility.args @@ -0,0 +1,4 @@ +$TESTDATA_DIR$/jvmDefaultAll.kt +-d +$TEMP_DIR$ +-Xjvm-default=compatibility diff --git a/compiler/testData/cli/jvm/jvmDefaultCompatibility.kt b/compiler/testData/cli/jvm/jvmDefaultCompatibility.kt new file mode 100644 index 00000000000..a1684d9ee69 --- /dev/null +++ b/compiler/testData/cli/jvm/jvmDefaultCompatibility.kt @@ -0,0 +1,4 @@ +interface Foo { + @JvmDefault + fun test() {} +} \ No newline at end of file diff --git a/compiler/testData/cli/jvm/jvmDefaultCompatibility.out b/compiler/testData/cli/jvm/jvmDefaultCompatibility.out new file mode 100644 index 00000000000..c7c30c52201 --- /dev/null +++ b/compiler/testData/cli/jvm/jvmDefaultCompatibility.out @@ -0,0 +1,2 @@ +warning: '-Xjvm-default=compatibility' is deprecated, please use '-Xjvm-default=all|all-compatibility' +OK diff --git a/compiler/testData/cli/jvm/jvmDefaultEnable.args b/compiler/testData/cli/jvm/jvmDefaultEnable.args new file mode 100644 index 00000000000..dbfa48c8b82 --- /dev/null +++ b/compiler/testData/cli/jvm/jvmDefaultEnable.args @@ -0,0 +1,4 @@ +$TESTDATA_DIR$/jvmDefaultAll.kt +-d +$TEMP_DIR$ +-Xjvm-default=enable diff --git a/compiler/testData/cli/jvm/jvmDefaultEnable.kt b/compiler/testData/cli/jvm/jvmDefaultEnable.kt new file mode 100644 index 00000000000..a1684d9ee69 --- /dev/null +++ b/compiler/testData/cli/jvm/jvmDefaultEnable.kt @@ -0,0 +1,4 @@ +interface Foo { + @JvmDefault + fun test() {} +} \ No newline at end of file diff --git a/compiler/testData/cli/jvm/jvmDefaultEnable.out b/compiler/testData/cli/jvm/jvmDefaultEnable.out new file mode 100644 index 00000000000..92b35bd5b12 --- /dev/null +++ b/compiler/testData/cli/jvm/jvmDefaultEnable.out @@ -0,0 +1,2 @@ +warning: '-Xjvm-default=enable' is deprecated, please use '-Xjvm-default=all|all-compatibility' +OK diff --git a/compiler/tests-gen/org/jetbrains/kotlin/cli/CliTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/cli/CliTestGenerated.java index 0495c9c47c7..2c1cf0cb12b 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/cli/CliTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/cli/CliTestGenerated.java @@ -649,6 +649,16 @@ public class CliTestGenerated extends AbstractCliTest { runTest("compiler/testData/cli/jvm/jvmDefaultAll.args"); } + @TestMetadata("jvmDefaultCompatibility.args") + public void testJvmDefaultCompatibility() throws Exception { + runTest("compiler/testData/cli/jvm/jvmDefaultCompatibility.args"); + } + + @TestMetadata("jvmDefaultEnable.args") + public void testJvmDefaultEnable() throws Exception { + runTest("compiler/testData/cli/jvm/jvmDefaultEnable.args"); + } + @TestMetadata("jvmIrByDefault1_4.args") public void testJvmIrByDefault1_4() throws Exception { runTest("compiler/testData/cli/jvm/jvmIrByDefault1_4.args");