Add an explicit diagnostic for when expect/actual modifiers are used in

an unsupported compilation

^KT-31281
This commit is contained in:
Timofey Solonin
2023-07-10 11:35:05 +02:00
committed by Space Team
parent cab0487f98
commit e12e78d96b
11 changed files with 39 additions and 13 deletions
@@ -835,6 +835,7 @@ public interface Errors {
DiagnosticFactory0<PsiElement> OPTIONAL_EXPECTATION_NOT_ON_EXPECTED = DiagnosticFactory0.create(ERROR);
DiagnosticFactory0<PsiElement> OPTIONAL_DECLARATION_OUTSIDE_OF_ANNOTATION_ENTRY = DiagnosticFactory0.create(ERROR);
DiagnosticFactory0<PsiElement> OPTIONAL_DECLARATION_USAGE_IN_NON_COMMON_SOURCE = DiagnosticFactory0.create(ERROR);
DiagnosticFactory0<PsiElement> NOT_A_MULTIPLATFORM_COMPILATION = DiagnosticFactory0.create(ERROR);
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -391,6 +391,7 @@ public class DefaultErrorMessages {
MAP.put(OPTIONAL_EXPECTATION_NOT_ON_EXPECTED, "'@OptionalExpectation' can only be used on an expected annotation class");
MAP.put(OPTIONAL_DECLARATION_OUTSIDE_OF_ANNOTATION_ENTRY, "Declaration annotated with '@OptionalExpectation' can only be used inside an annotation entry");
MAP.put(OPTIONAL_DECLARATION_USAGE_IN_NON_COMMON_SOURCE, "Declaration annotated with '@OptionalExpectation' can only be used in common module sources");
MAP.put(NOT_A_MULTIPLATFORM_COMPILATION, "'expect' and 'actual' declarations can be used only in multiplatform projects. Learn more about Kotlin Multiplatform: https://kotl.in/multiplatform-setup");
MAP.put(PROJECTION_ON_NON_CLASS_TYPE_ARGUMENT, "Projections are not allowed on type arguments of functions and properties");
MAP.put(SUPERTYPE_NOT_INITIALIZED, "This type has a constructor, and thus must be initialized here");
@@ -216,8 +216,6 @@ object ModifierCheckerCore {
continue
}
val featureSupport = languageVersionSettings.getFeatureSupport(dependency)
if (dependency == LanguageFeature.Coroutines) {
checkCoroutinesFeature(languageVersionSettings, trace, node.psi)
continue
@@ -230,6 +228,13 @@ object ModifierCheckerCore {
}
}
val featureSupport = languageVersionSettings.getFeatureSupport(dependency)
if (dependency == LanguageFeature.MultiPlatformProjects && featureSupport == LanguageFeature.State.DISABLED) {
trace.report(Errors.NOT_A_MULTIPLATFORM_COMPILATION.on(node.psi))
continue
}
val diagnosticData = dependency to languageVersionSettings
when (featureSupport) {
LanguageFeature.State.ENABLED_WITH_WARNING -> {