Remove extra copyOf calls during filtering in collectRealOverrides (#3916)
This commit is contained in:
@@ -30,14 +30,17 @@ val IrFunction.target: IrFunction get() = when (this) {
|
||||
else -> error(this)
|
||||
}
|
||||
|
||||
fun IrSimpleFunction.collectRealOverrides(toSkip: (IrSimpleFunction) -> Boolean = { false }): Set<IrSimpleFunction> {
|
||||
fun IrSimpleFunction.collectRealOverrides(
|
||||
toSkip: (IrSimpleFunction) -> Boolean = { false },
|
||||
filter: (IrOverridableMember) -> Boolean = { false }
|
||||
): Set<IrSimpleFunction> {
|
||||
if (isReal && !toSkip(this)) return setOf(this)
|
||||
|
||||
return this.overriddenSymbols
|
||||
.map { it.owner }
|
||||
.collectAndFilterRealOverrides {
|
||||
require(it is IrSimpleFunction) { "Expected IrSimpleFunction: ${it.render()}" }
|
||||
toSkip(it)
|
||||
toSkip(it) || filter(it)
|
||||
}
|
||||
.map { it as IrSimpleFunction }
|
||||
.toSet()
|
||||
@@ -85,13 +88,12 @@ fun Collection<IrOverridableMember>.collectAndFilterRealOverrides(toSkip: (IrOve
|
||||
|
||||
// TODO: use this implementation instead of any other
|
||||
fun IrSimpleFunction.resolveFakeOverride(allowAbstract: Boolean = false, toSkip: (IrSimpleFunction) -> Boolean = { false }): IrSimpleFunction? {
|
||||
val reals = collectRealOverrides(toSkip)
|
||||
return if (allowAbstract) {
|
||||
val reals = collectRealOverrides(toSkip)
|
||||
if (reals.isEmpty()) error("No real overrides for ${this.render()}")
|
||||
reals.first()
|
||||
} else {
|
||||
reals
|
||||
.filter { it.modality != Modality.ABSTRACT }
|
||||
collectRealOverrides(toSkip, { it.modality == Modality.ABSTRACT })
|
||||
.let { realOverrides ->
|
||||
// Kotlin forbids conflicts between overrides, but they may trickle down from Java.
|
||||
realOverrides.singleOrNull { it.parent.safeAs<IrClass>()?.isInterface != true }
|
||||
|
||||
Reference in New Issue
Block a user