A proper modality calculation was missing in IR fake override construction algorithm
#KT-41765 Fixed
This commit is contained in:
Generated
+5
@@ -15345,6 +15345,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
|||||||
runTest("compiler/testData/codegen/box/ir/kt40083.kt");
|
runTest("compiler/testData/codegen/box/ir/kt40083.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt41765.kt")
|
||||||
|
public void testKt41765() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/ir/kt41765.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("objectClass.kt")
|
@TestMetadata("objectClass.kt")
|
||||||
public void testObjectClass() throws Exception {
|
public void testObjectClass() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/ir/objectClass.kt");
|
runTest("compiler/testData/codegen/box/ir/objectClass.kt");
|
||||||
|
|||||||
@@ -6,17 +6,14 @@
|
|||||||
package org.jetbrains.kotlin.ir.overrides
|
package org.jetbrains.kotlin.ir.overrides
|
||||||
|
|
||||||
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
|
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.Modality
|
|
||||||
import org.jetbrains.kotlin.descriptors.DescriptorVisibilities
|
import org.jetbrains.kotlin.descriptors.DescriptorVisibilities
|
||||||
import org.jetbrains.kotlin.descriptors.DescriptorVisibility
|
import org.jetbrains.kotlin.descriptors.DescriptorVisibility
|
||||||
|
import org.jetbrains.kotlin.descriptors.Modality
|
||||||
import org.jetbrains.kotlin.ir.declarations.*
|
import org.jetbrains.kotlin.ir.declarations.*
|
||||||
import org.jetbrains.kotlin.ir.descriptors.IrBuiltIns
|
import org.jetbrains.kotlin.ir.descriptors.IrBuiltIns
|
||||||
import org.jetbrains.kotlin.ir.descriptors.WrappedPropertyDescriptor
|
|
||||||
import org.jetbrains.kotlin.ir.descriptors.WrappedSimpleFunctionDescriptor
|
|
||||||
import org.jetbrains.kotlin.ir.symbols.*
|
import org.jetbrains.kotlin.ir.symbols.*
|
||||||
import org.jetbrains.kotlin.ir.symbols.impl.IrPropertySymbolImpl
|
|
||||||
import org.jetbrains.kotlin.ir.symbols.impl.IrSimpleFunctionSymbolImpl
|
|
||||||
import org.jetbrains.kotlin.ir.types.*
|
import org.jetbrains.kotlin.ir.types.*
|
||||||
|
import org.jetbrains.kotlin.ir.util.collectAndFilterRealOverrides
|
||||||
import org.jetbrains.kotlin.ir.util.isReal
|
import org.jetbrains.kotlin.ir.util.isReal
|
||||||
import org.jetbrains.kotlin.ir.util.render
|
import org.jetbrains.kotlin.ir.util.render
|
||||||
import org.jetbrains.kotlin.resolve.OverridingUtil.OverrideCompatibilityInfo
|
import org.jetbrains.kotlin.resolve.OverridingUtil.OverrideCompatibilityInfo
|
||||||
@@ -284,7 +281,11 @@ class IrOverridingUtil(
|
|||||||
if (!hasOpen && hasAbstract) {
|
if (!hasOpen && hasAbstract) {
|
||||||
return if (transformAbstractToClassModality) current.modality else Modality.ABSTRACT
|
return if (transformAbstractToClassModality) current.modality else Modality.ABSTRACT
|
||||||
}
|
}
|
||||||
return getMinimalModality(members, transformAbstractToClassModality, current.modality)
|
|
||||||
|
val realOverrides = members
|
||||||
|
.map{ originals[it]!! }
|
||||||
|
.collectAndFilterRealOverrides()
|
||||||
|
return getMinimalModality(realOverrides, transformAbstractToClassModality, current.modality)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun areEquivalent(a: IrOverridableMember, b: IrOverridableMember) = (a == b)
|
private fun areEquivalent(a: IrOverridableMember, b: IrOverridableMember) = (a == b)
|
||||||
|
|||||||
@@ -33,27 +33,47 @@ val IrFunction.target: IrFunction get() = when (this) {
|
|||||||
fun IrSimpleFunction.collectRealOverrides(toSkip: (IrSimpleFunction) -> Boolean = { false }): Set<IrSimpleFunction> {
|
fun IrSimpleFunction.collectRealOverrides(toSkip: (IrSimpleFunction) -> Boolean = { false }): Set<IrSimpleFunction> {
|
||||||
if (isReal && !toSkip(this)) return setOf(this)
|
if (isReal && !toSkip(this)) return setOf(this)
|
||||||
|
|
||||||
val visited = mutableSetOf<IrSimpleFunction>()
|
return this.overriddenSymbols
|
||||||
val realOverrides = mutableSetOf<IrSimpleFunction>()
|
.map { it.owner }
|
||||||
|
.collectAndFilterRealOverrides {
|
||||||
|
require(it is IrSimpleFunction) { "Expected IrSimpleFunction: ${it.render()}" }
|
||||||
|
toSkip(it)
|
||||||
|
}
|
||||||
|
.map { it as IrSimpleFunction }
|
||||||
|
.toSet()
|
||||||
|
}
|
||||||
|
|
||||||
fun collectRealOverrides(func: IrSimpleFunction) {
|
fun Collection<IrOverridableMember>.collectAndFilterRealOverrides(toSkip: (IrOverridableMember) -> Boolean = { false }): Set<IrOverridableMember> {
|
||||||
if (!visited.add(func)) return
|
|
||||||
|
|
||||||
if (func.isReal && !toSkip(func)) {
|
val visited = mutableSetOf<IrOverridableMember>()
|
||||||
realOverrides += func
|
val realOverrides = mutableSetOf<IrOverridableMember>()
|
||||||
|
|
||||||
|
fun overriddenSymbols(declaration: IrOverridableMember) = when (declaration) {
|
||||||
|
is IrSimpleFunction -> declaration.overriddenSymbols
|
||||||
|
is IrProperty -> (declaration.getter ?: declaration.setter)
|
||||||
|
?.overriddenSymbols?.mapNotNull { it.owner.correspondingPropertySymbol }
|
||||||
|
?: emptyList()
|
||||||
|
else -> error("Unexpected overridable member: ${declaration.render()}")
|
||||||
|
}
|
||||||
|
|
||||||
|
fun collectRealOverrides(member: IrOverridableMember) {
|
||||||
|
if (!visited.add(member)) return
|
||||||
|
|
||||||
|
if (member.isReal && !toSkip(member)) {
|
||||||
|
realOverrides += member
|
||||||
} else {
|
} else {
|
||||||
func.overriddenSymbols.forEach { collectRealOverrides(it.owner) }
|
overriddenSymbols(member).forEach { collectRealOverrides(it.owner as IrOverridableMember) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
overriddenSymbols.forEach { collectRealOverrides(it.owner) }
|
this.forEach { collectRealOverrides(it) }
|
||||||
|
|
||||||
fun excludeRepeated(func: IrSimpleFunction) {
|
fun excludeRepeated(member: IrOverridableMember) {
|
||||||
if (!visited.add(func)) return
|
if (!visited.add(member)) return
|
||||||
|
|
||||||
func.overriddenSymbols.forEach {
|
overriddenSymbols(member).forEach {
|
||||||
realOverrides.remove(it.owner)
|
realOverrides.remove(it.owner)
|
||||||
excludeRepeated(it.owner)
|
excludeRepeated(it.owner as IrOverridableMember)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+25
@@ -0,0 +1,25 @@
|
|||||||
|
// MODULE: lib
|
||||||
|
// FILE: lib.kt
|
||||||
|
|
||||||
|
// KT-41765
|
||||||
|
|
||||||
|
interface X {
|
||||||
|
override fun toString() :String
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Y
|
||||||
|
|
||||||
|
abstract class A: Y, X
|
||||||
|
|
||||||
|
// MODULE: main(lib)
|
||||||
|
// FILE: main.kt
|
||||||
|
|
||||||
|
class B: A() {
|
||||||
|
override fun toString() = "BBB"
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
if (B().toString() == "BBB") return "OK"
|
||||||
|
return "FAIL"
|
||||||
|
}
|
||||||
|
|
||||||
+5
@@ -16740,6 +16740,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
|||||||
runTest("compiler/testData/codegen/box/ir/kt40083.kt");
|
runTest("compiler/testData/codegen/box/ir/kt40083.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt41765.kt")
|
||||||
|
public void testKt41765() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/ir/kt41765.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("objectClass.kt")
|
@TestMetadata("objectClass.kt")
|
||||||
public void testObjectClass() throws Exception {
|
public void testObjectClass() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/ir/objectClass.kt");
|
runTest("compiler/testData/codegen/box/ir/objectClass.kt");
|
||||||
|
|||||||
+5
@@ -16740,6 +16740,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
|||||||
runTest("compiler/testData/codegen/box/ir/kt40083.kt");
|
runTest("compiler/testData/codegen/box/ir/kt40083.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt41765.kt")
|
||||||
|
public void testKt41765() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/ir/kt41765.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("objectClass.kt")
|
@TestMetadata("objectClass.kt")
|
||||||
public void testObjectClass() throws Exception {
|
public void testObjectClass() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/ir/objectClass.kt");
|
runTest("compiler/testData/codegen/box/ir/objectClass.kt");
|
||||||
|
|||||||
+5
@@ -15345,6 +15345,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
|||||||
runTest("compiler/testData/codegen/box/ir/kt40083.kt");
|
runTest("compiler/testData/codegen/box/ir/kt40083.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt41765.kt")
|
||||||
|
public void testKt41765() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/ir/kt41765.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("objectClass.kt")
|
@TestMetadata("objectClass.kt")
|
||||||
public void testObjectClass() throws Exception {
|
public void testObjectClass() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/ir/objectClass.kt");
|
runTest("compiler/testData/codegen/box/ir/objectClass.kt");
|
||||||
|
|||||||
Generated
+5
@@ -13355,6 +13355,11 @@ public class IrJsCodegenBoxES6TestGenerated extends AbstractIrJsCodegenBoxES6Tes
|
|||||||
runTest("compiler/testData/codegen/box/ir/kt40083.kt");
|
runTest("compiler/testData/codegen/box/ir/kt40083.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt41765.kt")
|
||||||
|
public void testKt41765() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/ir/kt41765.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("objectClass.kt")
|
@TestMetadata("objectClass.kt")
|
||||||
public void testObjectClass() throws Exception {
|
public void testObjectClass() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/ir/objectClass.kt");
|
runTest("compiler/testData/codegen/box/ir/objectClass.kt");
|
||||||
|
|||||||
Generated
+5
@@ -13355,6 +13355,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
|
|||||||
runTest("compiler/testData/codegen/box/ir/kt40083.kt");
|
runTest("compiler/testData/codegen/box/ir/kt40083.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt41765.kt")
|
||||||
|
public void testKt41765() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/ir/kt41765.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("objectClass.kt")
|
@TestMetadata("objectClass.kt")
|
||||||
public void testObjectClass() throws Exception {
|
public void testObjectClass() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/ir/objectClass.kt");
|
runTest("compiler/testData/codegen/box/ir/objectClass.kt");
|
||||||
|
|||||||
+5
@@ -13420,6 +13420,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
|||||||
runTest("compiler/testData/codegen/box/ir/kt40083.kt");
|
runTest("compiler/testData/codegen/box/ir/kt40083.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt41765.kt")
|
||||||
|
public void testKt41765() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/ir/kt41765.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("objectClass.kt")
|
@TestMetadata("objectClass.kt")
|
||||||
public void testObjectClass() throws Exception {
|
public void testObjectClass() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/ir/objectClass.kt");
|
runTest("compiler/testData/codegen/box/ir/objectClass.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user