[FIR] Fix missing ACTUAL_WITHOUT_EXPECT when expect is fake-override
^KT-65270 Fixed
KT review: https://jetbrains.team/p/kt/reviews/14064/timeline
IJ review: https://jetbrains.team/p/ij/reviews/124657/timeline
diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFE10TestdataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFE10TestdataTestGenerated.java
index 19017f5..59982ce 100644
--- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFE10TestdataTestGenerated.java
+++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFE10TestdataTestGenerated.java
@@ -24778,6 +24778,12 @@
}
@Test
+ @TestMetadata("actualWithoutExpectWhenExpectIsFakeOverride.kt")
+ public void testActualWithoutExpectWhenExpectIsFakeOverride() throws Exception {
+ runTest("compiler/testData/diagnostics/tests/multiplatform/actualWithoutExpectWhenExpectIsFakeOverride.kt");
+ }
+
+ @Test
public void testAllFilesPresentInMultiplatform() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/multiplatform"), Pattern.compile("^(.+)\\.(kt|kts)$"), Pattern.compile("^(.+)\\.(reversed|fir|ll)\\.kts?$"), true);
}
diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated.java
index 8a941b4..a040b39 100644
--- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated.java
+++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated.java
@@ -24778,6 +24778,12 @@
}
@Test
+ @TestMetadata("actualWithoutExpectWhenExpectIsFakeOverride.kt")
+ public void testActualWithoutExpectWhenExpectIsFakeOverride() throws Exception {
+ runTest("compiler/testData/diagnostics/tests/multiplatform/actualWithoutExpectWhenExpectIsFakeOverride.kt");
+ }
+
+ @Test
public void testAllFilesPresentInMultiplatform() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/multiplatform"), Pattern.compile("^(.+)\\.(kt|kts)$"), Pattern.compile("^(.+)\\.(reversed|fir|ll)\\.kts?$"), true);
}
diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendMPPDiagnosticsWithLightTreeTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendMPPDiagnosticsWithLightTreeTestGenerated.java
index 1074010..f2d1640 100644
--- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendMPPDiagnosticsWithLightTreeTestGenerated.java
+++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendMPPDiagnosticsWithLightTreeTestGenerated.java
@@ -63,6 +63,12 @@
}
@Test
+ @TestMetadata("actualWithoutExpectWhenExpectIsFakeOverride.kt")
+ public void testActualWithoutExpectWhenExpectIsFakeOverride() throws Exception {
+ runTest("compiler/testData/diagnostics/tests/multiplatform/actualWithoutExpectWhenExpectIsFakeOverride.kt");
+ }
+
+ @Test
public void testAllFilesPresentInMultiplatform() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/multiplatform"), Pattern.compile("^(.*)\\.kts?$"), Pattern.compile("^(.+)\\.(reversed|fir|ll)\\.kts?$"), TargetBackend.JVM_IR, true);
}
diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendMPPDiagnosticsWithPsiTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendMPPDiagnosticsWithPsiTestGenerated.java
index de3e49ab..1bdd746 100644
--- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendMPPDiagnosticsWithPsiTestGenerated.java
+++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendMPPDiagnosticsWithPsiTestGenerated.java
@@ -63,6 +63,12 @@
}
@Test
+ @TestMetadata("actualWithoutExpectWhenExpectIsFakeOverride.kt")
+ public void testActualWithoutExpectWhenExpectIsFakeOverride() throws Exception {
+ runTest("compiler/testData/diagnostics/tests/multiplatform/actualWithoutExpectWhenExpectIsFakeOverride.kt");
+ }
+
+ @Test
public void testAllFilesPresentInMultiplatform() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/multiplatform"), Pattern.compile("^(.*)\\.kts?$"), Pattern.compile("^(.+)\\.(reversed|fir|ll)\\.kts?$"), TargetBackend.JVM_IR, true);
}
diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirExpectActualDeclarationChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirExpectActualDeclarationChecker.kt
index 98e8e5c..d483348 100644
--- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirExpectActualDeclarationChecker.kt
+++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirExpectActualDeclarationChecker.kt
@@ -174,7 +174,10 @@
reportClassScopesIncompatibility(symbol, expectedSingleCandidate, declaration, checkingCompatibility, reporter, source, context)
}
- ExpectActualMatchingCompatibility.MatchedSuccessfully !in matchingCompatibilityToMembersMap -> {
+ ExpectActualMatchingCompatibility.MatchedSuccessfully !in matchingCompatibilityToMembersMap ||
+ expectedSingleCandidate != null &&
+ declaration.hasActualModifier() &&
+ expectedSingleCandidate.isFakeOverride(expectContainingClass, expectActualMatchingContext) -> {
reporter.reportOn(
source,
FirErrors.ACTUAL_WITHOUT_EXPECT,
diff --git a/compiler/testData/diagnostics/tests/multiplatform/actualWithoutExpectWhenExpectIsFakeOverride.fir.kt b/compiler/testData/diagnostics/tests/multiplatform/actualWithoutExpectWhenExpectIsFakeOverride.fir.kt
new file mode 100644
index 0000000..aae03051
--- /dev/null
+++ b/compiler/testData/diagnostics/tests/multiplatform/actualWithoutExpectWhenExpectIsFakeOverride.fir.kt
@@ -0,0 +1,33 @@
+// MODULE: m1-common
+// FILE: common.kt
+
+fun foo() {}
+class Foo
+
+open class Base {
+ open fun foo() {}
+}
+expect class Bar : Base {
+}
+
+expect open class ExpectBase {
+ open fun foo()
+}
+expect class Baz : ExpectBase
+
+// MODULE: m1-jvm()()(m1-common)
+// FILE: jvm.kt
+
+actual fun <!ACTUAL_WITHOUT_EXPECT!>foo<!>() {}
+actual class <!ACTUAL_WITHOUT_EXPECT!>Foo<!>
+
+actual class Bar : Base() {
+ actual override fun <!ACTUAL_WITHOUT_EXPECT!>foo<!>() {}
+}
+
+actual open class ExpectBase {
+ actual open fun foo() {}
+}
+actual class Baz : ExpectBase() {
+ actual override fun <!ACTUAL_WITHOUT_EXPECT!>foo<!>() {}
+}
diff --git a/compiler/testData/diagnostics/tests/multiplatform/actualWithoutExpectWhenExpectIsFakeOverride.kt b/compiler/testData/diagnostics/tests/multiplatform/actualWithoutExpectWhenExpectIsFakeOverride.kt
new file mode 100644
index 0000000..897148b
--- /dev/null
+++ b/compiler/testData/diagnostics/tests/multiplatform/actualWithoutExpectWhenExpectIsFakeOverride.kt
@@ -0,0 +1,33 @@
+// MODULE: m1-common
+// FILE: common.kt
+
+<!CONFLICTING_OVERLOADS{JVM}!>fun foo()<!> {}
+class <!PACKAGE_OR_CLASSIFIER_REDECLARATION{JVM}!>Foo<!>
+
+open class Base {
+ open fun foo() {}
+}
+expect class Bar : Base {
+}
+
+expect open class ExpectBase {
+ open fun foo()
+}
+expect class Baz : ExpectBase
+
+// MODULE: m1-jvm()()(m1-common)
+// FILE: jvm.kt
+
+<!CONFLICTING_OVERLOADS!>actual fun <!ACTUAL_WITHOUT_EXPECT!>foo<!>()<!> {}
+actual class <!ACTUAL_WITHOUT_EXPECT, PACKAGE_OR_CLASSIFIER_REDECLARATION!>Foo<!>
+
+actual class Bar : Base() {
+ actual override fun <!ACTUAL_WITHOUT_EXPECT!>foo<!>() {}
+}
+
+actual open class ExpectBase {
+ actual open fun foo() {}
+}
+actual class Baz : ExpectBase() {
+ actual override fun <!ACTUAL_WITHOUT_EXPECT!>foo<!>() {}
+}
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 9e4ccd0..426977c 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
@@ -24778,6 +24778,12 @@
}
@Test
+ @TestMetadata("actualWithoutExpectWhenExpectIsFakeOverride.kt")
+ public void testActualWithoutExpectWhenExpectIsFakeOverride() throws Exception {
+ runTest("compiler/testData/diagnostics/tests/multiplatform/actualWithoutExpectWhenExpectIsFakeOverride.kt");
+ }
+
+ @Test
public void testAllFilesPresentInMultiplatform() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/multiplatform"), Pattern.compile("^(.*)\\.kts?$"), Pattern.compile("^(.+)\\.(reversed|fir|ll)\\.kts?$"), true);
}