KMP: Put "prohibit expect actual OptIn annotations" under the flag
^KT-61668 Fixed Review: https://jetbrains.team/p/kt/reviews/12062/timeline
This commit is contained in:
+6
@@ -163,6 +163,12 @@ public class FirOldFrontendMPPDiagnosticsWithLightTreeTestGenerated extends Abst
|
||||
runTest("compiler/testData/diagnostics/tests/multiplatform/expectOptInAnnotation.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("expectOptInAnnotation_oldLanguageVersion.kt")
|
||||
public void testExpectOptInAnnotation_oldLanguageVersion() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/multiplatform/expectOptInAnnotation_oldLanguageVersion.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("expectTailrec.kt")
|
||||
public void testExpectTailrec() throws Exception {
|
||||
|
||||
+6
@@ -163,6 +163,12 @@ public class FirOldFrontendMPPDiagnosticsWithPsiTestGenerated extends AbstractFi
|
||||
runTest("compiler/testData/diagnostics/tests/multiplatform/expectOptInAnnotation.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("expectOptInAnnotation_oldLanguageVersion.kt")
|
||||
public void testExpectOptInAnnotation_oldLanguageVersion() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/multiplatform/expectOptInAnnotation_oldLanguageVersion.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("expectTailrec.kt")
|
||||
public void testExpectTailrec() throws Exception {
|
||||
|
||||
+2
-1
@@ -291,7 +291,8 @@ object FirExpectActualDeclarationChecker : FirBasicDeclarationChecker() {
|
||||
context: CheckerContext,
|
||||
reporter: DiagnosticReporter,
|
||||
) {
|
||||
if (declaration is FirClass &&
|
||||
if (context.languageVersionSettings.supportsFeature(LanguageFeature.MultiplatformRestrictions) &&
|
||||
declaration is FirClass &&
|
||||
declaration.classKind == ClassKind.ANNOTATION_CLASS &&
|
||||
!expectDeclarationSymbol.hasAnnotation(StandardClassIds.Annotations.OptionalExpectation, context.session) &&
|
||||
declaration.hasAnnotation(OptInNames.REQUIRES_OPT_IN_CLASS_ID, context.session)
|
||||
|
||||
+6
-5
@@ -70,7 +70,7 @@ class ExpectedActualDeclarationChecker(
|
||||
declaration, descriptor, context.trace,
|
||||
checkActualModifier, context
|
||||
)
|
||||
checkOptInAnnotation(declaration, descriptor, descriptor, context.trace)
|
||||
checkOptInAnnotation(declaration, descriptor, descriptor, context)
|
||||
}
|
||||
if (descriptor.isActualOrSomeContainerIsActual()) {
|
||||
val allDependsOnModules = moduleStructureOracle.findAllDependsOnPaths(descriptor.module).flatMap { it.nodes }.toHashSet()
|
||||
@@ -376,7 +376,7 @@ class ExpectedActualDeclarationChecker(
|
||||
if (expectedConstructor != null && actualConstructor != null) {
|
||||
checkAnnotationConstructors(expectedConstructor, actualConstructor, trace, reportOn)
|
||||
}
|
||||
checkOptInAnnotation(reportOn, descriptor, expected, trace)
|
||||
checkOptInAnnotation(reportOn, descriptor, expected, context)
|
||||
}
|
||||
}
|
||||
// We want to report errors even if a candidate is incompatible, but it's single
|
||||
@@ -475,14 +475,15 @@ class ExpectedActualDeclarationChecker(
|
||||
reportOn: KtNamedDeclaration,
|
||||
descriptor: MemberDescriptor,
|
||||
expectDescriptor: MemberDescriptor,
|
||||
trace: BindingTrace,
|
||||
context: DeclarationCheckerContext,
|
||||
) {
|
||||
if (descriptor is ClassDescriptor &&
|
||||
if (context.languageVersionSettings.supportsFeature(LanguageFeature.MultiplatformRestrictions) &&
|
||||
descriptor is ClassDescriptor &&
|
||||
descriptor.kind == ClassKind.ANNOTATION_CLASS &&
|
||||
descriptor.annotations.hasAnnotation(OptInNames.REQUIRES_OPT_IN_FQ_NAME) &&
|
||||
!expectDescriptor.annotations.hasAnnotation(OptionalAnnotationUtil.OPTIONAL_EXPECTATION_FQ_NAME)
|
||||
) {
|
||||
trace.report(Errors.EXPECT_ACTUAL_OPT_IN_ANNOTATION.on(reportOn))
|
||||
context.trace.report(Errors.EXPECT_ACTUAL_OPT_IN_ANNOTATION.on(reportOn))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Vendored
+19
@@ -0,0 +1,19 @@
|
||||
// FIR_IDENTICAL
|
||||
// LANGUAGE: -MultiplatformRestrictions
|
||||
// WITH_STDLIB
|
||||
// MODULE: m1-common
|
||||
// FILE: common.kt
|
||||
@file:OptIn(ExperimentalMultiplatform::class)
|
||||
|
||||
expect annotation class ActualOnly
|
||||
|
||||
@RequiresOptIn
|
||||
expect annotation class Both
|
||||
|
||||
// MODULE: m1-jvm()()(m1-common)
|
||||
// FILE: jvm.kt
|
||||
@RequiresOptIn
|
||||
actual annotation class ActualOnly
|
||||
|
||||
@RequiresOptIn
|
||||
actual annotation class Both
|
||||
Generated
+6
@@ -23158,6 +23158,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
||||
runTest("compiler/testData/diagnostics/tests/multiplatform/expectOptInAnnotation.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("expectOptInAnnotation_oldLanguageVersion.kt")
|
||||
public void testExpectOptInAnnotation_oldLanguageVersion() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/multiplatform/expectOptInAnnotation_oldLanguageVersion.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("expectTailrec.kt")
|
||||
public void testExpectTailrec() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user