Mark expect/actual classifiers as experimental

^KT-61573 Fixed
Review: https://jetbrains.team/p/kt/reviews/11969/timeline

Tests:
- MultiPlatformIntegrationTestGenerated
- CliTestGenerated
- MultiPlatformIntegrationTestGenerated
- DiagnosticTestGenerated.Multiplatform
- FirLightTreeOldFrontendDiagnosticsTestGenerated

Also add -Xexpect-actual-classes flag to all necessary ./libraries/* modules
Otherwise compilation of those modules failes because of `-Werror`
This commit is contained in:
Nikita Bobko
2023-08-30 15:39:19 +02:00
committed by Space Team
parent 6a19c4ce96
commit 01fc708a0f
68 changed files with 633 additions and 5 deletions
@@ -866,6 +866,8 @@ public interface Errors {
ACTUAL_CLASSIFIER_MUST_HAVE_THE_SAME_SUPERTYPES_AS_NON_FINAL_EXPECT_CLASSIFIER =
DiagnosticFactory3.create(ERROR, DECLARATION_NAME);
DiagnosticFactory0<KtClassLikeDeclaration> EXPECT_ACTUAL_CLASSIFIERS_ARE_EXPERIMENTAL_WARNING = DiagnosticFactory0.create(WARNING, EXPECT_ACTUAL_MODIFIER);
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);
@@ -16,7 +16,6 @@ import org.jetbrains.kotlin.diagnostics.Errors;
import org.jetbrains.kotlin.diagnostics.UnboundDiagnostic;
import org.jetbrains.kotlin.metadata.deserialization.VersionRequirement;
import org.jetbrains.kotlin.resolve.VarianceConflictDiagnosticData;
import org.jetbrains.kotlin.resolve.multiplatform.ExpectActualCompatibility;
import org.jetbrains.kotlin.resolve.multiplatform.ExpectActualCompatibility.Incompatible;
import org.jetbrains.kotlin.types.KotlinTypeKt;
import org.jetbrains.kotlin.util.OperatorNameConventions;
@@ -431,6 +430,10 @@ public class DefaultErrorMessages {
new ListRenderer<>(TO_STRING, (elem) -> "'" + elem + "'"),
NAME);
MAP.put(EXPECT_ACTUAL_CLASSIFIERS_ARE_EXPERIMENTAL_WARNING,
"The expect/actual classes (including interfaces, objects, annotations, enums, actual typealiases) are an experimental feature. " +
"You can use -Xexpect-actual-classes flag to suppress this warning.");
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");
@@ -17,6 +17,7 @@ import org.jetbrains.kotlin.types.DynamicTypesSettings
private val DEFAULT_DECLARATION_CHECKERS = listOf(
ExpectActualInTheSameModuleChecker,
ActualClassifierMustHasTheSameMembersAsNonFinalExpectClassifierChecker,
ExpectActualClassifiersAreExperimentalChecker,
DataClassDeclarationChecker(),
ConstModifierChecker,
UnderscoreChecker,
@@ -0,0 +1,37 @@
/*
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.resolve.checkers
import org.jetbrains.kotlin.config.AnalysisFlags
import org.jetbrains.kotlin.config.LanguageFeature
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.ClassifierDescriptorWithTypeParameters
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.descriptors.TypeAliasDescriptor
import org.jetbrains.kotlin.diagnostics.Errors
import org.jetbrains.kotlin.psi.KtClassLikeDeclaration
import org.jetbrains.kotlin.psi.KtClassOrObject
import org.jetbrains.kotlin.psi.KtDeclaration
import org.jetbrains.kotlin.psi.KtTypeAlias
object ExpectActualClassifiersAreExperimentalChecker : DeclarationChecker {
override fun check(declaration: KtDeclaration, descriptor: DeclarationDescriptor, context: DeclarationCheckerContext) {
if (!context.languageVersionSettings.supportsFeature(LanguageFeature.MultiPlatformProjects)) return
if (context.languageVersionSettings.getFlag(AnalysisFlags.muteExpectActualClassesWarning)) return
if (descriptor !is TypeAliasDescriptor && descriptor !is ClassDescriptor) return
check(declaration is KtClassOrObject || declaration is KtTypeAlias)
// Common supertype of KtTypeAlias and KtClassOrObject is KtClassLikeDeclaration.
// Common supertype of TypeAliasDescriptor and ClassDescriptor is ClassifierDescriptorWithTypeParameters.
// The explicit casts won't be necessary when we start compiling kotlin with K2.
check(declaration is KtClassLikeDeclaration)
check(descriptor is ClassifierDescriptorWithTypeParameters)
if (descriptor.isExpect || descriptor.isActual) {
context.trace.report(Errors.EXPECT_ACTUAL_CLASSIFIERS_ARE_EXPERIMENTAL_WARNING.on(declaration))
}
}
}