[JS IR] Do not copy interface method if base class inherits it

^KT-58599 Fixed
This commit is contained in:
Alexander Korepanov
2023-05-30 08:22:43 +00:00
committed by Space Team
parent 9ca9fc9c68
commit 8066f1b7d2
54 changed files with 886 additions and 8 deletions
@@ -166,7 +166,9 @@ abstract class UsefulDeclarationProcessor(
protected open fun processSimpleFunction(irFunction: IrSimpleFunction) {
if (irFunction.isFakeOverride) {
irFunction.resolveFakeOverride()?.enqueue(irFunction, "real overridden fun", isContagious = false)
irFunction.overriddenSymbols.forEach {
it.owner.enqueue(irFunction, "overridden by a useful fake override", isContagious = false)
}
}
}
@@ -257,7 +257,14 @@ class JsClassGenerator(private val irClass: IrClass, val context: JsGenerationCo
}
private fun IrClass.shouldCopyFrom(): Boolean {
return isInterface && !isEffectivelyExternal()
if (!isInterface || isEffectivelyExternal()) {
return false
}
// Do not copy an interface method if the interface is already a parent of the base class,
// as the method will already be copied from the interface into the base class
val superIrClass = baseClass?.classOrNull?.owner ?: return true
return !superIrClass.isSubclassOf(this)
}
private fun generateMemberFunction(declaration: IrSimpleFunction): Pair<JsName, JsFunction?> {
@@ -477,4 +484,4 @@ class JsIrClassModel(val klass: IrClass) {
class JsIrIcClassModel(val superClasses: List<JsName>) {
val preDeclarationBlock = JsCompositeBlock()
val postDeclarationBlock = JsCompositeBlock()
}
}