From 2faa247075a6eeed5a963afed08783ed0aa43070 Mon Sep 17 00:00:00 2001 From: Marco Pennekamp Date: Mon, 19 Dec 2022 23:21:26 +0100 Subject: [PATCH] [FIR] KT-55570 Fix `ACTUAL_WITHOUT_EXPECT` reporting for empty classes - FirExpectActualMatcherTransformer: Instead of returning, `transformMemberDeclaration` must assign an empty map to `expectForActualData` so that `FirExpectActualDeclarationChecker` doesn't assume that the member declaration needs no expect-actual checking. ^KT-55570 fixed --- ...CompilerTestFE10TestdataTestGenerated.java | 12 ++++ ...irOldFrontendDiagnosticsTestGenerated.java | 12 ++++ ...DiagnosticsWithLightTreeTestGenerated.java | 12 ++++ .../mpp/FirExpectActualMatcherTransformer.kt | 6 +- .../hmpp/intermediateWithActualAndExpect.kt | 15 +++++ .../hmpp/intermediateWithActualAndExpect.txt | 66 +++++++++++++++++++ .../tests/multiplatform/hmpp/kt-55570.fir.kt | 5 ++ .../tests/multiplatform/hmpp/kt-55570.kt | 5 ++ .../tests/multiplatform/hmpp/kt-55570.txt | 13 ++++ .../tests/multiplatform/hmpp/simple.kt | 8 --- .../tests/multiplatform/incompatibles.fir.kt | 10 +-- .../modifierApplicability.fir.kt | 2 +- .../test/runners/DiagnosticTestGenerated.java | 12 ++++ 13 files changed, 163 insertions(+), 15 deletions(-) create mode 100644 compiler/testData/diagnostics/tests/multiplatform/hmpp/intermediateWithActualAndExpect.kt create mode 100644 compiler/testData/diagnostics/tests/multiplatform/hmpp/intermediateWithActualAndExpect.txt create mode 100644 compiler/testData/diagnostics/tests/multiplatform/hmpp/kt-55570.fir.kt create mode 100644 compiler/testData/diagnostics/tests/multiplatform/hmpp/kt-55570.kt create mode 100644 compiler/testData/diagnostics/tests/multiplatform/hmpp/kt-55570.txt diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java index 2562903fe21..8d7a5b22f4d 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java @@ -21827,6 +21827,18 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/multiplatform/hmpp"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.(fir|ll)\\.kts?$"), true); } + @Test + @TestMetadata("intermediateWithActualAndExpect.kt") + public void testIntermediateWithActualAndExpect() throws Exception { + runTest("compiler/testData/diagnostics/tests/multiplatform/hmpp/intermediateWithActualAndExpect.kt"); + } + + @Test + @TestMetadata("kt-55570.kt") + public void testKt_55570() throws Exception { + runTest("compiler/testData/diagnostics/tests/multiplatform/hmpp/kt-55570.kt"); + } + @Test @TestMetadata("sealedInheritorsInComplexModuleStructure.kt") public void testSealedInheritorsInComplexModuleStructure() throws Exception { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java index 4d520435c9f..36f89435ace 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java @@ -21833,6 +21833,18 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/multiplatform/hmpp"), Pattern.compile("^(.*)\\.kts?$"), Pattern.compile("^(.+)\\.(fir|ll)\\.kts?$"), true); } + @Test + @TestMetadata("intermediateWithActualAndExpect.kt") + public void testIntermediateWithActualAndExpect() throws Exception { + runTest("compiler/testData/diagnostics/tests/multiplatform/hmpp/intermediateWithActualAndExpect.kt"); + } + + @Test + @TestMetadata("kt-55570.kt") + public void testKt_55570() throws Exception { + runTest("compiler/testData/diagnostics/tests/multiplatform/hmpp/kt-55570.kt"); + } + @Test @TestMetadata("sealedInheritorsInComplexModuleStructure.kt") public void testSealedInheritorsInComplexModuleStructure() throws Exception { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java index 2e4541c1b1a..05d6e5f6748 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java @@ -21827,6 +21827,18 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/multiplatform/hmpp"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.(fir|ll)\\.kts?$"), true); } + @Test + @TestMetadata("intermediateWithActualAndExpect.kt") + public void testIntermediateWithActualAndExpect() throws Exception { + runTest("compiler/testData/diagnostics/tests/multiplatform/hmpp/intermediateWithActualAndExpect.kt"); + } + + @Test + @TestMetadata("kt-55570.kt") + public void testKt_55570() throws Exception { + runTest("compiler/testData/diagnostics/tests/multiplatform/hmpp/kt-55570.kt"); + } + @Test @TestMetadata("sealedInheritorsInComplexModuleStructure.kt") public void testSealedInheritorsInComplexModuleStructure() throws Exception { diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/mpp/FirExpectActualMatcherTransformer.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/mpp/FirExpectActualMatcherTransformer.kt index 4b40808c90e..a92cf94f6fa 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/mpp/FirExpectActualMatcherTransformer.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/mpp/FirExpectActualMatcherTransformer.kt @@ -79,11 +79,15 @@ open class FirExpectActualMatcherTransformer( private fun transformMemberDeclaration(memberDeclaration: FirMemberDeclaration) { if (!memberDeclaration.isActual) return val actualSymbol = memberDeclaration.symbol + + // Regardless of whether any `expect` symbols are found for `memberDeclaration`, it must be assigned an `expectForActual` map. + // Otherwise, `FirExpectActualDeclarationChecker` will assume that the symbol needs no checking and not report an + // `EXPECT_WITHOUT_ACTUAL` error. val expectForActualData = FirExpectActualResolver.findExpectForActual( actualSymbol, session, scopeSession - ) ?: return + ) ?: mapOf() memberDeclaration.expectForActual = expectForActualData for ((compatibility, expectSymbols) in expectForActualData) { if (compatibility.compatible) { diff --git a/compiler/testData/diagnostics/tests/multiplatform/hmpp/intermediateWithActualAndExpect.kt b/compiler/testData/diagnostics/tests/multiplatform/hmpp/intermediateWithActualAndExpect.kt new file mode 100644 index 00000000000..e2fc28749fc --- /dev/null +++ b/compiler/testData/diagnostics/tests/multiplatform/hmpp/intermediateWithActualAndExpect.kt @@ -0,0 +1,15 @@ +// FIR_IDENTICAL + +// MODULE: common +// TARGET_PLATFORM: Common +expect class A +expect class B + +// MODULE: intermediate()()(common) +// TARGET_PLATFORM: Common +actual class B +expect class C + +// MODULE: main()()(intermediate) +actual class A +actual class C diff --git a/compiler/testData/diagnostics/tests/multiplatform/hmpp/intermediateWithActualAndExpect.txt b/compiler/testData/diagnostics/tests/multiplatform/hmpp/intermediateWithActualAndExpect.txt new file mode 100644 index 00000000000..bc475e77ac2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/multiplatform/hmpp/intermediateWithActualAndExpect.txt @@ -0,0 +1,66 @@ +// -- Module: -- +package + +public final expect class A { + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final expect class B { + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +// -- Module: -- +package + +public final expect class A { + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final actual class B { + public constructor B() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final expect class B { + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final expect class C { + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +// -- Module:
-- +package + +public final actual class A { + public constructor A() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final actual class B { + public constructor B() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final actual class C { + public constructor C() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/diagnostics/tests/multiplatform/hmpp/kt-55570.fir.kt b/compiler/testData/diagnostics/tests/multiplatform/hmpp/kt-55570.fir.kt new file mode 100644 index 00000000000..ed0a8d34e14 --- /dev/null +++ b/compiler/testData/diagnostics/tests/multiplatform/hmpp/kt-55570.fir.kt @@ -0,0 +1,5 @@ +// MODULE: common +// TARGET_PLATFORM: Common + +// MODULE: main()()(common) +actual class A diff --git a/compiler/testData/diagnostics/tests/multiplatform/hmpp/kt-55570.kt b/compiler/testData/diagnostics/tests/multiplatform/hmpp/kt-55570.kt new file mode 100644 index 00000000000..5e53ddc9b04 --- /dev/null +++ b/compiler/testData/diagnostics/tests/multiplatform/hmpp/kt-55570.kt @@ -0,0 +1,5 @@ +// MODULE: common +// TARGET_PLATFORM: Common + +// MODULE: main()()(common) +actual class A diff --git a/compiler/testData/diagnostics/tests/multiplatform/hmpp/kt-55570.txt b/compiler/testData/diagnostics/tests/multiplatform/hmpp/kt-55570.txt new file mode 100644 index 00000000000..870e5fdda04 --- /dev/null +++ b/compiler/testData/diagnostics/tests/multiplatform/hmpp/kt-55570.txt @@ -0,0 +1,13 @@ +// -- Module: -- +package + + +// -- Module:
-- +package + +public final actual class A { + public constructor A() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/diagnostics/tests/multiplatform/hmpp/simple.kt b/compiler/testData/diagnostics/tests/multiplatform/hmpp/simple.kt index b9a2a1a3419..8df3cabd382 100644 --- a/compiler/testData/diagnostics/tests/multiplatform/hmpp/simple.kt +++ b/compiler/testData/diagnostics/tests/multiplatform/hmpp/simple.kt @@ -1,13 +1,5 @@ // FIR_IDENTICAL // FIR_IDE_IGNORE -/* - * This test is used for general testing of how compiler diagnostics tests for HMPP projects works - * Js backend is ignored because they use old test infrastructure which doesn't support HMPP - */ - - -// IGNORE_BACKEND_K2: JVM_IR -// TARGET_BACKEND: JVM // MODULE: common // TARGET_PLATFORM: Common diff --git a/compiler/testData/diagnostics/tests/multiplatform/incompatibles.fir.kt b/compiler/testData/diagnostics/tests/multiplatform/incompatibles.fir.kt index 9665559832c..5ff617bf181 100644 --- a/compiler/testData/diagnostics/tests/multiplatform/incompatibles.fir.kt +++ b/compiler/testData/diagnostics/tests/multiplatform/incompatibles.fir.kt @@ -1,12 +1,12 @@ -header impl class First +header impl class First header expect class Second -header actual class Third +header actual class Third -impl expect class Fourth +impl expect class Fourth -impl actual class Fifth +impl actual class Fifth -expect actual class Sixth +expect actual class Sixth diff --git a/compiler/testData/diagnostics/tests/multiplatform/modifierApplicability.fir.kt b/compiler/testData/diagnostics/tests/multiplatform/modifierApplicability.fir.kt index 6240999700a..7b2f6e72f05 100644 --- a/compiler/testData/diagnostics/tests/multiplatform/modifierApplicability.fir.kt +++ b/compiler/testData/diagnostics/tests/multiplatform/modifierApplicability.fir.kt @@ -22,7 +22,7 @@ fun foo() { // FILE: jvm.kt class Outer actual constructor() { - actual class Nested + actual class Nested actual init {} } diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java index 7ae0452863b..7a535aa9bd5 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java @@ -21833,6 +21833,18 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/multiplatform/hmpp"), Pattern.compile("^(.*)\\.kts?$"), Pattern.compile("^(.+)\\.(fir|ll)\\.kts?$"), true); } + @Test + @TestMetadata("intermediateWithActualAndExpect.kt") + public void testIntermediateWithActualAndExpect() throws Exception { + runTest("compiler/testData/diagnostics/tests/multiplatform/hmpp/intermediateWithActualAndExpect.kt"); + } + + @Test + @TestMetadata("kt-55570.kt") + public void testKt_55570() throws Exception { + runTest("compiler/testData/diagnostics/tests/multiplatform/hmpp/kt-55570.kt"); + } + @Test @TestMetadata("sealedInheritorsInComplexModuleStructure.kt") public void testSealedInheritorsInComplexModuleStructure() throws Exception {