JvmDefault. Add deprecation warning for '-Xjvm-default=enable|compatibility' options

#KT-46329
This commit is contained in:
Mikhael Bogdanov
2021-12-02 16:01:06 +01:00
committed by Alexander Udalov
parent 42a465efe2
commit 8f60f73207
9 changed files with 42 additions and 1 deletions
@@ -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<String> by rootProject.extra
@@ -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)
@@ -0,0 +1,4 @@
$TESTDATA_DIR$/jvmDefaultAll.kt
-d
$TEMP_DIR$
-Xjvm-default=compatibility
+4
View File
@@ -0,0 +1,4 @@
interface Foo {
@JvmDefault
fun test() {}
}
+2
View File
@@ -0,0 +1,2 @@
warning: '-Xjvm-default=compatibility' is deprecated, please use '-Xjvm-default=all|all-compatibility'
OK
+4
View File
@@ -0,0 +1,4 @@
$TESTDATA_DIR$/jvmDefaultAll.kt
-d
$TEMP_DIR$
-Xjvm-default=enable
+4
View File
@@ -0,0 +1,4 @@
interface Foo {
@JvmDefault
fun test() {}
}
+2
View File
@@ -0,0 +1,2 @@
warning: '-Xjvm-default=enable' is deprecated, please use '-Xjvm-default=all|all-compatibility'
OK
@@ -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");