Add an explicit diagnostic for when expect/actual modifiers are used in
an unsupported compilation ^KT-31281
This commit is contained in:
committed by
Space Team
parent
cab0487f98
commit
e12e78d96b
+6
@@ -3451,6 +3451,12 @@ internal val KT_DIAGNOSTIC_CONVERTER = KtDiagnosticConverterBuilder.buildConvert
|
|||||||
token,
|
token,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
add(FirErrors.NOT_A_MULTIPLATFORM_COMPILATION) { firDiagnostic ->
|
||||||
|
NotAMultiplatformCompilationImpl(
|
||||||
|
firDiagnostic as KtPsiDiagnostic,
|
||||||
|
token,
|
||||||
|
)
|
||||||
|
}
|
||||||
add(FirErrors.INITIALIZER_REQUIRED_FOR_DESTRUCTURING_DECLARATION) { firDiagnostic ->
|
add(FirErrors.INITIALIZER_REQUIRED_FOR_DESTRUCTURING_DECLARATION) { firDiagnostic ->
|
||||||
InitializerRequiredForDestructuringDeclarationImpl(
|
InitializerRequiredForDestructuringDeclarationImpl(
|
||||||
firDiagnostic as KtPsiDiagnostic,
|
firDiagnostic as KtPsiDiagnostic,
|
||||||
|
|||||||
+4
@@ -2411,6 +2411,10 @@ sealed interface KtFirDiagnostic<PSI : PsiElement> : KtDiagnosticWithPsi<PSI> {
|
|||||||
override val diagnosticClass get() = ActualMissing::class
|
override val diagnosticClass get() = ActualMissing::class
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface NotAMultiplatformCompilation : KtFirDiagnostic<PsiElement> {
|
||||||
|
override val diagnosticClass get() = NotAMultiplatformCompilation::class
|
||||||
|
}
|
||||||
|
|
||||||
interface InitializerRequiredForDestructuringDeclaration : KtFirDiagnostic<KtDestructuringDeclaration> {
|
interface InitializerRequiredForDestructuringDeclaration : KtFirDiagnostic<KtDestructuringDeclaration> {
|
||||||
override val diagnosticClass get() = InitializerRequiredForDestructuringDeclaration::class
|
override val diagnosticClass get() = InitializerRequiredForDestructuringDeclaration::class
|
||||||
}
|
}
|
||||||
|
|||||||
+5
@@ -2907,6 +2907,11 @@ internal class ActualMissingImpl(
|
|||||||
token: KtLifetimeToken,
|
token: KtLifetimeToken,
|
||||||
) : KtAbstractFirDiagnostic<KtNamedDeclaration>(firDiagnostic, token), KtFirDiagnostic.ActualMissing
|
) : KtAbstractFirDiagnostic<KtNamedDeclaration>(firDiagnostic, token), KtFirDiagnostic.ActualMissing
|
||||||
|
|
||||||
|
internal class NotAMultiplatformCompilationImpl(
|
||||||
|
firDiagnostic: KtPsiDiagnostic,
|
||||||
|
token: KtLifetimeToken,
|
||||||
|
) : KtAbstractFirDiagnostic<PsiElement>(firDiagnostic, token), KtFirDiagnostic.NotAMultiplatformCompilation
|
||||||
|
|
||||||
internal class InitializerRequiredForDestructuringDeclarationImpl(
|
internal class InitializerRequiredForDestructuringDeclarationImpl(
|
||||||
firDiagnostic: KtPsiDiagnostic,
|
firDiagnostic: KtPsiDiagnostic,
|
||||||
token: KtLifetimeToken,
|
token: KtLifetimeToken,
|
||||||
|
|||||||
+2
@@ -1170,6 +1170,8 @@ object DIAGNOSTICS_LIST : DiagnosticList("FirErrors") {
|
|||||||
}
|
}
|
||||||
|
|
||||||
val ACTUAL_MISSING by error<KtNamedDeclaration>(PositioningStrategy.ACTUAL_DECLARATION_NAME)
|
val ACTUAL_MISSING by error<KtNamedDeclaration>(PositioningStrategy.ACTUAL_DECLARATION_NAME)
|
||||||
|
|
||||||
|
val NOT_A_MULTIPLATFORM_COMPILATION by error<PsiElement>()
|
||||||
}
|
}
|
||||||
|
|
||||||
val DESTRUCTING_DECLARATION by object : DiagnosticGroup("Destructuring declaration") {
|
val DESTRUCTING_DECLARATION by object : DiagnosticGroup("Destructuring declaration") {
|
||||||
|
|||||||
@@ -625,6 +625,7 @@ object FirErrors {
|
|||||||
val AMBIGUOUS_EXPECTS by error2<KtNamedDeclaration, FirBasedSymbol<*>, Collection<FirModuleData>>(SourceElementPositioningStrategies.INCOMPATIBLE_DECLARATION)
|
val AMBIGUOUS_EXPECTS by error2<KtNamedDeclaration, FirBasedSymbol<*>, Collection<FirModuleData>>(SourceElementPositioningStrategies.INCOMPATIBLE_DECLARATION)
|
||||||
val NO_ACTUAL_CLASS_MEMBER_FOR_EXPECTED_CLASS by error2<KtNamedDeclaration, FirBasedSymbol<*>, List<Pair<FirBasedSymbol<*>, Map<Incompatible<FirBasedSymbol<*>>, Collection<FirBasedSymbol<*>>>>>>(SourceElementPositioningStrategies.ACTUAL_DECLARATION_NAME)
|
val NO_ACTUAL_CLASS_MEMBER_FOR_EXPECTED_CLASS by error2<KtNamedDeclaration, FirBasedSymbol<*>, List<Pair<FirBasedSymbol<*>, Map<Incompatible<FirBasedSymbol<*>>, Collection<FirBasedSymbol<*>>>>>>(SourceElementPositioningStrategies.ACTUAL_DECLARATION_NAME)
|
||||||
val ACTUAL_MISSING by error0<KtNamedDeclaration>(SourceElementPositioningStrategies.ACTUAL_DECLARATION_NAME)
|
val ACTUAL_MISSING by error0<KtNamedDeclaration>(SourceElementPositioningStrategies.ACTUAL_DECLARATION_NAME)
|
||||||
|
val NOT_A_MULTIPLATFORM_COMPILATION by error0<PsiElement>()
|
||||||
|
|
||||||
// Destructuring declaration
|
// Destructuring declaration
|
||||||
val INITIALIZER_REQUIRED_FOR_DESTRUCTURING_DECLARATION by error0<KtDestructuringDeclaration>()
|
val INITIALIZER_REQUIRED_FOR_DESTRUCTURING_DECLARATION by error0<KtDestructuringDeclaration>()
|
||||||
|
|||||||
+1
-2
@@ -41,8 +41,7 @@ object FirExpectActualDeclarationChecker : FirBasicDeclarationChecker() {
|
|||||||
if ((declaration.isExpect || declaration.isActual) && containsExpectOrActualModifier(declaration)) {
|
if ((declaration.isExpect || declaration.isActual) && containsExpectOrActualModifier(declaration)) {
|
||||||
reporter.reportOn(
|
reporter.reportOn(
|
||||||
declaration.source,
|
declaration.source,
|
||||||
FirErrors.UNSUPPORTED_FEATURE,
|
FirErrors.NOT_A_MULTIPLATFORM_COMPILATION,
|
||||||
LanguageFeature.MultiPlatformProjects to context.session.languageVersionSettings,
|
|
||||||
context,
|
context,
|
||||||
positioningStrategy = SourceElementPositioningStrategies.EXPECT_ACTUAL_MODIFIER
|
positioningStrategy = SourceElementPositioningStrategies.EXPECT_ACTUAL_MODIFIER
|
||||||
)
|
)
|
||||||
|
|||||||
+2
@@ -343,6 +343,7 @@ import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.MISSING_STDLIB_CL
|
|||||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.MISSING_VAL_ON_ANNOTATION_PARAMETER
|
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.MISSING_VAL_ON_ANNOTATION_PARAMETER
|
||||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.MODIFIER_FORM_FOR_NON_BUILT_IN_SUSPEND
|
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.MODIFIER_FORM_FOR_NON_BUILT_IN_SUSPEND
|
||||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.MODIFIER_FORM_FOR_NON_BUILT_IN_SUSPEND_FUN
|
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.MODIFIER_FORM_FOR_NON_BUILT_IN_SUSPEND_FUN
|
||||||
|
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.NOT_A_MULTIPLATFORM_COMPILATION
|
||||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.MULTIPLE_ARGUMENTS_APPLICABLE_FOR_CONTEXT_RECEIVER
|
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.MULTIPLE_ARGUMENTS_APPLICABLE_FOR_CONTEXT_RECEIVER
|
||||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.MULTIPLE_VARARG_PARAMETERS
|
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.MULTIPLE_VARARG_PARAMETERS
|
||||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.MULTI_FIELD_VALUE_CLASS_PRIMARY_CONSTRUCTOR_DEFAULT_PARAMETER
|
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.MULTI_FIELD_VALUE_CLASS_PRIMARY_CONSTRUCTOR_DEFAULT_PARAMETER
|
||||||
@@ -1843,6 +1844,7 @@ object FirErrorsDefaultMessages : BaseDiagnosticRendererFactory() {
|
|||||||
FirIncompatibleExpectedActualClassScopesRenderer.TEXT
|
FirIncompatibleExpectedActualClassScopesRenderer.TEXT
|
||||||
)
|
)
|
||||||
map.put(ACTUAL_MISSING, "Declaration must be marked with 'actual'")
|
map.put(ACTUAL_MISSING, "Declaration must be marked with 'actual'")
|
||||||
|
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")
|
||||||
|
|
||||||
// Destructuring declaration
|
// Destructuring declaration
|
||||||
map.put(INITIALIZER_REQUIRED_FOR_DESTRUCTURING_DECLARATION, "Initializer required for destructuring declaration")
|
map.put(INITIALIZER_REQUIRED_FOR_DESTRUCTURING_DECLARATION, "Initializer required for destructuring declaration")
|
||||||
|
|||||||
@@ -835,6 +835,7 @@ public interface Errors {
|
|||||||
DiagnosticFactory0<PsiElement> OPTIONAL_EXPECTATION_NOT_ON_EXPECTED = DiagnosticFactory0.create(ERROR);
|
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_OUTSIDE_OF_ANNOTATION_ENTRY = DiagnosticFactory0.create(ERROR);
|
||||||
DiagnosticFactory0<PsiElement> OPTIONAL_DECLARATION_USAGE_IN_NON_COMMON_SOURCE = DiagnosticFactory0.create(ERROR);
|
DiagnosticFactory0<PsiElement> OPTIONAL_DECLARATION_USAGE_IN_NON_COMMON_SOURCE = DiagnosticFactory0.create(ERROR);
|
||||||
|
DiagnosticFactory0<PsiElement> NOT_A_MULTIPLATFORM_COMPILATION = DiagnosticFactory0.create(ERROR);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|||||||
+1
@@ -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_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_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(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(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");
|
MAP.put(SUPERTYPE_NOT_INITIALIZED, "This type has a constructor, and thus must be initialized here");
|
||||||
|
|||||||
@@ -216,8 +216,6 @@ object ModifierCheckerCore {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
val featureSupport = languageVersionSettings.getFeatureSupport(dependency)
|
|
||||||
|
|
||||||
if (dependency == LanguageFeature.Coroutines) {
|
if (dependency == LanguageFeature.Coroutines) {
|
||||||
checkCoroutinesFeature(languageVersionSettings, trace, node.psi)
|
checkCoroutinesFeature(languageVersionSettings, trace, node.psi)
|
||||||
continue
|
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
|
val diagnosticData = dependency to languageVersionSettings
|
||||||
when (featureSupport) {
|
when (featureSupport) {
|
||||||
LanguageFeature.State.ENABLED_WITH_WARNING -> {
|
LanguageFeature.State.ENABLED_WITH_WARNING -> {
|
||||||
|
|||||||
+9
-9
@@ -1,17 +1,17 @@
|
|||||||
// FIR_IDENTICAL
|
// FIR_IDENTICAL
|
||||||
<!UNSUPPORTED_FEATURE!>expect<!> fun foo1()
|
<!NOT_A_MULTIPLATFORM_COMPILATION!>expect<!> fun foo1()
|
||||||
<!UNSUPPORTED_FEATURE!>expect<!> val bar1 = <!EXPECTED_PROPERTY_INITIALIZER!>42<!>
|
<!NOT_A_MULTIPLATFORM_COMPILATION!>expect<!> val bar1 = <!EXPECTED_PROPERTY_INITIALIZER!>42<!>
|
||||||
<!UNSUPPORTED_FEATURE!>expect<!> class Baz1 {
|
<!NOT_A_MULTIPLATFORM_COMPILATION!>expect<!> class Baz1 {
|
||||||
fun foo()
|
fun foo()
|
||||||
|
|
||||||
class Baz12
|
class Baz12
|
||||||
}
|
}
|
||||||
|
|
||||||
<!UNSUPPORTED_FEATURE!>actual<!> fun foo2() = 42
|
<!NOT_A_MULTIPLATFORM_COMPILATION!>actual<!> fun foo2() = 42
|
||||||
<!MUST_BE_INITIALIZED!><!UNSUPPORTED_FEATURE!>actual<!> val bar2: Int<!>
|
<!MUST_BE_INITIALIZED!><!NOT_A_MULTIPLATFORM_COMPILATION!>actual<!> val bar2: Int<!>
|
||||||
<!UNSUPPORTED_FEATURE!>actual<!> interface Baz2
|
<!NOT_A_MULTIPLATFORM_COMPILATION!>actual<!> interface Baz2
|
||||||
|
|
||||||
<!UNSUPPORTED_FEATURE!>actual<!> class Baz1 {
|
<!NOT_A_MULTIPLATFORM_COMPILATION!>actual<!> class Baz1 {
|
||||||
<!UNSUPPORTED_FEATURE!>actual<!> fun foo() {
|
<!NOT_A_MULTIPLATFORM_COMPILATION!>actual<!> fun foo() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user