Report error if IR is enabled with incorrect language version
^KT-36338 Fixed
This commit is contained in:
+5
@@ -497,6 +497,7 @@ abstract class CommonCompilerArguments : CommonToolArguments() {
|
|||||||
)
|
)
|
||||||
|
|
||||||
checkCoroutines(languageVersionSettings, collector)
|
checkCoroutines(languageVersionSettings, collector)
|
||||||
|
checkIrSupport(languageVersionSettings, collector)
|
||||||
|
|
||||||
return languageVersionSettings
|
return languageVersionSettings
|
||||||
}
|
}
|
||||||
@@ -577,6 +578,10 @@ abstract class CommonCompilerArguments : CommonToolArguments() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected open fun checkIrSupport(languageVersionSettings: LanguageVersionSettings, collector: MessageCollector) {
|
||||||
|
// backend-specific
|
||||||
|
}
|
||||||
|
|
||||||
private enum class VersionKind(val text: String) {
|
private enum class VersionKind(val text: String) {
|
||||||
LANGUAGE("Language"), API("API")
|
LANGUAGE("Language"), API("API")
|
||||||
}
|
}
|
||||||
|
|||||||
+18
@@ -18,6 +18,11 @@ package org.jetbrains.kotlin.cli.common.arguments
|
|||||||
|
|
||||||
import org.jetbrains.kotlin.cli.common.arguments.K2JsArgumentConstants.CALL
|
import org.jetbrains.kotlin.cli.common.arguments.K2JsArgumentConstants.CALL
|
||||||
import org.jetbrains.kotlin.cli.common.arguments.K2JsArgumentConstants.NO_CALL
|
import org.jetbrains.kotlin.cli.common.arguments.K2JsArgumentConstants.NO_CALL
|
||||||
|
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
|
||||||
|
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
|
||||||
|
import org.jetbrains.kotlin.config.ApiVersion
|
||||||
|
import org.jetbrains.kotlin.config.LanguageVersion
|
||||||
|
import org.jetbrains.kotlin.config.LanguageVersionSettings
|
||||||
|
|
||||||
class K2JSCompilerArguments : CommonCompilerArguments() {
|
class K2JSCompilerArguments : CommonCompilerArguments() {
|
||||||
companion object {
|
companion object {
|
||||||
@@ -164,6 +169,19 @@ class K2JSCompilerArguments : CommonCompilerArguments() {
|
|||||||
|
|
||||||
@Argument(value = "-Xenable-js-scripting", description = "Enable experimental support of .kts files using K/JS (with -Xir only)")
|
@Argument(value = "-Xenable-js-scripting", description = "Enable experimental support of .kts files using K/JS (with -Xir only)")
|
||||||
var enableJsScripting: Boolean by FreezableVar(false)
|
var enableJsScripting: Boolean by FreezableVar(false)
|
||||||
|
|
||||||
|
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"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun K2JSCompilerArguments.isPreIrBackendDisabled(): Boolean =
|
fun K2JSCompilerArguments.isPreIrBackendDisabled(): Boolean =
|
||||||
|
|||||||
+13
@@ -352,4 +352,17 @@ class K2JVMCompilerArguments : CommonCompilerArguments() {
|
|||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun checkIrSupport(languageVersionSettings: LanguageVersionSettings, collector: MessageCollector) {
|
||||||
|
if (!useIR) return
|
||||||
|
|
||||||
|
if (languageVersionSettings.languageVersion < LanguageVersion.KOTLIN_1_3
|
||||||
|
|| languageVersionSettings.apiVersion < ApiVersion.KOTLIN_1_3
|
||||||
|
) {
|
||||||
|
collector.report(
|
||||||
|
CompilerMessageSeverity.ERROR,
|
||||||
|
"IR backend cannot be used with language or API version below 1.3"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
$TESTDATA_DIR$/simple2js.kt
|
||||||
|
-Xir-produce-js
|
||||||
|
-language-version
|
||||||
|
1.4
|
||||||
|
-api-version
|
||||||
|
1.3
|
||||||
|
-output
|
||||||
|
$TEMP_DIR$/out.js
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
error: IR backend cannot be used with language or API version below 1.4
|
||||||
|
COMPILATION_ERROR
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
$TESTDATA_DIR$/simple2js.kt
|
||||||
|
-Xir-produce-js
|
||||||
|
-language-version
|
||||||
|
1.3
|
||||||
|
-output
|
||||||
|
$TEMP_DIR$/out.js
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
error: IR backend cannot be used with language or API version below 1.4
|
||||||
|
COMPILATION_ERROR
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
$TESTDATA_DIR$/simple.kt
|
||||||
|
-d
|
||||||
|
$TEMP_DIR$
|
||||||
|
-language-version
|
||||||
|
1.3
|
||||||
|
-api-version
|
||||||
|
1.2
|
||||||
|
-Xuse-ir
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
warning: API version 1.2 is deprecated and its support will be removed in a future version of Kotlin
|
||||||
|
error: IR backend cannot be used with language or API version below 1.3
|
||||||
|
COMPILATION_ERROR
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
$TESTDATA_DIR$/simple.kt
|
||||||
|
-d
|
||||||
|
$TEMP_DIR$
|
||||||
|
-language-version
|
||||||
|
1.2
|
||||||
|
-Xuse-ir
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
warning: language version 1.2 is deprecated and its support will be removed in a future version of Kotlin
|
||||||
|
error: IR backend cannot be used with language or API version below 1.3
|
||||||
|
COMPILATION_ERROR
|
||||||
+8
@@ -0,0 +1,8 @@
|
|||||||
|
$TESTDATA_DIR$/simple.kt
|
||||||
|
-d
|
||||||
|
$TEMP_DIR$
|
||||||
|
-language-version
|
||||||
|
1.3
|
||||||
|
-api-version
|
||||||
|
1.3
|
||||||
|
-Xuse-ir
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
OK
|
||||||
@@ -365,6 +365,21 @@ public class CliTestGenerated extends AbstractCliTest {
|
|||||||
runTest("compiler/testData/cli/jvm/invalidMetadataVersion.args");
|
runTest("compiler/testData/cli/jvm/invalidMetadataVersion.args");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("irApiVersionUnsupported.args")
|
||||||
|
public void testIrApiVersionUnsupported() throws Exception {
|
||||||
|
runTest("compiler/testData/cli/jvm/irApiVersionUnsupported.args");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("irLanguageVersionUnsupported.args")
|
||||||
|
public void testIrLanguageVersionUnsupported() throws Exception {
|
||||||
|
runTest("compiler/testData/cli/jvm/irLanguageVersionUnsupported.args");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("irSupported.args")
|
||||||
|
public void testIrSupported() throws Exception {
|
||||||
|
runTest("compiler/testData/cli/jvm/irSupported.args");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("javaSrcWrongPackage.args")
|
@TestMetadata("javaSrcWrongPackage.args")
|
||||||
public void testJavaSrcWrongPackage() throws Exception {
|
public void testJavaSrcWrongPackage() throws Exception {
|
||||||
runTest("compiler/testData/cli/jvm/javaSrcWrongPackage.args");
|
runTest("compiler/testData/cli/jvm/javaSrcWrongPackage.args");
|
||||||
@@ -783,6 +798,16 @@ public class CliTestGenerated extends AbstractCliTest {
|
|||||||
runTest("compiler/testData/cli/js/inlineCycle.args");
|
runTest("compiler/testData/cli/js/inlineCycle.args");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("irApiVersionUnsupported.args")
|
||||||
|
public void testIrApiVersionUnsupported() throws Exception {
|
||||||
|
runTest("compiler/testData/cli/js/irApiVersionUnsupported.args");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("irLanguageVersionUnsupported.args")
|
||||||
|
public void testIrLanguageVersionUnsupported() throws Exception {
|
||||||
|
runTest("compiler/testData/cli/js/irLanguageVersionUnsupported.args");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("jsExtraHelp.args")
|
@TestMetadata("jsExtraHelp.args")
|
||||||
public void testJsExtraHelp() throws Exception {
|
public void testJsExtraHelp() throws Exception {
|
||||||
runTest("compiler/testData/cli/js/jsExtraHelp.args");
|
runTest("compiler/testData/cli/js/jsExtraHelp.args");
|
||||||
|
|||||||
Reference in New Issue
Block a user