Add warning on -Xcoroutines flag use

The only case when warning is not reported is -Xcoroutines=default.
But this is OK until the flag is removed completely.
This commit is contained in:
Ilmir Usmanov
2018-07-17 23:09:56 +03:00
committed by Ilya Gorbunov
parent 8f6d2b70a9
commit cf1f194f8b
8 changed files with 24 additions and 14 deletions
@@ -33,6 +33,7 @@ abstract class CommonCompilerArguments : CommonToolArguments() {
const val WARN = "warn"
const val ERROR = "error"
const val ENABLE = "enable"
const val DEFAULT = "default"
}
@get:Transient
@@ -108,7 +109,7 @@ abstract class CommonCompilerArguments : CommonToolArguments() {
valueDescription = "{enable|warn|error}",
description = "Enable coroutines or report warnings or errors on declarations and use sites of 'suspend' modifier"
)
var coroutinesState: String? by NullableStringFreezableVar(WARN)
var coroutinesState: String? by NullableStringFreezableVar(DEFAULT)
@Argument(
value = "-Xnew-inference",
@@ -208,7 +209,7 @@ abstract class CommonCompilerArguments : CommonToolArguments() {
when (coroutinesState) {
CommonCompilerArguments.ERROR -> put(LanguageFeature.Coroutines, LanguageFeature.State.ENABLED_WITH_ERROR)
CommonCompilerArguments.ENABLE -> put(LanguageFeature.Coroutines, LanguageFeature.State.ENABLED)
CommonCompilerArguments.WARN -> {
CommonCompilerArguments.WARN, CommonCompilerArguments.DEFAULT -> {
}
else -> {
val message = "Invalid value of -Xcoroutines (should be: enable, warn or error): " + coroutinesState
@@ -311,12 +312,23 @@ abstract class CommonCompilerArguments : CommonToolArguments() {
)
}
return LanguageVersionSettingsImpl(
val languageVersionSettings = LanguageVersionSettingsImpl(
languageVersion,
ApiVersion.createByLanguageVersion(apiVersion),
configureAnalysisFlags(collector),
configureLanguageFeatures(collector)
)
if (languageVersionSettings.supportsFeature(LanguageFeature.ReleaseCoroutines)) {
if (coroutinesState != DEFAULT) {
collector.report(
CompilerMessageSeverity.STRONG_WARNING,
"-Xcoroutines has no effect: coroutines are enabled anyway in 1.3 and beyond"
)
}
}
return languageVersionSettings
}
private fun parseVersion(collector: MessageCollector, value: String?, versionOf: String): LanguageVersion? =
+1
View File
@@ -1 +1,2 @@
warning: -Xcoroutines has no effect: coroutines are enabled anyway in 1.3 and beyond
OK
+2 -4
View File
@@ -1,4 +1,2 @@
compiler/testData/cli/jvm/coroutines.kt:1:1: error: the feature "coroutines" is experimental and disabled (see: https://kotlinlang.org/docs/diagnostics/experimental-coroutines)
suspend fun simple() = 5
^
COMPILATION_ERROR
warning: -Xcoroutines has no effect: coroutines are enabled anyway in 1.3 and beyond
OK
+2 -1
View File
@@ -1,2 +1,3 @@
warning: argument -Xcoroutines is passed multiple times. Only the last value will be used: enable
OK
warning: -Xcoroutines has no effect: coroutines are enabled anyway in 1.3 and beyond
OK
+2 -4
View File
@@ -1,4 +1,2 @@
compiler/testData/cli/jvm/coroutines.kt:1:1: warning: the feature "coroutines" is experimental (see: https://kotlinlang.org/docs/diagnostics/experimental-coroutines)
suspend fun simple() = 5
^
OK
warning: -Xcoroutines has no effect: coroutines are enabled anyway in 1.3 and beyond
OK
@@ -1,4 +1,3 @@
warning: language version 1.3 is experimental, there are no backwards compatibility guarantees for new language and library features
compiler/testData/cli/jvm/releaseCoroutinesApiVersion1.2.kt:1:1: error: unsupported [cannot use release coroutines with api version less than 1.3]
suspend fun dummy() {}
^
@@ -1,3 +1,4 @@
-- Common --
Exit code: OK
Output:
warning: -Xcoroutines has no effect: coroutines are enabled anyway in 1.3 and beyond
@@ -54,7 +54,7 @@ object CoroutineSupport {
fun byCompilerArgumentsOrNull(arguments: CommonCompilerArguments?): LanguageFeature.State? = when (arguments?.coroutinesState) {
CommonCompilerArguments.ENABLE -> LanguageFeature.State.ENABLED
CommonCompilerArguments.WARN -> LanguageFeature.State.ENABLED_WITH_WARNING
CommonCompilerArguments.WARN, CommonCompilerArguments.DEFAULT -> LanguageFeature.State.ENABLED_WITH_WARNING
CommonCompilerArguments.ERROR -> LanguageFeature.State.ENABLED_WITH_ERROR
else -> null
}