Invert LanguageFeature responsible for warning on coroutines
The problem was that LanguageVersionSettingsImpl.DEFAULT did not have "WarnOnCoroutines" as a feature and so it was manually added to the settings, but only in two places: in the compiler and in the IDE
This commit is contained in:
@@ -288,19 +288,19 @@ public abstract class CLICompiler<A extends CommonCompilerArguments> {
|
|||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private static LanguageFeature chooseCoroutinesApplicabilityLevel(
|
private static LanguageFeature chooseCoroutinesApplicabilityLevel(
|
||||||
@NotNull CompilerConfiguration configuration, @NotNull CommonCompilerArguments arguments) {
|
@NotNull CompilerConfiguration configuration,
|
||||||
if (!arguments.coroutinesEnable && !arguments.coroutinesError && !arguments.coroutinesWarn) {
|
@NotNull CommonCompilerArguments arguments
|
||||||
return LanguageFeature.WarnOnCoroutines;
|
) {
|
||||||
}
|
if (arguments.coroutinesError && !arguments.coroutinesWarn && !arguments.coroutinesEnable) {
|
||||||
else if (arguments.coroutinesError && !arguments.coroutinesWarn && !arguments.coroutinesEnable) {
|
|
||||||
return LanguageFeature.ErrorOnCoroutines;
|
return LanguageFeature.ErrorOnCoroutines;
|
||||||
}
|
}
|
||||||
else if (arguments.coroutinesWarn && !arguments.coroutinesError && !arguments.coroutinesEnable) {
|
|
||||||
return LanguageFeature.WarnOnCoroutines;
|
|
||||||
}
|
|
||||||
else if (arguments.coroutinesEnable && !arguments.coroutinesWarn && !arguments.coroutinesError) {
|
else if (arguments.coroutinesEnable && !arguments.coroutinesWarn && !arguments.coroutinesError) {
|
||||||
|
return LanguageFeature.DoNotWarnOnCoroutines;
|
||||||
|
}
|
||||||
|
else if (!arguments.coroutinesEnable && !arguments.coroutinesError) {
|
||||||
return null;
|
return null;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
String message = "The -Xcoroutines can only have one value";
|
String message = "The -Xcoroutines can only have one value";
|
||||||
configuration.getNotNull(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY).report(
|
configuration.getNotNull(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY).report(
|
||||||
CompilerMessageSeverity.ERROR, message, CompilerMessageLocation.NO_LOCATION
|
CompilerMessageSeverity.ERROR, message, CompilerMessageLocation.NO_LOCATION
|
||||||
|
|||||||
@@ -103,8 +103,8 @@ object ModifierCheckerCore {
|
|||||||
LanguageFeature.Coroutines to LanguageFeature.ErrorOnCoroutines
|
LanguageFeature.Coroutines to LanguageFeature.ErrorOnCoroutines
|
||||||
)
|
)
|
||||||
|
|
||||||
val warningOnFeature = mapOf(
|
val noWarningOnFeature = mapOf(
|
||||||
LanguageFeature.Coroutines to LanguageFeature.WarnOnCoroutines
|
LanguageFeature.Coroutines to LanguageFeature.DoNotWarnOnCoroutines
|
||||||
)
|
)
|
||||||
|
|
||||||
val featureDependenciesTargets = mapOf(
|
val featureDependenciesTargets = mapOf(
|
||||||
@@ -299,8 +299,8 @@ object ModifierCheckerCore {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
val pairedWarningFeature = warningOnFeature[dependency]
|
val pairedNoWarningFeature = noWarningOnFeature[dependency]
|
||||||
if (pairedWarningFeature != null && languageVersionSettings.supportsFeature(pairedWarningFeature)) {
|
if (pairedNoWarningFeature != null && !languageVersionSettings.supportsFeature(pairedNoWarningFeature)) {
|
||||||
trace.report(Errors.EXPERIMENTAL_FEATURE_WARNING.on(node.psi, diagnosticData))
|
trace.report(Errors.EXPERIMENTAL_FEATURE_WARNING.on(node.psi, diagnosticData))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -96,7 +96,7 @@ fun checkCoroutinesFeature(languageVersionSettings: LanguageVersionSettings, dia
|
|||||||
else if (languageVersionSettings.supportsFeature(LanguageFeature.ErrorOnCoroutines)) {
|
else if (languageVersionSettings.supportsFeature(LanguageFeature.ErrorOnCoroutines)) {
|
||||||
diagnosticHolder.report(Errors.EXPERIMENTAL_FEATURE_ERROR.on(reportOn, diagnosticData))
|
diagnosticHolder.report(Errors.EXPERIMENTAL_FEATURE_ERROR.on(reportOn, diagnosticData))
|
||||||
}
|
}
|
||||||
else if (languageVersionSettings.supportsFeature(LanguageFeature.WarnOnCoroutines)) {
|
else if (!languageVersionSettings.supportsFeature(LanguageFeature.DoNotWarnOnCoroutines)) {
|
||||||
diagnosticHolder.report(Errors.EXPERIMENTAL_FEATURE_WARNING.on(reportOn, diagnosticData))
|
diagnosticHolder.report(Errors.EXPERIMENTAL_FEATURE_WARNING.on(reportOn, diagnosticData))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||||
// !LANGUAGE: +WarnOnCoroutines
|
// !LANGUAGE: -DoNotWarnOnCoroutines
|
||||||
|
|
||||||
<!EXPERIMENTAL_FEATURE_WARNING!>suspend<!> fun suspendHere(): String = "OK"
|
<!EXPERIMENTAL_FEATURE_WARNING!>suspend<!> fun suspendHere(): String = "OK"
|
||||||
|
|
||||||
|
|||||||
Vendored
+1
@@ -1,4 +1,5 @@
|
|||||||
// !API_VERSION: 1.1
|
// !API_VERSION: 1.1
|
||||||
|
// !LANGUAGE: +DoNotWarnOnCoroutines
|
||||||
// SKIP_TXT
|
// SKIP_TXT
|
||||||
|
|
||||||
import kotlin.coroutines.experimental.*
|
import kotlin.coroutines.experimental.*
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ import org.jetbrains.kotlin.analyzer.common.DefaultAnalyzerFacade
|
|||||||
import org.jetbrains.kotlin.cli.jvm.compiler.CliLightClassGenerationSupport
|
import org.jetbrains.kotlin.cli.jvm.compiler.CliLightClassGenerationSupport
|
||||||
import org.jetbrains.kotlin.cli.jvm.compiler.JvmPackagePartProvider
|
import org.jetbrains.kotlin.cli.jvm.compiler.JvmPackagePartProvider
|
||||||
import org.jetbrains.kotlin.config.LanguageVersionSettings
|
import org.jetbrains.kotlin.config.LanguageVersionSettings
|
||||||
|
import org.jetbrains.kotlin.config.LanguageVersionSettingsImpl
|
||||||
import org.jetbrains.kotlin.config.languageVersionSettings
|
import org.jetbrains.kotlin.config.languageVersionSettings
|
||||||
import org.jetbrains.kotlin.container.get
|
import org.jetbrains.kotlin.container.get
|
||||||
import org.jetbrains.kotlin.context.ModuleContext
|
import org.jetbrains.kotlin.context.ModuleContext
|
||||||
@@ -63,6 +64,7 @@ import org.jetbrains.kotlin.test.util.DescriptorValidator
|
|||||||
import org.jetbrains.kotlin.test.util.RecursiveDescriptorComparator
|
import org.jetbrains.kotlin.test.util.RecursiveDescriptorComparator
|
||||||
import org.jetbrains.kotlin.test.util.RecursiveDescriptorComparator.RECURSIVE
|
import org.jetbrains.kotlin.test.util.RecursiveDescriptorComparator.RECURSIVE
|
||||||
import org.jetbrains.kotlin.test.util.RecursiveDescriptorComparator.RECURSIVE_ALL
|
import org.jetbrains.kotlin.test.util.RecursiveDescriptorComparator.RECURSIVE_ALL
|
||||||
|
import org.jetbrains.kotlin.utils.keysToMap
|
||||||
import org.junit.Assert
|
import org.junit.Assert
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.util.*
|
import java.util.*
|
||||||
@@ -198,7 +200,7 @@ abstract class AbstractDiagnosticsTest : BaseDiagnosticsTest() {
|
|||||||
// To be overridden by diagnostic-like tests.
|
// To be overridden by diagnostic-like tests.
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun loadLanguageVersionSettings(module: List<TestFile>): LanguageVersionSettings? {
|
private fun loadLanguageVersionSettings(module: List<TestFile>): LanguageVersionSettings {
|
||||||
var result: LanguageVersionSettings? = null
|
var result: LanguageVersionSettings? = null
|
||||||
for (file in module) {
|
for (file in module) {
|
||||||
val current = file.customLanguageVersionSettings
|
val current = file.customLanguageVersionSettings
|
||||||
@@ -213,7 +215,11 @@ abstract class AbstractDiagnosticsTest : BaseDiagnosticsTest() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result
|
return result ?: BaseDiagnosticsTest.DiagnosticTestLanguageVersionSettings(
|
||||||
|
BaseDiagnosticsTest.DEFAULT_DIAGNOSTIC_TESTS_FEATURES.keysToMap { true },
|
||||||
|
LanguageVersionSettingsImpl.DEFAULT.apiVersion,
|
||||||
|
LanguageVersionSettingsImpl.DEFAULT.languageVersion
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun checkDynamicCallDescriptors(expectedFile: File, testFiles: List<TestFile>) {
|
private fun checkDynamicCallDescriptors(expectedFile: File, testFiles: List<TestFile>) {
|
||||||
@@ -253,19 +259,15 @@ abstract class AbstractDiagnosticsTest : BaseDiagnosticsTest() {
|
|||||||
moduleContext: ModuleContext,
|
moduleContext: ModuleContext,
|
||||||
files: List<KtFile>,
|
files: List<KtFile>,
|
||||||
moduleTrace: BindingTrace,
|
moduleTrace: BindingTrace,
|
||||||
languageVersionSettings: LanguageVersionSettings?,
|
languageVersionSettings: LanguageVersionSettings,
|
||||||
separateModules: Boolean
|
separateModules: Boolean
|
||||||
): AnalysisResult {
|
): AnalysisResult {
|
||||||
@Suppress("NAME_SHADOWING")
|
@Suppress("NAME_SHADOWING")
|
||||||
var files = files
|
var files = files
|
||||||
|
|
||||||
val configuration =
|
val configuration = environment.configuration.copy().apply {
|
||||||
if (languageVersionSettings != null)
|
this.languageVersionSettings = languageVersionSettings
|
||||||
environment.configuration.copy().apply {
|
}
|
||||||
this.languageVersionSettings = languageVersionSettings
|
|
||||||
}
|
|
||||||
else
|
|
||||||
environment.configuration
|
|
||||||
|
|
||||||
// New JavaDescriptorResolver is created for each module, which is good because it emulates different Java libraries for each module,
|
// New JavaDescriptorResolver is created for each module, which is good because it emulates different Java libraries for each module,
|
||||||
// albeit with same class names
|
// albeit with same class names
|
||||||
|
|||||||
@@ -286,6 +286,10 @@ abstract class BaseDiagnosticsTest : KotlinMultiFileTestWithJava<TestModule, Tes
|
|||||||
val LANGUAGE_VERSION = "LANGUAGE_VERSION"
|
val LANGUAGE_VERSION = "LANGUAGE_VERSION"
|
||||||
private val LANGUAGE_PATTERN = Pattern.compile("([\\+\\-])(\\w+)\\s*")
|
private val LANGUAGE_PATTERN = Pattern.compile("([\\+\\-])(\\w+)\\s*")
|
||||||
|
|
||||||
|
val DEFAULT_DIAGNOSTIC_TESTS_FEATURES = listOf(
|
||||||
|
LanguageFeature.DoNotWarnOnCoroutines
|
||||||
|
)
|
||||||
|
|
||||||
val API_VERSION_DIRECTIVE = "API_VERSION"
|
val API_VERSION_DIRECTIVE = "API_VERSION"
|
||||||
|
|
||||||
val CHECK_TYPE_DIRECTIVE = "CHECK_TYPE"
|
val CHECK_TYPE_DIRECTIVE = "CHECK_TYPE"
|
||||||
|
|||||||
@@ -62,11 +62,10 @@ abstract class AbstractDiagnosticsTestWithJsStdLib : AbstractDiagnosticsTest() {
|
|||||||
moduleContext: ModuleContext,
|
moduleContext: ModuleContext,
|
||||||
files: List<KtFile>,
|
files: List<KtFile>,
|
||||||
moduleTrace: BindingTrace,
|
moduleTrace: BindingTrace,
|
||||||
languageVersionSettings: LanguageVersionSettings?,
|
languageVersionSettings: LanguageVersionSettings,
|
||||||
separateModules: Boolean
|
separateModules: Boolean
|
||||||
): JsAnalysisResult {
|
): JsAnalysisResult {
|
||||||
// TODO: support LANGUAGE directive in JS diagnostic tests
|
// TODO: support LANGUAGE directive in JS diagnostic tests
|
||||||
assert(languageVersionSettings == null) { "$LANGUAGE_DIRECTIVE directive is not supported in JS diagnostic tests" }
|
|
||||||
moduleTrace.record<ModuleDescriptor, ModuleKind>(MODULE_KIND, moduleContext.module, getModuleKind(files))
|
moduleTrace.record<ModuleDescriptor, ModuleKind>(MODULE_KIND, moduleContext.module, getModuleKind(files))
|
||||||
return TopDownAnalyzerFacadeForJS.analyzeFilesWithGivenTrace(files, moduleTrace, moduleContext, config)
|
return TopDownAnalyzerFacadeForJS.analyzeFilesWithGivenTrace(files, moduleTrace, moduleContext, config)
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -30,7 +30,7 @@ abstract class AbstractDiagnosticsTestWithJsStdLibAndBackendCompilation : Abstra
|
|||||||
moduleContext: ModuleContext,
|
moduleContext: ModuleContext,
|
||||||
files: List<KtFile>,
|
files: List<KtFile>,
|
||||||
moduleTrace: BindingTrace,
|
moduleTrace: BindingTrace,
|
||||||
languageVersionSettings: LanguageVersionSettings?,
|
languageVersionSettings: LanguageVersionSettings,
|
||||||
separateModules: Boolean
|
separateModules: Boolean
|
||||||
): JsAnalysisResult {
|
): JsAnalysisResult {
|
||||||
val analysisResult = super.analyzeModuleContents(moduleContext, files, moduleTrace, languageVersionSettings, separateModules)
|
val analysisResult = super.analyzeModuleContents(moduleContext, files, moduleTrace, languageVersionSettings, separateModules)
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ enum class LanguageFeature(
|
|||||||
MultiPlatformProjects(null),
|
MultiPlatformProjects(null),
|
||||||
MultiPlatformDoNotCheckImpl(null),
|
MultiPlatformDoNotCheckImpl(null),
|
||||||
|
|
||||||
WarnOnCoroutines(null),
|
DoNotWarnOnCoroutines(null),
|
||||||
ErrorOnCoroutines(null)
|
ErrorOnCoroutines(null)
|
||||||
;
|
;
|
||||||
|
|
||||||
@@ -100,7 +100,6 @@ interface LanguageVersionSettings {
|
|||||||
// Please do not use this to enable/disable specific features/checks. Instead add a new LanguageFeature entry and call supportsFeature
|
// Please do not use this to enable/disable specific features/checks. Instead add a new LanguageFeature entry and call supportsFeature
|
||||||
val languageVersion: LanguageVersion
|
val languageVersion: LanguageVersion
|
||||||
|
|
||||||
// TODO: refactor arguments related to coroutines so that this list is empty by default
|
|
||||||
val additionalFeatures: Collection<LanguageFeature>
|
val additionalFeatures: Collection<LanguageFeature>
|
||||||
|
|
||||||
@Deprecated("This is a temporary solution, please do not use.")
|
@Deprecated("This is a temporary solution, please do not use.")
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ import org.jetbrains.kotlin.psi.KtElement
|
|||||||
import org.jetbrains.kotlin.resolve.TargetPlatform
|
import org.jetbrains.kotlin.resolve.TargetPlatform
|
||||||
|
|
||||||
val KtElement.platform: TargetPlatform
|
val KtElement.platform: TargetPlatform
|
||||||
get() = TargetPlatformDetector.getPlatform(getContainingKtFile())
|
get() = TargetPlatformDetector.getPlatform(containingKtFile)
|
||||||
|
|
||||||
val KtElement.builtIns: KotlinBuiltIns
|
val KtElement.builtIns: KotlinBuiltIns
|
||||||
get() = getResolutionFacade().moduleDescriptor.builtIns
|
get() = getResolutionFacade().moduleDescriptor.builtIns
|
||||||
@@ -130,8 +130,8 @@ private fun getExtraLanguageFeatures(
|
|||||||
): List<LanguageFeature> {
|
): List<LanguageFeature> {
|
||||||
return mutableListOf<LanguageFeature>().apply {
|
return mutableListOf<LanguageFeature>().apply {
|
||||||
when (coroutineSupport) {
|
when (coroutineSupport) {
|
||||||
CoroutineSupport.ENABLED -> {}
|
CoroutineSupport.ENABLED -> add(LanguageFeature.DoNotWarnOnCoroutines)
|
||||||
CoroutineSupport.ENABLED_WITH_WARNING -> add(LanguageFeature.WarnOnCoroutines)
|
CoroutineSupport.ENABLED_WITH_WARNING -> {}
|
||||||
CoroutineSupport.DISABLED -> add(LanguageFeature.ErrorOnCoroutines)
|
CoroutineSupport.DISABLED -> add(LanguageFeature.ErrorOnCoroutines)
|
||||||
}
|
}
|
||||||
if (targetPlatformKind == TargetPlatformKind.Common ||
|
if (targetPlatformKind == TargetPlatformKind.Common ||
|
||||||
|
|||||||
Reference in New Issue
Block a user