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 2fdb52565a6..7589ee27dd8 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 @@ -574,6 +574,8 @@ abstract class CommonCompilerArguments : CommonToolArguments() { checkLanguageVersionIsStable(languageVersion, collector) checkOutdatedVersions(languageVersion, apiVersion, collector) checkProgressiveMode(languageVersion, collector) + + checkIrSupport(languageVersionSettings, collector) } checkPlatformSpecificSettings(languageVersionSettings, collector) @@ -652,6 +654,10 @@ abstract class CommonCompilerArguments : CommonToolArguments() { protected open fun checkPlatformSpecificSettings(languageVersionSettings: LanguageVersionSettings, collector: MessageCollector) { } + protected open fun checkIrSupport(languageVersionSettings: LanguageVersionSettings, collector: MessageCollector) { + // backend-specific + } + 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/K2JSCompilerArguments.kt b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JSCompilerArguments.kt index d8d0ca6fe1f..0c4f47b2c01 100644 --- a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JSCompilerArguments.kt +++ b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JSCompilerArguments.kt @@ -6,11 +6,10 @@ package org.jetbrains.kotlin.cli.common.arguments import org.jetbrains.kotlin.cli.common.arguments.K2JsArgumentConstants.* +import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity import org.jetbrains.kotlin.cli.common.messages.MessageCollector -import org.jetbrains.kotlin.config.AnalysisFlag +import org.jetbrains.kotlin.config.* import org.jetbrains.kotlin.config.AnalysisFlags.allowFullyQualifiedNameInKClass -import org.jetbrains.kotlin.config.LanguageFeature -import org.jetbrains.kotlin.config.LanguageVersion class K2JSCompilerArguments : CommonCompilerArguments() { companion object { @@ -257,6 +256,19 @@ class K2JSCompilerArguments : CommonCompilerArguments() { } } + override fun checkIrSupport(languageVersionSettings: LanguageVersionSettings, collector: MessageCollector) { + if (!isIrBackendEnabled()) return + + if (languageVersionSettings.languageVersion < LanguageVersion.KOTLIN_1_4 + || languageVersionSettings.apiVersion < ApiVersion.KOTLIN_1_4 + ) { + collector.report( + CompilerMessageSeverity.ERROR, + "IR backend cannot be used with language or API version below 1.4" + ) + } + } + override fun configureLanguageFeatures(collector: MessageCollector): MutableMap { return super.configureLanguageFeatures(collector).apply { if (extensionFunctionsInExternals) { diff --git a/kotlin-native/backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2NativeCompilerArguments.kt b/kotlin-native/backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2NativeCompilerArguments.kt index 2010cff7723..15458940189 100644 --- a/kotlin-native/backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2NativeCompilerArguments.kt +++ b/kotlin-native/backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2NativeCompilerArguments.kt @@ -371,6 +371,17 @@ class K2NativeCompilerArguments : CommonCompilerArguments() { if (printIr) phasesToDumpAfter = arrayOf("ALL") } + + override fun checkIrSupport(languageVersionSettings: LanguageVersionSettings, collector: MessageCollector) { + if (languageVersionSettings.languageVersion < LanguageVersion.KOTLIN_1_4 + || languageVersionSettings.apiVersion < ApiVersion.KOTLIN_1_4 + ) { + collector.report( + severity = CompilerMessageSeverity.ERROR, + message = "Native backend cannot be used with language or API version below 1.4" + ) + } + } } const val EMBED_BITCODE_FLAG = "-Xembed-bitcode"