Validate "-language-version" argument value, add tests
This commit is contained in:
@@ -39,6 +39,7 @@ import org.jetbrains.kotlin.config.Services;
|
||||
import org.jetbrains.kotlin.progress.CompilationCanceledException;
|
||||
import org.jetbrains.kotlin.progress.CompilationCanceledStatus;
|
||||
import org.jetbrains.kotlin.progress.ProgressIndicatorAndCompilationCanceledStatus;
|
||||
import org.jetbrains.kotlin.utils.StringsKt;
|
||||
|
||||
import java.io.PrintStream;
|
||||
import java.util.List;
|
||||
@@ -245,10 +246,18 @@ public abstract class CLICompiler<A extends CommonCompilerArguments> {
|
||||
}
|
||||
|
||||
if (arguments.languageVersion != null) {
|
||||
configuration.put(
|
||||
CommonConfigurationKeys.LANGUAGE_FEATURE_SETTINGS,
|
||||
LanguageFeatureSettings.fromLanguageVersion(arguments.languageVersion)
|
||||
);
|
||||
LanguageFeatureSettings languageFeatureSettings = LanguageFeatureSettings.fromLanguageVersion(arguments.languageVersion);
|
||||
if (languageFeatureSettings != null) {
|
||||
configuration.put(CommonConfigurationKeys.LANGUAGE_FEATURE_SETTINGS, languageFeatureSettings);
|
||||
}
|
||||
else {
|
||||
String message =
|
||||
"Unknown language version: " + arguments.languageVersion + "\n" +
|
||||
"Supported language versions: " + StringsKt.join(LanguageFeatureSettings.getAllLanguageVersions(), ", ");
|
||||
configuration.getNotNull(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY).report(
|
||||
CompilerMessageSeverity.ERROR, message, CompilerMessageLocation.NO_LOCATION
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -221,10 +221,11 @@ class K2JVMCompiler : CLICompiler<K2JVMCompilerArguments>() {
|
||||
configuration: CompilerConfiguration, arguments: K2JVMCompilerArguments, services: Services
|
||||
) {
|
||||
if (IncrementalCompilation.isEnabled()) {
|
||||
configuration.put(
|
||||
JVMConfigurationKeys.INCREMENTAL_COMPILATION_COMPONENTS,
|
||||
services.get(IncrementalCompilationComponents::class.java)
|
||||
)
|
||||
val components = services.get(IncrementalCompilationComponents::class.java)
|
||||
@Suppress("SENSELESS_COMPARISON")
|
||||
if (components != null) {
|
||||
configuration.put(JVMConfigurationKeys.INCREMENTAL_COMPILATION_COMPONENTS, components)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -283,10 +284,11 @@ class K2JVMCompiler : CLICompiler<K2JVMCompilerArguments>() {
|
||||
configuration.put(JVMConfigurationKeys.DISABLE_CALL_ASSERTIONS, arguments.noCallAssertions)
|
||||
configuration.put(JVMConfigurationKeys.DISABLE_PARAM_ASSERTIONS, arguments.noParamAssertions)
|
||||
configuration.put(JVMConfigurationKeys.DISABLE_OPTIMIZATION, arguments.noOptimize)
|
||||
configuration.put(JVMConfigurationKeys.DECLARATIONS_JSON_PATH, arguments.declarationsOutputPath)
|
||||
configuration.put(JVMConfigurationKeys.INHERIT_MULTIFILE_PARTS, arguments.inheritMultifileParts)
|
||||
configuration.put(CLIConfigurationKeys.ALLOW_KOTLIN_PACKAGE, arguments.allowKotlinPackage)
|
||||
configuration.put(CLIConfigurationKeys.REPORT_PERF, arguments.reportPerf)
|
||||
|
||||
arguments.declarationsOutputPath?.let { configuration.put(JVMConfigurationKeys.DECLARATIONS_JSON_PATH, it) }
|
||||
}
|
||||
|
||||
private fun getClasspath(paths: KotlinPaths, arguments: K2JVMCompilerArguments): List<File> {
|
||||
|
||||
@@ -62,7 +62,7 @@ public class CompilerConfiguration {
|
||||
return data == null ? Collections.<T>emptyList() : data;
|
||||
}
|
||||
|
||||
public <T> void put(@NotNull CompilerConfigurationKey<T> key, @Nullable T value) {
|
||||
public <T> void put(@NotNull CompilerConfigurationKey<T> key, @NotNull T value) {
|
||||
checkReadOnly();
|
||||
map.put(key.ideaKey, value);
|
||||
}
|
||||
|
||||
@@ -39,5 +39,8 @@ class LanguageFeatureSettings(
|
||||
|
||||
@JvmStatic
|
||||
fun fromLanguageVersion(source: String): LanguageFeatureSettings? = SETTINGS[source]
|
||||
|
||||
@JvmStatic
|
||||
fun getAllLanguageVersions(): List<String> = SETTINGS.keys.toList()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
$TESTDATA_DIR$/languageVersion.kt
|
||||
-output
|
||||
$TEMP_DIR$/out.js
|
||||
-language-version
|
||||
1.0
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
package test
|
||||
|
||||
sealed class Base
|
||||
|
||||
class Derived : Base()
|
||||
@@ -0,0 +1,4 @@
|
||||
compiler/testData/cli/js/languageVersion.kt:5:17: error: this type is sealed, so it can be inherited by only its own nested classes or objects
|
||||
class Derived : Base()
|
||||
^
|
||||
COMPILATION_ERROR
|
||||
@@ -0,0 +1,5 @@
|
||||
$TESTDATA_DIR$/languageVersion.kt
|
||||
-d
|
||||
$TEMP_DIR$
|
||||
-language-version
|
||||
1.0
|
||||
@@ -0,0 +1,5 @@
|
||||
package test
|
||||
|
||||
sealed class Base
|
||||
|
||||
class Derived : Base()
|
||||
@@ -0,0 +1,4 @@
|
||||
compiler/testData/cli/jvm/languageVersion.kt:5:17: error: this type is sealed, so it can be inherited by only its own nested classes or objects
|
||||
class Derived : Base()
|
||||
^
|
||||
COMPILATION_ERROR
|
||||
@@ -0,0 +1,5 @@
|
||||
$TESTDATA_DIR$/simple.kt
|
||||
-d
|
||||
$TEMP_DIR$
|
||||
-language-version
|
||||
239.42
|
||||
@@ -0,0 +1,3 @@
|
||||
error: unknown language version: 239.42
|
||||
Supported language versions: 1.0, 1.1
|
||||
COMPILATION_ERROR
|
||||
@@ -151,6 +151,18 @@ public class CliTestGenerated extends AbstractCliTest {
|
||||
doJvmTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("languageVersion.args")
|
||||
public void testLanguageVersion() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cli/jvm/languageVersion.args");
|
||||
doJvmTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("languageVersionInvalid.args")
|
||||
public void testLanguageVersionInvalid() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cli/jvm/languageVersionInvalid.args");
|
||||
doJvmTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("multipleTextRangesInDiagnosticsOrder.args")
|
||||
public void testMultipleTextRangesInDiagnosticsOrder() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cli/jvm/multipleTextRangesInDiagnosticsOrder.args");
|
||||
@@ -340,6 +352,12 @@ public class CliTestGenerated extends AbstractCliTest {
|
||||
doJsTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("languageVersion.args")
|
||||
public void testLanguageVersion() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cli/js/languageVersion.args");
|
||||
doJsTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("libraryDirNotFound.args")
|
||||
public void testLibraryDirNotFound() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cli/js/libraryDirNotFound.args");
|
||||
|
||||
Reference in New Issue
Block a user