Don't issue a warning about expect/actual in the same module for incompatible expect/actual pairs
^KT-57067 Fixed Review: https://jetbrains.team/p/kt/reviews/9123
This commit is contained in:
+6
@@ -22062,6 +22062,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag
|
||||
runTest("compiler/testData/diagnostics/tests/multiplatform/hmpp/multiplatformCompositeAnalysis/expectAndActualInTheSameModule.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("expectAndActualInTheSameModuleIncompatibilities.kt")
|
||||
public void testExpectAndActualInTheSameModuleIncompatibilities() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/multiplatform/hmpp/multiplatformCompositeAnalysis/expectAndActualInTheSameModuleIncompatibilities.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("intermediateWithActualAndExpect.kt")
|
||||
public void testIntermediateWithActualAndExpect() throws Exception {
|
||||
|
||||
+6
@@ -22062,6 +22062,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir
|
||||
runTest("compiler/testData/diagnostics/tests/multiplatform/hmpp/multiplatformCompositeAnalysis/expectAndActualInTheSameModule.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("expectAndActualInTheSameModuleIncompatibilities.kt")
|
||||
public void testExpectAndActualInTheSameModuleIncompatibilities() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/multiplatform/hmpp/multiplatformCompositeAnalysis/expectAndActualInTheSameModuleIncompatibilities.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("intermediateWithActualAndExpect.kt")
|
||||
public void testIntermediateWithActualAndExpect() throws Exception {
|
||||
|
||||
+6
@@ -22068,6 +22068,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia
|
||||
runTest("compiler/testData/diagnostics/tests/multiplatform/hmpp/multiplatformCompositeAnalysis/expectAndActualInTheSameModule.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("expectAndActualInTheSameModuleIncompatibilities.kt")
|
||||
public void testExpectAndActualInTheSameModuleIncompatibilities() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/multiplatform/hmpp/multiplatformCompositeAnalysis/expectAndActualInTheSameModuleIncompatibilities.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("intermediateWithActualAndExpect.kt")
|
||||
public void testIntermediateWithActualAndExpect() throws Exception {
|
||||
|
||||
+4
-1
@@ -13,6 +13,7 @@ import org.jetbrains.kotlin.diagnostics.Errors
|
||||
import org.jetbrains.kotlin.platform.isCommon
|
||||
import org.jetbrains.kotlin.psi.KtDeclaration
|
||||
import org.jetbrains.kotlin.psi.KtNamedDeclaration
|
||||
import org.jetbrains.kotlin.resolve.checkers.ExpectedActualDeclarationChecker.Companion.isCompatibleOrWeakCompatible
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.module
|
||||
import org.jetbrains.kotlin.resolve.multiplatform.ExpectedActualResolver
|
||||
import org.jetbrains.kotlin.resolve.multiplatform.isCommonSource
|
||||
@@ -27,7 +28,9 @@ object ExpectActualInTheSameModuleChecker : DeclarationChecker {
|
||||
// Only look for top level actual members; class members will be handled as a part of that expected class
|
||||
if (descriptor.containingDeclaration !is PackageFragmentDescriptor) return
|
||||
val module = descriptor.module
|
||||
val actuals = ExpectedActualResolver.findActualForExpected(descriptor, module)?.flatMap { it.value }
|
||||
val actuals = ExpectedActualResolver.findActualForExpected(descriptor, module)
|
||||
?.filter { (compatibility, _) -> compatibility.isCompatibleOrWeakCompatible() }
|
||||
?.flatMap { (_, members) -> members }
|
||||
?.takeIf(List<MemberDescriptor>::isNotEmpty) ?: return
|
||||
|
||||
// There are 4 cases:
|
||||
|
||||
+4
-4
@@ -329,10 +329,6 @@ class ExpectedActualDeclarationChecker(
|
||||
}
|
||||
}
|
||||
|
||||
private fun ExpectActualCompatibility<MemberDescriptor>.isCompatibleOrWeakCompatible() =
|
||||
this is Compatible ||
|
||||
this is Incompatible && kind == IncompatibilityKind.WEAK
|
||||
|
||||
// we don't require `actual` modifier on
|
||||
// - annotation constructors, because annotation classes can only have one constructor
|
||||
// - inline class primary constructors, because inline class must have primary constructor
|
||||
@@ -399,6 +395,10 @@ class ExpectedActualDeclarationChecker(
|
||||
companion object {
|
||||
fun Map<out ExpectActualCompatibility<MemberDescriptor>, Collection<MemberDescriptor>>.allStrongIncompatibilities(): Boolean =
|
||||
this.keys.all { it is Incompatible && it.kind == IncompatibilityKind.STRONG }
|
||||
|
||||
internal fun ExpectActualCompatibility<MemberDescriptor>.isCompatibleOrWeakCompatible() =
|
||||
this is Compatible ||
|
||||
this is Incompatible && kind == IncompatibilityKind.WEAK
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
// MODULE: common
|
||||
// TARGET_PLATFORM: Common
|
||||
|
||||
expect fun parameterCount()
|
||||
fun parameterCount(p: String) {}
|
||||
|
||||
expect fun parameterCount2()
|
||||
<!ACTUAL_WITHOUT_EXPECT!>actual fun parameterCount2(p: String) {}<!>
|
||||
|
||||
expect fun callableKind(): Int
|
||||
val callableKind: Int = 1
|
||||
|
||||
expect fun <T> typeParameterCount()
|
||||
fun typeParameterCount() {}
|
||||
|
||||
expect enum class EnumEntries {
|
||||
ONE, TWO;
|
||||
}
|
||||
<!ACTUAL_WITHOUT_EXPECT!>actual enum class EnumEntries {
|
||||
ONE;
|
||||
}<!>
|
||||
|
||||
expect fun vararg(bar: Int)
|
||||
fun vararg(vararg bar: Int) = Unit
|
||||
|
||||
// MODULE: main()()(common)
|
||||
|
||||
actual fun parameterCount() {}
|
||||
actual fun <T> typeParameterCount() {}
|
||||
actual fun callableKind(): Int = 1
|
||||
actual fun vararg(bar: Int) = Unit
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
// MODULE: common
|
||||
// TARGET_PLATFORM: Common
|
||||
|
||||
expect fun parameterCount()
|
||||
fun parameterCount(p: String) {}
|
||||
|
||||
expect fun parameterCount2()
|
||||
actual fun parameterCount2(p: String) {}
|
||||
|
||||
expect fun callableKind(): Int
|
||||
val callableKind: Int = 1
|
||||
|
||||
expect fun <T> typeParameterCount()
|
||||
fun typeParameterCount() {}
|
||||
|
||||
expect <!EXPECT_AND_ACTUAL_IN_THE_SAME_MODULE!>enum class EnumEntries<!> {
|
||||
ONE, TWO;
|
||||
}
|
||||
actual <!EXPECT_AND_ACTUAL_IN_THE_SAME_MODULE!>enum class EnumEntries<!> {
|
||||
ONE;
|
||||
}
|
||||
|
||||
expect fun vararg(bar: Int)
|
||||
fun vararg(vararg bar: Int) = Unit
|
||||
|
||||
// MODULE: main()()(common)
|
||||
|
||||
actual fun parameterCount() {}
|
||||
actual fun <T> typeParameterCount() {}
|
||||
actual fun callableKind(): Int = 1
|
||||
actual fun vararg(bar: Int) = Unit
|
||||
Generated
+6
@@ -22068,6 +22068,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
||||
runTest("compiler/testData/diagnostics/tests/multiplatform/hmpp/multiplatformCompositeAnalysis/expectAndActualInTheSameModule.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("expectAndActualInTheSameModuleIncompatibilities.kt")
|
||||
public void testExpectAndActualInTheSameModuleIncompatibilities() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/multiplatform/hmpp/multiplatformCompositeAnalysis/expectAndActualInTheSameModuleIncompatibilities.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("intermediateWithActualAndExpect.kt")
|
||||
public void testIntermediateWithActualAndExpect() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user