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");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("expectInterfaceInheritance.kt")
|
||||
public void testExpectInterfaceInheritance() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/multiplatform/multiModule/expectInterfaceInheritance.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("fakeOverridesInPlatformModule.kt")
|
||||
public void testFakeOverridesInPlatformModule() throws Exception {
|
||||
|
||||
+6
@@ -33148,6 +33148,12 @@ public class FirPsiBlackBoxCodegenTestGenerated extends AbstractFirPsiBlackBoxCo
|
||||
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
|
||||
@TestMetadata("fakeOverridesInPlatformModule.kt")
|
||||
public void testFakeOverridesInPlatformModule() throws Exception {
|
||||
|
||||
+40
-17
@@ -43,25 +43,48 @@ class MissingFakeOverridesAdder(
|
||||
}
|
||||
|
||||
for (superType in declaration.superTypes) {
|
||||
val actualClass = expectActualMap[superType.classifierOrFail]?.owner as? IrClass ?: continue
|
||||
for (actualMember in actualClass.declarations) {
|
||||
if (actualMember.isBuiltinMember()) continue
|
||||
when (actualMember) {
|
||||
is IrFunctionImpl,
|
||||
is IrPropertyImpl -> {
|
||||
if (members[generateIrElementFullName(actualMember, expectActualMap, typeAliasMap)] != null) {
|
||||
reportManyInterfacesMembersNotImplemented(declaration, actualMember as IrDeclarationWithName)
|
||||
continue
|
||||
}
|
||||
val expectClass = superType.classifierOrFail.owner as? IrClass ?: continue
|
||||
val added = mutableSetOf<IrDeclaration>()
|
||||
for (expectMember in expectClass.declarations) {
|
||||
if (expectMember.isBuiltinMember()) continue
|
||||
val actualMember = expectActualMap[expectMember.symbol]?.owner as? IrDeclaration ?: continue
|
||||
|
||||
val newMember = if (actualMember is IrFunctionImpl) {
|
||||
createFakeOverrideFunction(actualMember, declaration)
|
||||
} else {
|
||||
createFakeOverrideProperty(actualMember as IrPropertyImpl, declaration)
|
||||
}
|
||||
declaration.declarations.add(newMember)
|
||||
}
|
||||
// Do not add FAKE_OVERRIDE if the subclass already has overridden member
|
||||
if (declaration.declarations.filterIsInstance<IrOverridableDeclaration<*>>()
|
||||
.any { expectMember.symbol in it.overriddenSymbols }
|
||||
) {
|
||||
continue
|
||||
}
|
||||
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");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("expectInterfaceInheritance.kt")
|
||||
public void testExpectInterfaceInheritance() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/multiplatform/multiModule/expectInterfaceInheritance.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("fakeOverridesInPlatformModule.kt")
|
||||
public void testFakeOverridesInPlatformModule() throws Exception {
|
||||
|
||||
+6
@@ -33148,6 +33148,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
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
|
||||
@TestMetadata("fakeOverridesInPlatformModule.kt")
|
||||
public void testFakeOverridesInPlatformModule() throws Exception {
|
||||
|
||||
+5
@@ -27089,6 +27089,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
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")
|
||||
public void testFakeOverridesInPlatformModule() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/multiplatform/multiModule/fakeOverridesInPlatformModule.kt");
|
||||
|
||||
Reference in New Issue
Block a user