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");
|
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
|
@Test
|
||||||
@TestMetadata("annotationTarget.kt")
|
@TestMetadata("annotationTarget.kt")
|
||||||
public void testAnnotationTarget() throws Exception {
|
public void testAnnotationTarget() throws Exception {
|
||||||
|
|||||||
+6
@@ -746,6 +746,12 @@ public class FirOldFrontendMPPDiagnosticsWithPsiTestGenerated extends AbstractFi
|
|||||||
runTest("compiler/testData/diagnostics/tests/multiplatform/annotationMatching/annotationArgumentsDefaults.kt");
|
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
|
@Test
|
||||||
@TestMetadata("annotationTarget.kt")
|
@TestMetadata("annotationTarget.kt")
|
||||||
public void testAnnotationTarget() throws Exception {
|
public void testAnnotationTarget() throws Exception {
|
||||||
|
|||||||
+1
@@ -258,6 +258,7 @@ object FirExpectActualDeclarationChecker : FirBasicDeclarationChecker() {
|
|||||||
context: CheckerContext,
|
context: CheckerContext,
|
||||||
reporter: DiagnosticReporter
|
reporter: DiagnosticReporter
|
||||||
) {
|
) {
|
||||||
|
if (!context.languageVersionSettings.supportsFeature(LanguageFeature.MultiplatformRestrictions)) return
|
||||||
val matchingContext = context.session.expectActualMatchingContextFactory.create(context.session, context.scopeSession)
|
val matchingContext = context.session.expectActualMatchingContextFactory.create(context.session, context.scopeSession)
|
||||||
val incompatibility =
|
val incompatibility =
|
||||||
AbstractExpectActualAnnotationMatchChecker.areAnnotationsCompatible(expectSymbol, actualSymbol, matchingContext) ?: return
|
AbstractExpectActualAnnotationMatchChecker.areAnnotationsCompatible(expectSymbol, actualSymbol, matchingContext) ?: return
|
||||||
|
|||||||
+9
-7
@@ -78,7 +78,7 @@ class ExpectedActualDeclarationChecker(
|
|||||||
declaration,
|
declaration,
|
||||||
descriptor,
|
descriptor,
|
||||||
checkActualModifier,
|
checkActualModifier,
|
||||||
context.trace,
|
context,
|
||||||
moduleVisibilityFilter = { it in allDependsOnModules }
|
moduleVisibilityFilter = { it in allDependsOnModules }
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -294,9 +294,10 @@ class ExpectedActualDeclarationChecker(
|
|||||||
reportOn: KtNamedDeclaration,
|
reportOn: KtNamedDeclaration,
|
||||||
descriptor: MemberDescriptor,
|
descriptor: MemberDescriptor,
|
||||||
checkActualModifier: Boolean,
|
checkActualModifier: Boolean,
|
||||||
trace: BindingTrace,
|
context: DeclarationCheckerContext,
|
||||||
moduleVisibilityFilter: ModuleFilter
|
moduleVisibilityFilter: ModuleFilter
|
||||||
) {
|
) {
|
||||||
|
val trace = context.trace
|
||||||
val compatibility = ExpectedActualResolver
|
val compatibility = ExpectedActualResolver
|
||||||
.findExpectedForActual(descriptor, moduleVisibilityFilter, shouldCheckAbsenceOfDefaultParamsInActual = true)
|
.findExpectedForActual(descriptor, moduleVisibilityFilter, shouldCheckAbsenceOfDefaultParamsInActual = true)
|
||||||
?: return
|
?: return
|
||||||
@@ -381,7 +382,7 @@ class ExpectedActualDeclarationChecker(
|
|||||||
val expectSingleCandidate = (compatibility[Compatible] ?: compatibility.values.singleOrNull())?.singleOrNull()
|
val expectSingleCandidate = (compatibility[Compatible] ?: compatibility.values.singleOrNull())?.singleOrNull()
|
||||||
if (expectSingleCandidate != null) {
|
if (expectSingleCandidate != null) {
|
||||||
checkIfExpectHasDefaultArgumentsAndActualizedWithTypealias(expectSingleCandidate, reportOn, trace)
|
checkIfExpectHasDefaultArgumentsAndActualizedWithTypealias(expectSingleCandidate, reportOn, trace)
|
||||||
checkAnnotationsMatch(expectSingleCandidate, descriptor, reportOn, trace)
|
checkAnnotationsMatch(expectSingleCandidate, descriptor, reportOn, context)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -488,12 +489,13 @@ class ExpectedActualDeclarationChecker(
|
|||||||
expectDescriptor: MemberDescriptor,
|
expectDescriptor: MemberDescriptor,
|
||||||
actualDescriptor: MemberDescriptor,
|
actualDescriptor: MemberDescriptor,
|
||||||
reportOn: KtNamedDeclaration,
|
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 =
|
val incompatibility =
|
||||||
AbstractExpectActualAnnotationMatchChecker.areAnnotationsCompatible(expectDescriptor, actualDescriptor, context) ?: return
|
AbstractExpectActualAnnotationMatchChecker.areAnnotationsCompatible(expectDescriptor, actualDescriptor, matchingContext) ?: return
|
||||||
trace.report(
|
context.trace.report(
|
||||||
Errors.ACTUAL_ANNOTATIONS_NOT_MATCH_EXPECT.on(
|
Errors.ACTUAL_ANNOTATIONS_NOT_MATCH_EXPECT.on(
|
||||||
reportOn,
|
reportOn,
|
||||||
incompatibility.expectSymbol as DeclarationDescriptor,
|
incompatibility.expectSymbol as DeclarationDescriptor,
|
||||||
|
|||||||
+4
-1
@@ -6,6 +6,7 @@
|
|||||||
package org.jetbrains.kotlin.backend.common.actualizer
|
package org.jetbrains.kotlin.backend.common.actualizer
|
||||||
|
|
||||||
import org.jetbrains.kotlin.KtDiagnosticReporterWithImplicitIrBasedContext
|
import org.jetbrains.kotlin.KtDiagnosticReporterWithImplicitIrBasedContext
|
||||||
|
import org.jetbrains.kotlin.config.LanguageFeature
|
||||||
import org.jetbrains.kotlin.config.LanguageVersionSettings
|
import org.jetbrains.kotlin.config.LanguageVersionSettings
|
||||||
import org.jetbrains.kotlin.diagnostics.DiagnosticReporter
|
import org.jetbrains.kotlin.diagnostics.DiagnosticReporter
|
||||||
import org.jetbrains.kotlin.ir.declarations.*
|
import org.jetbrains.kotlin.ir.declarations.*
|
||||||
@@ -38,7 +39,9 @@ object IrActualizer {
|
|||||||
typeSystemContext,
|
typeSystemContext,
|
||||||
ktDiagnosticReporter
|
ktDiagnosticReporter
|
||||||
).collect()
|
).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
|
// 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.
|
// 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");
|
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
|
@Test
|
||||||
@TestMetadata("annotationTarget.kt")
|
@TestMetadata("annotationTarget.kt")
|
||||||
public void testAnnotationTarget() throws Exception {
|
public void testAnnotationTarget() throws Exception {
|
||||||
|
|||||||
Reference in New Issue
Block a user