IR: never check static members for overridability

#KT-66077 Fixed
This commit is contained in:
Alexander Udalov
2024-02-26 12:20:32 +01:00
committed by Space Team
parent bdb96dc0db
commit d4278250e6
13 changed files with 95 additions and 10 deletions
@@ -34077,6 +34077,12 @@ public class LLFirBlackBoxCodegenBasedTestGenerated extends AbstractLLFirBlackBo
runTest("compiler/testData/codegen/box/javaInterop/statics/inheritTwoStaticMethods.kt");
}
@Test
@TestMetadata("inheritTwoStaticMethods2.kt")
public void testInheritTwoStaticMethods2() {
runTest("compiler/testData/codegen/box/javaInterop/statics/inheritTwoStaticMethods2.kt");
}
@Test
@TestMetadata("jkkjk.kt")
public void testJkkjk() {
@@ -34077,6 +34077,12 @@ public class LLFirReversedBlackBoxCodegenBasedTestGenerated extends AbstractLLFi
runTest("compiler/testData/codegen/box/javaInterop/statics/inheritTwoStaticMethods.kt");
}
@Test
@TestMetadata("inheritTwoStaticMethods2.kt")
public void testInheritTwoStaticMethods2() {
runTest("compiler/testData/codegen/box/javaInterop/statics/inheritTwoStaticMethods2.kt");
}
@Test
@TestMetadata("jkkjk.kt")
public void testJkkjk() {
@@ -33946,6 +33946,12 @@ public class FirLightTreeBlackBoxCodegenTestGenerated extends AbstractFirLightTr
runTest("compiler/testData/codegen/box/javaInterop/statics/inheritTwoStaticMethods.kt");
}
@Test
@TestMetadata("inheritTwoStaticMethods2.kt")
public void testInheritTwoStaticMethods2() {
runTest("compiler/testData/codegen/box/javaInterop/statics/inheritTwoStaticMethods2.kt");
}
@Test
@TestMetadata("jkkjk.kt")
public void testJkkjk() {
@@ -33946,6 +33946,12 @@ public class FirLightTreeBlackBoxCodegenWithIrFakeOverrideGeneratorTestGenerated
runTest("compiler/testData/codegen/box/javaInterop/statics/inheritTwoStaticMethods.kt");
}
@Test
@TestMetadata("inheritTwoStaticMethods2.kt")
public void testInheritTwoStaticMethods2() {
runTest("compiler/testData/codegen/box/javaInterop/statics/inheritTwoStaticMethods2.kt");
}
@Test
@TestMetadata("jkkjk.kt")
public void testJkkjk() {
@@ -33946,6 +33946,12 @@ public class FirPsiBlackBoxCodegenTestGenerated extends AbstractFirPsiBlackBoxCo
runTest("compiler/testData/codegen/box/javaInterop/statics/inheritTwoStaticMethods.kt");
}
@Test
@TestMetadata("inheritTwoStaticMethods2.kt")
public void testInheritTwoStaticMethods2() {
runTest("compiler/testData/codegen/box/javaInterop/statics/inheritTwoStaticMethods2.kt");
}
@Test
@TestMetadata("jkkjk.kt")
public void testJkkjk() {
@@ -67,7 +67,7 @@ class IrFakeOverrideBuilder(
val (staticMembers, instanceMembers) =
clazz.declarations.filterIsInstance<IrOverridableMember>().partition { it.isStaticMember }
buildFakeOverridesForClassImpl(clazz, instanceMembers, oldSignatures, clazz.superTypes) { !it.isStaticMember }
buildFakeOverridesForClassImpl(clazz, instanceMembers, oldSignatures, clazz.superTypes, isStaticMembers = false)
// Static Java members from the superclass need fake overrides in the subclass, to support the case when the static member is
// declared in an inaccessible grandparent class but is exposed as public in the parent. For example:
@@ -80,7 +80,7 @@ class IrFakeOverrideBuilder(
// we need to generate a fake override in class B. This is only possible in case of superclasses, as static _interface_ members
// are not inherited (see JLS 8.4.8 and 9.4.1).
val superClass = clazz.superTypes.filter { it.classOrFail.owner.isClass }
buildFakeOverridesForClassImpl(clazz, staticMembers, oldSignatures, superClass) { it.isStaticMember }
buildFakeOverridesForClassImpl(clazz, staticMembers, oldSignatures, superClass, isStaticMembers = true)
}
}
@@ -89,11 +89,11 @@ class IrFakeOverrideBuilder(
allFromCurrent: List<IrOverridableMember>,
oldSignatures: Boolean,
supertypes: List<IrType>,
declarationFilter: (IrOverridableMember) -> Boolean,
isStaticMembers: Boolean,
) {
val allFromSuper = supertypes.flatMap { superType ->
superType.classOrFail.owner.declarations
.filterIsInstanceAnd<IrOverridableMember>(declarationFilter)
.filterIsInstanceAnd<IrOverridableMember> { it.isStaticMember == isStaticMembers }
.mapNotNull {
val fakeOverride = strategy.fakeOverrideMember(superType, it, clazz) ?: return@mapNotNull null
FakeOverride(fakeOverride, it)
@@ -105,10 +105,7 @@ class IrFakeOverrideBuilder(
allFromSuperByName.forEach { (name, superMembers) ->
generateOverridesInFunctionGroup(
superMembers,
allFromCurrentByName[name] ?: emptyList(),
clazz,
oldSignatures
superMembers, allFromCurrentByName[name] ?: emptyList(), clazz, oldSignatures, isStaticMembers
)
}
@@ -164,7 +161,8 @@ class IrFakeOverrideBuilder(
membersFromSupertypes: List<FakeOverride>,
membersFromCurrent: List<IrOverridableMember>,
current: IrClass,
compatibilityMode: Boolean
compatibilityMode: Boolean,
isStaticMembers: Boolean,
) {
val notOverridden = membersFromSupertypes.toMutableSet()
@@ -174,7 +172,11 @@ class IrFakeOverrideBuilder(
}
val addedFakeOverrides = mutableListOf<IrOverridableMember>()
createAndBindFakeOverrides(current, notOverridden, addedFakeOverrides, compatibilityMode)
if (isStaticMembers) {
createAndBindFakeOverride(notOverridden.toList(), current, addedFakeOverrides, compatibilityMode)
} else {
createAndBindFakeOverrides(current, notOverridden, addedFakeOverrides, compatibilityMode)
}
current.declarations.addAll(addedFakeOverrides)
}
@@ -0,0 +1,18 @@
// TARGET_BACKEND: JVM
// FILE: A.java
public class A {
public static String f(Long x) {
return "Fail";
}
public static String f(long x) {
return "OK";
}
}
// FILE: 1.kt
class B : A() {
fun g(): String = f(0L)
}
fun box(): String = B().g()
@@ -33946,6 +33946,12 @@ public class JvmAbiConsistencyTestBoxGenerated extends AbstractJvmAbiConsistency
runTest("compiler/testData/codegen/box/javaInterop/statics/inheritTwoStaticMethods.kt");
}
@Test
@TestMetadata("inheritTwoStaticMethods2.kt")
public void testInheritTwoStaticMethods2() {
runTest("compiler/testData/codegen/box/javaInterop/statics/inheritTwoStaticMethods2.kt");
}
@Test
@TestMetadata("jkkjk.kt")
public void testJkkjk() {
@@ -32086,6 +32086,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTest("compiler/testData/codegen/box/javaInterop/statics/inheritTwoStaticMethods.kt");
}
@Test
@TestMetadata("inheritTwoStaticMethods2.kt")
public void testInheritTwoStaticMethods2() {
runTest("compiler/testData/codegen/box/javaInterop/statics/inheritTwoStaticMethods2.kt");
}
@Test
@TestMetadata("jkkjk.kt")
public void testJkkjk() {
@@ -33946,6 +33946,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTest("compiler/testData/codegen/box/javaInterop/statics/inheritTwoStaticMethods.kt");
}
@Test
@TestMetadata("inheritTwoStaticMethods2.kt")
public void testInheritTwoStaticMethods2() {
runTest("compiler/testData/codegen/box/javaInterop/statics/inheritTwoStaticMethods2.kt");
}
@Test
@TestMetadata("jkkjk.kt")
public void testJkkjk() {
@@ -33946,6 +33946,12 @@ public class IrBlackBoxCodegenWithIrInlinerTestGenerated extends AbstractIrBlack
runTest("compiler/testData/codegen/box/javaInterop/statics/inheritTwoStaticMethods.kt");
}
@Test
@TestMetadata("inheritTwoStaticMethods2.kt")
public void testInheritTwoStaticMethods2() {
runTest("compiler/testData/codegen/box/javaInterop/statics/inheritTwoStaticMethods2.kt");
}
@Test
@TestMetadata("jkkjk.kt")
public void testJkkjk() {
@@ -33946,6 +33946,12 @@ public class FirBlackBoxCodegenTestWithInlineScopesGenerated extends AbstractFir
runTest("compiler/testData/codegen/box/javaInterop/statics/inheritTwoStaticMethods.kt");
}
@Test
@TestMetadata("inheritTwoStaticMethods2.kt")
public void testInheritTwoStaticMethods2() {
runTest("compiler/testData/codegen/box/javaInterop/statics/inheritTwoStaticMethods2.kt");
}
@Test
@TestMetadata("jkkjk.kt")
public void testJkkjk() {
@@ -28808,6 +28808,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTest("compiler/testData/codegen/box/javaInterop/statics/inheritTwoStaticMethods.kt");
}
@TestMetadata("inheritTwoStaticMethods2.kt")
public void testInheritTwoStaticMethods2() {
runTest("compiler/testData/codegen/box/javaInterop/statics/inheritTwoStaticMethods2.kt");
}
@TestMetadata("jkkjk.kt")
public void testJkkjk() {
runTest("compiler/testData/codegen/box/javaInterop/statics/jkkjk.kt");