KMP: Put "prohbit expect/actual different annotations" under the flag
^KT-61668 Fixed Review: https://jetbrains.team/p/kt/reviews/12062/timeline
This commit is contained in:
+6
@@ -746,6 +746,12 @@ public class FirOldFrontendMPPDiagnosticsWithLightTreeTestGenerated extends Abst
|
||||
runTest("compiler/testData/diagnostics/tests/multiplatform/annotationMatching/annotationArgumentsDefaults.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("annotationMatching_oldLanguageVersion.kt")
|
||||
public void testAnnotationMatching_oldLanguageVersion() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/multiplatform/annotationMatching/annotationMatching_oldLanguageVersion.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("annotationTarget.kt")
|
||||
public void testAnnotationTarget() throws Exception {
|
||||
|
||||
+6
@@ -746,6 +746,12 @@ public class FirOldFrontendMPPDiagnosticsWithPsiTestGenerated extends AbstractFi
|
||||
runTest("compiler/testData/diagnostics/tests/multiplatform/annotationMatching/annotationArgumentsDefaults.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("annotationMatching_oldLanguageVersion.kt")
|
||||
public void testAnnotationMatching_oldLanguageVersion() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/multiplatform/annotationMatching/annotationMatching_oldLanguageVersion.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("annotationTarget.kt")
|
||||
public void testAnnotationTarget() throws Exception {
|
||||
|
||||
+1
@@ -258,6 +258,7 @@ object FirExpectActualDeclarationChecker : FirBasicDeclarationChecker() {
|
||||
context: CheckerContext,
|
||||
reporter: DiagnosticReporter
|
||||
) {
|
||||
if (!context.languageVersionSettings.supportsFeature(LanguageFeature.MultiplatformRestrictions)) return
|
||||
val matchingContext = context.session.expectActualMatchingContextFactory.create(context.session, context.scopeSession)
|
||||
val incompatibility =
|
||||
AbstractExpectActualAnnotationMatchChecker.areAnnotationsCompatible(expectSymbol, actualSymbol, matchingContext) ?: return
|
||||
|
||||
+9
-7
@@ -78,7 +78,7 @@ class ExpectedActualDeclarationChecker(
|
||||
declaration,
|
||||
descriptor,
|
||||
checkActualModifier,
|
||||
context.trace,
|
||||
context,
|
||||
moduleVisibilityFilter = { it in allDependsOnModules }
|
||||
)
|
||||
}
|
||||
@@ -294,9 +294,10 @@ class ExpectedActualDeclarationChecker(
|
||||
reportOn: KtNamedDeclaration,
|
||||
descriptor: MemberDescriptor,
|
||||
checkActualModifier: Boolean,
|
||||
trace: BindingTrace,
|
||||
context: DeclarationCheckerContext,
|
||||
moduleVisibilityFilter: ModuleFilter
|
||||
) {
|
||||
val trace = context.trace
|
||||
val compatibility = ExpectedActualResolver
|
||||
.findExpectedForActual(descriptor, moduleVisibilityFilter, shouldCheckAbsenceOfDefaultParamsInActual = true)
|
||||
?: return
|
||||
@@ -381,7 +382,7 @@ class ExpectedActualDeclarationChecker(
|
||||
val expectSingleCandidate = (compatibility[Compatible] ?: compatibility.values.singleOrNull())?.singleOrNull()
|
||||
if (expectSingleCandidate != null) {
|
||||
checkIfExpectHasDefaultArgumentsAndActualizedWithTypealias(expectSingleCandidate, reportOn, trace)
|
||||
checkAnnotationsMatch(expectSingleCandidate, descriptor, reportOn, trace)
|
||||
checkAnnotationsMatch(expectSingleCandidate, descriptor, reportOn, context)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -488,12 +489,13 @@ class ExpectedActualDeclarationChecker(
|
||||
expectDescriptor: MemberDescriptor,
|
||||
actualDescriptor: MemberDescriptor,
|
||||
reportOn: KtNamedDeclaration,
|
||||
trace: BindingTrace
|
||||
context: DeclarationCheckerContext
|
||||
) {
|
||||
val context = ClassicExpectActualMatchingContext(actualDescriptor.module)
|
||||
if (!context.languageVersionSettings.supportsFeature(LanguageFeature.MultiplatformRestrictions)) return
|
||||
val matchingContext = ClassicExpectActualMatchingContext(actualDescriptor.module)
|
||||
val incompatibility =
|
||||
AbstractExpectActualAnnotationMatchChecker.areAnnotationsCompatible(expectDescriptor, actualDescriptor, context) ?: return
|
||||
trace.report(
|
||||
AbstractExpectActualAnnotationMatchChecker.areAnnotationsCompatible(expectDescriptor, actualDescriptor, matchingContext) ?: return
|
||||
context.trace.report(
|
||||
Errors.ACTUAL_ANNOTATIONS_NOT_MATCH_EXPECT.on(
|
||||
reportOn,
|
||||
incompatibility.expectSymbol as DeclarationDescriptor,
|
||||
|
||||
+4
-1
@@ -6,6 +6,7 @@
|
||||
package org.jetbrains.kotlin.backend.common.actualizer
|
||||
|
||||
import org.jetbrains.kotlin.KtDiagnosticReporterWithImplicitIrBasedContext
|
||||
import org.jetbrains.kotlin.config.LanguageFeature
|
||||
import org.jetbrains.kotlin.config.LanguageVersionSettings
|
||||
import org.jetbrains.kotlin.diagnostics.DiagnosticReporter
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
@@ -38,7 +39,9 @@ object IrActualizer {
|
||||
typeSystemContext,
|
||||
ktDiagnosticReporter
|
||||
).collect()
|
||||
IrExpectActualAnnotationMatchingChecker(expectActualMap, actualDeclarations, typeSystemContext, ktDiagnosticReporter).check()
|
||||
if (languageVersionSettings.supportsFeature(LanguageFeature.MultiplatformRestrictions)) {
|
||||
IrExpectActualAnnotationMatchingChecker(expectActualMap, actualDeclarations, typeSystemContext, ktDiagnosticReporter).check()
|
||||
}
|
||||
|
||||
// 2. Remove top-only expect declarations since they are not needed anymore and should not be presented in the final IrFragment
|
||||
// Expect fake-overrides from non-expect classes remain untouched since they will be actualized in the next phase.
|
||||
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
// FIR_IDENTICAL
|
||||
// LANGUAGE: -MultiplatformRestrictions
|
||||
// MODULE: m1-common
|
||||
// FILE: common.kt
|
||||
annotation class Ann
|
||||
|
||||
@Ann
|
||||
expect class AnnotationOnExpectOnly
|
||||
|
||||
expect class AnnotationInside {
|
||||
@Ann
|
||||
fun onlyOnExpect()
|
||||
}
|
||||
|
||||
// MODULE: m1-jvm()()(m1-common)
|
||||
// FILE: jvm.kt
|
||||
|
||||
actual class AnnotationOnExpectOnly
|
||||
|
||||
actual class AnnotationInside {
|
||||
actual fun onlyOnExpect() {}
|
||||
}
|
||||
Generated
+6
@@ -23741,6 +23741,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
||||
runTest("compiler/testData/diagnostics/tests/multiplatform/annotationMatching/annotationArgumentsDefaults.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("annotationMatching_oldLanguageVersion.kt")
|
||||
public void testAnnotationMatching_oldLanguageVersion() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/multiplatform/annotationMatching/annotationMatching_oldLanguageVersion.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("annotationTarget.kt")
|
||||
public void testAnnotationTarget() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user