diff --git a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/CommonCompilerArguments.kt b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/CommonCompilerArguments.kt index 01ccc960b0d..97a98b5bfc3 100644 --- a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/CommonCompilerArguments.kt +++ b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/CommonCompilerArguments.kt @@ -531,9 +531,9 @@ abstract class CommonCompilerArguments : CommonToolArguments() { } fun toLanguageVersionSettings(collector: MessageCollector): LanguageVersionSettings { - // If only "-api-version" is specified, language version is assumed to be the latest stable - val languageVersion = parseVersion(collector, languageVersion, "language") ?: LanguageVersion.LATEST_STABLE + val languageVersion = parseVersion(collector, languageVersion, "language") + ?: defaultLanguageVersion(collector) // If only "-language-version" is specified, API version is assumed to be equal to the language version // (API version cannot be greater than the language version) @@ -554,6 +554,8 @@ abstract class CommonCompilerArguments : CommonToolArguments() { checkProgressiveMode(languageVersion, collector) } + checkPlatformSpecificSettings(languageVersionSettings, collector) + return languageVersionSettings } @@ -622,6 +624,12 @@ abstract class CommonCompilerArguments : CommonToolArguments() { } } + protected open fun defaultLanguageVersion(collector: MessageCollector): LanguageVersion = + LanguageVersion.LATEST_STABLE + + protected open fun checkPlatformSpecificSettings(languageVersionSettings: LanguageVersionSettings, collector: MessageCollector) { + } + private enum class VersionKind(val text: String) { LANGUAGE("Language"), API("API") } diff --git a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JVMCompilerArguments.kt b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JVMCompilerArguments.kt index e55a8b738a9..4049319eb10 100644 --- a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JVMCompilerArguments.kt +++ b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JVMCompilerArguments.kt @@ -534,4 +534,26 @@ default: `indy-with-constants` for JVM target 9 or greater, `inline` otherwise"" } return result } + + override fun defaultLanguageVersion(collector: MessageCollector): LanguageVersion = + if (useOldBackend) { + if (!suppressVersionWarnings) { + collector.report( + CompilerMessageSeverity.STRONG_WARNING, + "Language version is automatically inferred to ${LanguageVersion.KOTLIN_1_5.versionString} when using " + + "the old JVM backend. Consider specifying -language-version explicitly, or remove -Xuse-old-backend" + ) + } + LanguageVersion.KOTLIN_1_5 + } else super.defaultLanguageVersion(collector) + + override fun checkPlatformSpecificSettings(languageVersionSettings: LanguageVersionSettings, collector: MessageCollector) { + if (useOldBackend && languageVersionSettings.languageVersion >= LanguageVersion.KOTLIN_1_6) { + collector.report( + CompilerMessageSeverity.ERROR, + "Old JVM backend does not support language version 1.6 or above. " + + "Please use language version 1.5 or below, or remove -Xuse-old-backend" + ) + } + } } diff --git a/compiler/testData/cli/jvm/abiStabilityUnstableWithOldBackend.out b/compiler/testData/cli/jvm/abiStabilityUnstableWithOldBackend.out index 6a1292baf11..ce1c49c4e1c 100644 --- a/compiler/testData/cli/jvm/abiStabilityUnstableWithOldBackend.out +++ b/compiler/testData/cli/jvm/abiStabilityUnstableWithOldBackend.out @@ -1,3 +1,4 @@ +warning: language version is automatically inferred to 1.5 when using the old JVM backend. Consider specifying -language-version explicitly, or remove -Xuse-old-backend warning: -Xuse-old-backend is deprecated and will be removed in a future release error: -Xabi-stability=unstable is not supported in the old JVM backend COMPILATION_ERROR diff --git a/compiler/testData/cli/jvm/bothJvmIrAndOldBackend.args b/compiler/testData/cli/jvm/bothJvmIrAndOldBackend.args index aaa2e4e226f..2af4fe0d60f 100644 --- a/compiler/testData/cli/jvm/bothJvmIrAndOldBackend.args +++ b/compiler/testData/cli/jvm/bothJvmIrAndOldBackend.args @@ -3,3 +3,5 @@ $TESTDATA_DIR$/simple.kt $TEMP_DIR$ -Xuse-ir -Xuse-old-backend +-language-version +1.5 diff --git a/compiler/testData/cli/jvm/classAndTraitClash.args b/compiler/testData/cli/jvm/classAndTraitClash.args index a5a7cfcb7f4..6ed43fe597e 100644 --- a/compiler/testData/cli/jvm/classAndTraitClash.args +++ b/compiler/testData/cli/jvm/classAndTraitClash.args @@ -2,3 +2,5 @@ $TESTDATA_DIR$/classAndTraitClash.kt -d $TEMP_DIR$ -Xuse-old-backend +-language-version +1.5 diff --git a/compiler/testData/cli/jvm/oldBackendLv16.args b/compiler/testData/cli/jvm/oldBackendLv16.args new file mode 100644 index 00000000000..b04d96186ae --- /dev/null +++ b/compiler/testData/cli/jvm/oldBackendLv16.args @@ -0,0 +1,6 @@ +$TESTDATA_DIR$/simple.kt +-d +$TEMP_DIR$ +-Xuse-old-backend +-language-version +1.6 diff --git a/compiler/testData/cli/jvm/oldBackendLv16.out b/compiler/testData/cli/jvm/oldBackendLv16.out new file mode 100644 index 00000000000..ed485d5266d --- /dev/null +++ b/compiler/testData/cli/jvm/oldBackendLv16.out @@ -0,0 +1,2 @@ +error: old JVM backend does not support language version 1.6 or above. Please use language version 1.5 or below, or remove -Xuse-old-backend +COMPILATION_ERROR diff --git a/compiler/testData/cli/jvm/suspendInFunInterfaceIrDisabled.args b/compiler/testData/cli/jvm/suspendInFunInterfaceIrDisabled.args index c3e4e704343..eb4de6c6b8a 100644 --- a/compiler/testData/cli/jvm/suspendInFunInterfaceIrDisabled.args +++ b/compiler/testData/cli/jvm/suspendInFunInterfaceIrDisabled.args @@ -2,3 +2,5 @@ $TESTDATA_DIR$/suspendInFunInterfaceIrDisabled.kt -d $TEMP_DIR$ -Xuse-old-backend +-language-version +1.5 diff --git a/compiler/tests-gen/org/jetbrains/kotlin/cli/CliTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/cli/CliTestGenerated.java index 454db767187..841932cbf06 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/cli/CliTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/cli/CliTestGenerated.java @@ -736,6 +736,11 @@ public class CliTestGenerated extends AbstractCliTest { runTest("compiler/testData/cli/jvm/nullabilityAnnotations.args"); } + @TestMetadata("oldBackendLv16.args") + public void testOldBackendLv16() throws Exception { + runTest("compiler/testData/cli/jvm/oldBackendLv16.args"); + } + @TestMetadata("pluginSimple.args") public void testPluginSimple() throws Exception { runTest("compiler/testData/cli/jvm/pluginSimple.args"); diff --git a/plugins/jvm-abi-gen/testData/content/anonymousAnnotationInstantiation/directives.txt b/plugins/jvm-abi-gen/testData/content/anonymousAnnotationInstantiation/directives.txt index e89ced03c66..cfe6c53cb61 100644 --- a/plugins/jvm-abi-gen/testData/content/anonymousAnnotationInstantiation/directives.txt +++ b/plugins/jvm-abi-gen/testData/content/anonymousAnnotationInstantiation/directives.txt @@ -1 +1,3 @@ -// LANGUAGE_VERSION: 1.6 \ No newline at end of file +// LANGUAGE_VERSION: 1.6 +// IGNORE_BACKEND_LEGACY: JVM +// IGNORE_BACKEND: JVM