FIR2IR: Do not add fake override if the member is overridden
#KT-56398 Fixed
This commit is contained in:
+6
@@ -33148,6 +33148,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
|||||||
runTest("compiler/testData/codegen/box/multiplatform/multiModule/expectInterfaceInSupertypes.kt");
|
runTest("compiler/testData/codegen/box/multiplatform/multiModule/expectInterfaceInSupertypes.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("expectInterfaceInheritance.kt")
|
||||||
|
public void testExpectInterfaceInheritance() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/multiplatform/multiModule/expectInterfaceInheritance.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("fakeOverridesInPlatformModule.kt")
|
@TestMetadata("fakeOverridesInPlatformModule.kt")
|
||||||
public void testFakeOverridesInPlatformModule() throws Exception {
|
public void testFakeOverridesInPlatformModule() throws Exception {
|
||||||
|
|||||||
+6
@@ -33148,6 +33148,12 @@ public class FirPsiBlackBoxCodegenTestGenerated extends AbstractFirPsiBlackBoxCo
|
|||||||
runTest("compiler/testData/codegen/box/multiplatform/multiModule/expectInterfaceInSupertypes.kt");
|
runTest("compiler/testData/codegen/box/multiplatform/multiModule/expectInterfaceInSupertypes.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("expectInterfaceInheritance.kt")
|
||||||
|
public void testExpectInterfaceInheritance() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/multiplatform/multiModule/expectInterfaceInheritance.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("fakeOverridesInPlatformModule.kt")
|
@TestMetadata("fakeOverridesInPlatformModule.kt")
|
||||||
public void testFakeOverridesInPlatformModule() throws Exception {
|
public void testFakeOverridesInPlatformModule() throws Exception {
|
||||||
|
|||||||
+40
-17
@@ -43,25 +43,48 @@ class MissingFakeOverridesAdder(
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (superType in declaration.superTypes) {
|
for (superType in declaration.superTypes) {
|
||||||
val actualClass = expectActualMap[superType.classifierOrFail]?.owner as? IrClass ?: continue
|
val expectClass = superType.classifierOrFail.owner as? IrClass ?: continue
|
||||||
for (actualMember in actualClass.declarations) {
|
val added = mutableSetOf<IrDeclaration>()
|
||||||
if (actualMember.isBuiltinMember()) continue
|
for (expectMember in expectClass.declarations) {
|
||||||
when (actualMember) {
|
if (expectMember.isBuiltinMember()) continue
|
||||||
is IrFunctionImpl,
|
val actualMember = expectActualMap[expectMember.symbol]?.owner as? IrDeclaration ?: continue
|
||||||
is IrPropertyImpl -> {
|
|
||||||
if (members[generateIrElementFullName(actualMember, expectActualMap, typeAliasMap)] != null) {
|
|
||||||
reportManyInterfacesMembersNotImplemented(declaration, actualMember as IrDeclarationWithName)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
val newMember = if (actualMember is IrFunctionImpl) {
|
// Do not add FAKE_OVERRIDE if the subclass already has overridden member
|
||||||
createFakeOverrideFunction(actualMember, declaration)
|
if (declaration.declarations.filterIsInstance<IrOverridableDeclaration<*>>()
|
||||||
} else {
|
.any { expectMember.symbol in it.overriddenSymbols }
|
||||||
createFakeOverrideProperty(actualMember as IrPropertyImpl, declaration)
|
) {
|
||||||
}
|
continue
|
||||||
declaration.declarations.add(newMember)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
addFakeOverride(actualMember, members, declaration)
|
||||||
|
added += actualMember
|
||||||
|
}
|
||||||
|
val actualClass = expectActualMap[expectClass.symbol]?.owner as? IrClass ?: continue
|
||||||
|
for (actualMember in actualClass.declarations) {
|
||||||
|
if (actualMember.isBuiltinMember() || actualMember in added) continue
|
||||||
|
addFakeOverride(actualMember, members, declaration)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun addFakeOverride(
|
||||||
|
actualMember: IrDeclaration,
|
||||||
|
members: Map<String, IrDeclaration>,
|
||||||
|
declaration: IrClass
|
||||||
|
) {
|
||||||
|
when (actualMember) {
|
||||||
|
is IrFunctionImpl,
|
||||||
|
is IrPropertyImpl -> {
|
||||||
|
if (members[generateIrElementFullName(actualMember, expectActualMap, typeAliasMap)] != null) {
|
||||||
|
reportManyInterfacesMembersNotImplemented(declaration, actualMember as IrDeclarationWithName)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
val newMember = if (actualMember is IrFunctionImpl) {
|
||||||
|
createFakeOverrideFunction(actualMember, declaration)
|
||||||
|
} else {
|
||||||
|
createFakeOverrideProperty(actualMember as IrPropertyImpl, declaration)
|
||||||
|
}
|
||||||
|
declaration.declarations.add(newMember)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+25
@@ -0,0 +1,25 @@
|
|||||||
|
// ISSUE: KT-56398
|
||||||
|
// TARGET_BACKEND: JVM
|
||||||
|
// !LANGUAGE: +MultiPlatformProjects
|
||||||
|
|
||||||
|
// MODULE: common
|
||||||
|
// TARGET_PLATFORM: Common
|
||||||
|
// FILE: common.kt
|
||||||
|
|
||||||
|
expect interface Interface {
|
||||||
|
fun foo(): String
|
||||||
|
}
|
||||||
|
|
||||||
|
class Klass : Interface {
|
||||||
|
override fun foo() = "OK"
|
||||||
|
}
|
||||||
|
|
||||||
|
// MODULE: jvm()()(common)
|
||||||
|
// TARGET_PLATFORM: JVM
|
||||||
|
// FILE: main.kt
|
||||||
|
|
||||||
|
actual interface Interface {
|
||||||
|
actual fun foo(): String
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box() = Klass().foo()
|
||||||
+6
@@ -31822,6 +31822,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
|||||||
runTest("compiler/testData/codegen/box/multiplatform/multiModule/expectInterfaceInSupertypes.kt");
|
runTest("compiler/testData/codegen/box/multiplatform/multiModule/expectInterfaceInSupertypes.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("expectInterfaceInheritance.kt")
|
||||||
|
public void testExpectInterfaceInheritance() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/multiplatform/multiModule/expectInterfaceInheritance.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("fakeOverridesInPlatformModule.kt")
|
@TestMetadata("fakeOverridesInPlatformModule.kt")
|
||||||
public void testFakeOverridesInPlatformModule() throws Exception {
|
public void testFakeOverridesInPlatformModule() throws Exception {
|
||||||
|
|||||||
+6
@@ -33148,6 +33148,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
|||||||
runTest("compiler/testData/codegen/box/multiplatform/multiModule/expectInterfaceInSupertypes.kt");
|
runTest("compiler/testData/codegen/box/multiplatform/multiModule/expectInterfaceInSupertypes.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("expectInterfaceInheritance.kt")
|
||||||
|
public void testExpectInterfaceInheritance() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/multiplatform/multiModule/expectInterfaceInheritance.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("fakeOverridesInPlatformModule.kt")
|
@TestMetadata("fakeOverridesInPlatformModule.kt")
|
||||||
public void testFakeOverridesInPlatformModule() throws Exception {
|
public void testFakeOverridesInPlatformModule() throws Exception {
|
||||||
|
|||||||
+5
@@ -27089,6 +27089,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
|||||||
runTest("compiler/testData/codegen/box/multiplatform/multiModule/expectInterfaceInSupertypes.kt");
|
runTest("compiler/testData/codegen/box/multiplatform/multiModule/expectInterfaceInSupertypes.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("expectInterfaceInheritance.kt")
|
||||||
|
public void testExpectInterfaceInheritance() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/multiplatform/multiModule/expectInterfaceInheritance.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("fakeOverridesInPlatformModule.kt")
|
@TestMetadata("fakeOverridesInPlatformModule.kt")
|
||||||
public void testFakeOverridesInPlatformModule() throws Exception {
|
public void testFakeOverridesInPlatformModule() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/multiplatform/multiModule/fakeOverridesInPlatformModule.kt");
|
runTest("compiler/testData/codegen/box/multiplatform/multiModule/fakeOverridesInPlatformModule.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user