[FIR] Skip expect-actual rules check when overriding non-expect member

Overriding equals, hashCode, toString and any other member that is not
expect does not require satisfying the rules of expect-actual matching.

#KT-57381 Fixed
This commit is contained in:
Kirill Rakhman
2023-03-28 14:47:38 +02:00
committed by Space Team
parent ef51cf9083
commit 32cc28c6cf
15 changed files with 106 additions and 0 deletions
@@ -33399,6 +33399,12 @@ public class FirLightTreeBlackBoxCodegenTestGenerated extends AbstractFirLightTr
runTest("compiler/testData/codegen/box/multiplatform/k2/basic/noArgActualConstructor.kt");
}
@Test
@TestMetadata("nonExternalEquals.kt")
public void testNonExternalEquals() throws Exception {
runTest("compiler/testData/codegen/box/multiplatform/k2/basic/nonExternalEquals.kt");
}
@Test
@TestMetadata("removeExpectDeclarationsFromMetadata.kt")
public void testRemoveExpectDeclarationsFromMetadata() throws Exception {
@@ -33399,6 +33399,12 @@ public class FirPsiBlackBoxCodegenTestGenerated extends AbstractFirPsiBlackBoxCo
runTest("compiler/testData/codegen/box/multiplatform/k2/basic/noArgActualConstructor.kt");
}
@Test
@TestMetadata("nonExternalEquals.kt")
public void testNonExternalEquals() throws Exception {
runTest("compiler/testData/codegen/box/multiplatform/k2/basic/nonExternalEquals.kt");
}
@Test
@TestMetadata("removeExpectDeclarationsFromMetadata.kt")
public void testRemoveExpectDeclarationsFromMetadata() throws Exception {
@@ -186,6 +186,9 @@ object FirExpectActualResolver {
outer@ for (expectMember in expectClassSymbol.getMembers(scopeSession)) {
// if (expectMember is CallableMemberDescriptor && !expectMember.kind.isReal) continue
// Skip non-expect declarations like equals, hashCode, toString and any inherited declarations from non-expect super types.
if (expectMember is FirCallableSymbol && !expectMember.isExpect) continue
val actualMembers = when (expectMember) {
is FirConstructorSymbol -> actualConstructors
else -> actualMembersByName[expectMember.name]?.filter { actualMember ->
@@ -0,0 +1,27 @@
// !LANGUAGE: +MultiPlatformProjects
// IGNORE_BACKEND_K1: ANY
// IGNORE_BACKEND: WASM
// MODULE: common
// FILE: common.kt
open class Base {
open operator fun plus(b: Base) = Base()
}
expect open class Derived constructor() : Base() {
}
// MODULE: main()()(common)
// FILE: main.kt
actual open class Derived : Base() {
// Any.equals is is external on Native but because it's not expect, it's ok to override without external
override fun equals(other: Any?): Boolean = other === this
override fun hashCode() = 1
override fun toString() = "Derived"
// no operator modifier is legal because Base.plus is not expect
override fun plus(b: Base) = Derived()
}
fun box() = "OK"
@@ -32013,6 +32013,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTest("compiler/testData/codegen/box/multiplatform/k2/basic/noArgActualConstructor.kt");
}
@Test
@TestMetadata("nonExternalEquals.kt")
public void testNonExternalEquals() throws Exception {
runTest("compiler/testData/codegen/box/multiplatform/k2/basic/nonExternalEquals.kt");
}
@Test
@TestMetadata("removeExpectDeclarationsFromMetadata.kt")
public void testRemoveExpectDeclarationsFromMetadata() throws Exception {
@@ -33399,6 +33399,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTest("compiler/testData/codegen/box/multiplatform/k2/basic/noArgActualConstructor.kt");
}
@Test
@TestMetadata("nonExternalEquals.kt")
public void testNonExternalEquals() throws Exception {
runTest("compiler/testData/codegen/box/multiplatform/k2/basic/nonExternalEquals.kt");
}
@Test
@TestMetadata("removeExpectDeclarationsFromMetadata.kt")
public void testRemoveExpectDeclarationsFromMetadata() throws Exception {
@@ -33399,6 +33399,12 @@ public class IrBlackBoxCodegenWithIrInlinerTestGenerated extends AbstractIrBlack
runTest("compiler/testData/codegen/box/multiplatform/k2/basic/noArgActualConstructor.kt");
}
@Test
@TestMetadata("nonExternalEquals.kt")
public void testNonExternalEquals() throws Exception {
runTest("compiler/testData/codegen/box/multiplatform/k2/basic/nonExternalEquals.kt");
}
@Test
@TestMetadata("removeExpectDeclarationsFromMetadata.kt")
public void testRemoveExpectDeclarationsFromMetadata() throws Exception {
@@ -27266,6 +27266,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
public void testKt_56329() throws Exception {
runTest("compiler/testData/codegen/box/multiplatform/k2/basic/kt-56329.kt");
}
@TestMetadata("nonExternalEquals.kt")
public void testNonExternalEquals() throws Exception {
runTest("compiler/testData/codegen/box/multiplatform/k2/basic/nonExternalEquals.kt");
}
}
@TestMetadata("compiler/testData/codegen/box/multiplatform/k2/defaultArguments")
@@ -23207,6 +23207,12 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/multiplatform/k2/basic/kt-56329.kt");
}
@Test
@TestMetadata("nonExternalEquals.kt")
public void testNonExternalEquals() throws Exception {
runTest("compiler/testData/codegen/box/multiplatform/k2/basic/nonExternalEquals.kt");
}
@Test
@TestMetadata("removeExpectDeclarationsFromMetadata.kt")
public void testRemoveExpectDeclarationsFromMetadata() throws Exception {
@@ -23321,6 +23321,12 @@ public class FirJsCodegenBoxTestGenerated extends AbstractFirJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/multiplatform/k2/basic/kt-56329.kt");
}
@Test
@TestMetadata("nonExternalEquals.kt")
public void testNonExternalEquals() throws Exception {
runTest("compiler/testData/codegen/box/multiplatform/k2/basic/nonExternalEquals.kt");
}
@Test
@TestMetadata("removeExpectDeclarationsFromMetadata.kt")
public void testRemoveExpectDeclarationsFromMetadata() throws Exception {
@@ -23321,6 +23321,12 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/multiplatform/k2/basic/kt-56329.kt");
}
@Test
@TestMetadata("nonExternalEquals.kt")
public void testNonExternalEquals() throws Exception {
runTest("compiler/testData/codegen/box/multiplatform/k2/basic/nonExternalEquals.kt");
}
@Test
@TestMetadata("removeExpectDeclarationsFromMetadata.kt")
public void testRemoveExpectDeclarationsFromMetadata() throws Exception {
@@ -23321,6 +23321,12 @@ public class IrJsES6CodegenBoxTestGenerated extends AbstractIrJsES6CodegenBoxTes
runTest("compiler/testData/codegen/box/multiplatform/k2/basic/kt-56329.kt");
}
@Test
@TestMetadata("nonExternalEquals.kt")
public void testNonExternalEquals() throws Exception {
runTest("compiler/testData/codegen/box/multiplatform/k2/basic/nonExternalEquals.kt");
}
@Test
@TestMetadata("removeExpectDeclarationsFromMetadata.kt")
public void testRemoveExpectDeclarationsFromMetadata() throws Exception {
@@ -26747,6 +26747,12 @@ public class FirNativeCodegenBoxTestGenerated extends AbstractNativeCodegenBoxTe
runTest("compiler/testData/codegen/box/multiplatform/k2/basic/kt-56329.kt");
}
@Test
@TestMetadata("nonExternalEquals.kt")
public void testNonExternalEquals() throws Exception {
runTest("compiler/testData/codegen/box/multiplatform/k2/basic/nonExternalEquals.kt");
}
@Test
@TestMetadata("removeExpectDeclarationsFromMetadata.kt")
public void testRemoveExpectDeclarationsFromMetadata() throws Exception {
@@ -26444,6 +26444,12 @@ public class K1NativeCodegenBoxTestGenerated extends AbstractNativeCodegenBoxTes
runTest("compiler/testData/codegen/box/multiplatform/k2/basic/kt-56329.kt");
}
@Test
@TestMetadata("nonExternalEquals.kt")
public void testNonExternalEquals() throws Exception {
runTest("compiler/testData/codegen/box/multiplatform/k2/basic/nonExternalEquals.kt");
}
@Test
@TestMetadata("removeExpectDeclarationsFromMetadata.kt")
public void testRemoveExpectDeclarationsFromMetadata() throws Exception {
@@ -20785,6 +20785,11 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest
runTest("compiler/testData/codegen/box/multiplatform/k2/basic/kt-56329.kt");
}
@TestMetadata("nonExternalEquals.kt")
public void testNonExternalEquals() throws Exception {
runTest("compiler/testData/codegen/box/multiplatform/k2/basic/nonExternalEquals.kt");
}
@TestMetadata("removeExpectDeclarationsFromMetadata.kt")
public void testRemoveExpectDeclarationsFromMetadata() throws Exception {
runTest("compiler/testData/codegen/box/multiplatform/k2/basic/removeExpectDeclarationsFromMetadata.kt");