IR: don't produce fake overrides for static and private declarations

Note that only irrelevantStaticProperty.kt failed before this change.
Having private declarations caused no problems, but it seems incorrect,
so it's fixed now and irrelevantPrivateDeclarations is added just in
case.

 #KT-41848 Fixed
This commit is contained in:
Alexander Udalov
2020-09-11 20:48:43 +02:00
parent 703150e3ad
commit 2f86554d5a
10 changed files with 126 additions and 5 deletions
@@ -11899,6 +11899,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
runTest("compiler/testData/codegen/box/funInterface/intersectionTypeToFunInterfaceConversion.kt");
}
@TestMetadata("irrelevantPrivateDeclarations.kt")
public void testIrrelevantPrivateDeclarations() throws Exception {
runTest("compiler/testData/codegen/box/funInterface/irrelevantPrivateDeclarations.kt");
}
@TestMetadata("multimodule.kt")
public void testMultimodule() throws Exception {
runTest("compiler/testData/codegen/box/funInterface/multimodule.kt");
@@ -29075,6 +29080,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
runTest("compiler/testData/codegen/box/sam/inlinedSamWrapper.kt");
}
@TestMetadata("irrelevantStaticProperty.kt")
public void testIrrelevantStaticProperty() throws Exception {
runTest("compiler/testData/codegen/box/sam/irrelevantStaticProperty.kt");
}
@TestMetadata("kt17091.kt")
public void testKt17091() throws Exception {
runTest("compiler/testData/codegen/box/sam/kt17091.kt");
@@ -91,7 +91,8 @@ class IrOverridingUtil(
is IrProperty -> {
fakeOverrideBuilder.propertyOverriddenSymbols[this] =
value.map { it as? IrPropertySymbol ?: error("Unexpected property overridden symbol: $it") }
this.getter!!.overriddenSymbols = value.map { (it.owner as IrProperty).getter!!.symbol }
val getter = this.getter ?: error("Property has no getter: ${render()}")
getter.overriddenSymbols = value.map { (it.owner as IrProperty).getter!!.symbol }
this.setter?.let { setter ->
setter.overriddenSymbols = value.mapNotNull { (it.owner as IrProperty).setter?.symbol }
}
@@ -162,10 +163,12 @@ class IrOverridingUtil(
val superClass = superType.getClass() ?: error("Unexpected super type: $superType")
superClass.declarations
.filterIsInstance<IrOverridableMember>()
.filter { it !in overriddenMembers }
.map { overridenMember ->
val fakeOverride = fakeOverrideBuilder.fakeOverrideMember(superType, overridenMember, clazz)
originals[fakeOverride] = overridenMember
.filterNot {
it in overriddenMembers || it.isStaticMember || DescriptorVisibilities.isPrivate(it.visibility)
}
.map { overriddenMember ->
val fakeOverride = fakeOverrideBuilder.fakeOverrideMember(superType, overriddenMember, clazz)
originals[fakeOverride] = overriddenMember
originalSuperTypes[fakeOverride] = superType
fakeOverride
}
@@ -179,6 +182,16 @@ class IrOverridingUtil(
return fakeOverrides
}
private val IrOverridableMember.isStaticMember: Boolean
get() = when (this) {
is IrFunction ->
dispatchReceiverParameter == null
is IrProperty ->
backingField?.isStatic == true ||
getter?.let { it.dispatchReceiverParameter == null } == true
else -> error("Unknown overridable member: ${render()}")
}
private fun generateOverridesInFunctionGroup(
membersFromSupertypes: List<IrOverridableMember>,
membersFromCurrent: List<IrOverridableMember>,
@@ -0,0 +1,24 @@
fun interface A {
fun invoke(s: String)
private fun privateFun() {}
private var privateProperty: String
get() = ""
set(value) {}
companion object {
fun s(a: A) {
a.invoke("OK")
}
}
}
fun test(f: (String) -> Unit) {
A.s(f)
}
fun box(): String {
var result = "Fail"
test { result = it }
return result
}
@@ -0,0 +1,29 @@
// TARGET_BACKEND: JVM
// JVM_TARGET: 1.8
// FILE: box.kt
fun test(f: (String) -> Unit) {
A.s(f)
}
fun box(): String {
var result = "Fail"
test { result = it }
return result
}
// FILE: A.java
public interface A<T> {
void f(T t);
A<Object> N = new A<Object>() {
@Override
public void f(final Object object) {
}
};
static void s(A<String> a) {
a.f("OK");
}
}
@@ -13294,6 +13294,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTest("compiler/testData/codegen/box/funInterface/intersectionTypeToFunInterfaceConversion.kt");
}
@TestMetadata("irrelevantPrivateDeclarations.kt")
public void testIrrelevantPrivateDeclarations() throws Exception {
runTest("compiler/testData/codegen/box/funInterface/irrelevantPrivateDeclarations.kt");
}
@TestMetadata("multimodule.kt")
public void testMultimodule() throws Exception {
runTest("compiler/testData/codegen/box/funInterface/multimodule.kt");
@@ -30841,6 +30846,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTest("compiler/testData/codegen/box/sam/inlinedSamWrapper.kt");
}
@TestMetadata("irrelevantStaticProperty.kt")
public void testIrrelevantStaticProperty() throws Exception {
runTest("compiler/testData/codegen/box/sam/irrelevantStaticProperty.kt");
}
@TestMetadata("kt17091.kt")
public void testKt17091() throws Exception {
runTest("compiler/testData/codegen/box/sam/kt17091.kt");
@@ -13294,6 +13294,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTest("compiler/testData/codegen/box/funInterface/intersectionTypeToFunInterfaceConversion.kt");
}
@TestMetadata("irrelevantPrivateDeclarations.kt")
public void testIrrelevantPrivateDeclarations() throws Exception {
runTest("compiler/testData/codegen/box/funInterface/irrelevantPrivateDeclarations.kt");
}
@TestMetadata("multimodule.kt")
public void testMultimodule() throws Exception {
runTest("compiler/testData/codegen/box/funInterface/multimodule.kt");
@@ -28475,6 +28480,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTest("compiler/testData/codegen/box/sam/inlinedSamWrapper.kt");
}
@TestMetadata("irrelevantStaticProperty.kt")
public void testIrrelevantStaticProperty() throws Exception {
runTest("compiler/testData/codegen/box/sam/irrelevantStaticProperty.kt");
}
@TestMetadata("kt17091.kt")
public void testKt17091() throws Exception {
runTest("compiler/testData/codegen/box/sam/kt17091.kt");
@@ -11899,6 +11899,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTest("compiler/testData/codegen/box/funInterface/intersectionTypeToFunInterfaceConversion.kt");
}
@TestMetadata("irrelevantPrivateDeclarations.kt")
public void testIrrelevantPrivateDeclarations() throws Exception {
runTest("compiler/testData/codegen/box/funInterface/irrelevantPrivateDeclarations.kt");
}
@TestMetadata("multimodule.kt")
public void testMultimodule() throws Exception {
runTest("compiler/testData/codegen/box/funInterface/multimodule.kt");
@@ -29075,6 +29080,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTest("compiler/testData/codegen/box/sam/inlinedSamWrapper.kt");
}
@TestMetadata("irrelevantStaticProperty.kt")
public void testIrrelevantStaticProperty() throws Exception {
runTest("compiler/testData/codegen/box/sam/irrelevantStaticProperty.kt");
}
@TestMetadata("kt17091.kt")
public void testKt17091() throws Exception {
runTest("compiler/testData/codegen/box/sam/kt17091.kt");
@@ -10224,6 +10224,11 @@ public class IrJsCodegenBoxES6TestGenerated extends AbstractIrJsCodegenBoxES6Tes
runTest("compiler/testData/codegen/box/funInterface/intersectionTypeToFunInterfaceConversion.kt");
}
@TestMetadata("irrelevantPrivateDeclarations.kt")
public void testIrrelevantPrivateDeclarations() throws Exception {
runTest("compiler/testData/codegen/box/funInterface/irrelevantPrivateDeclarations.kt");
}
@TestMetadata("multimodule.kt")
public void testMultimodule() throws Exception {
runTest("compiler/testData/codegen/box/funInterface/multimodule.kt");
@@ -10224,6 +10224,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/funInterface/intersectionTypeToFunInterfaceConversion.kt");
}
@TestMetadata("irrelevantPrivateDeclarations.kt")
public void testIrrelevantPrivateDeclarations() throws Exception {
runTest("compiler/testData/codegen/box/funInterface/irrelevantPrivateDeclarations.kt");
}
@TestMetadata("multimodule.kt")
public void testMultimodule() throws Exception {
runTest("compiler/testData/codegen/box/funInterface/multimodule.kt");
@@ -10224,6 +10224,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/funInterface/intersectionTypeToFunInterfaceConversion.kt");
}
@TestMetadata("irrelevantPrivateDeclarations.kt")
public void testIrrelevantPrivateDeclarations() throws Exception {
runTest("compiler/testData/codegen/box/funInterface/irrelevantPrivateDeclarations.kt");
}
@TestMetadata("multimodule.kt")
public void testMultimodule() throws Exception {
runTest("compiler/testData/codegen/box/funInterface/multimodule.kt");