IR: remove isFromJava check from isOverridableMemberOrAccessor
This is needed because in case a static member is inherited via a Kotlin class (class C in the newly added test), its origin becomes FAKE_OVERRIDE which is technically not Java anymore. After this change, we'll build fake overrides for static members from superclasses regardless of whether they come from Java or Kotlin. Also, move the previous logic of isOverridableFunction/isOverridableProperty to the only call site at IdSignatureFactory. #KT-65589 Fixed
This commit is contained in:
committed by
Space Team
parent
03418c11c3
commit
b72effab98
+6
@@ -31931,6 +31931,12 @@ public class LLFirBlackBoxCodegenBasedTestGenerated extends AbstractLLFirBlackBo
|
||||
runTest("compiler/testData/codegen/box/javaInterop/statics/inheritTwoStaticMethods.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("jkkjk.kt")
|
||||
public void testJkkjk() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/javaInterop/statics/jkkjk.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("overrideInstanceMethodWithIrrelevantStatic.kt")
|
||||
public void testOverrideInstanceMethodWithIrrelevantStatic() throws Exception {
|
||||
|
||||
+6
@@ -31931,6 +31931,12 @@ public class LLFirReversedBlackBoxCodegenBasedTestGenerated extends AbstractLLFi
|
||||
runTest("compiler/testData/codegen/box/javaInterop/statics/inheritTwoStaticMethods.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("jkkjk.kt")
|
||||
public void testJkkjk() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/javaInterop/statics/jkkjk.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("overrideInstanceMethodWithIrrelevantStatic.kt")
|
||||
public void testOverrideInstanceMethodWithIrrelevantStatic() throws Exception {
|
||||
|
||||
+6
@@ -31594,6 +31594,12 @@ public class FirLightTreeBlackBoxCodegenTestGenerated extends AbstractFirLightTr
|
||||
runTest("compiler/testData/codegen/box/javaInterop/statics/inheritTwoStaticMethods.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("jkkjk.kt")
|
||||
public void testJkkjk() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/javaInterop/statics/jkkjk.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("overrideInstanceMethodWithIrrelevantStatic.kt")
|
||||
public void testOverrideInstanceMethodWithIrrelevantStatic() throws Exception {
|
||||
|
||||
+6
@@ -31594,6 +31594,12 @@ public class FirLightTreeBlackBoxCodegenWithIrFakeOverrideGeneratorTestGenerated
|
||||
runTest("compiler/testData/codegen/box/javaInterop/statics/inheritTwoStaticMethods.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("jkkjk.kt")
|
||||
public void testJkkjk() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/javaInterop/statics/jkkjk.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("overrideInstanceMethodWithIrrelevantStatic.kt")
|
||||
public void testOverrideInstanceMethodWithIrrelevantStatic() throws Exception {
|
||||
|
||||
+6
@@ -31594,6 +31594,12 @@ public class FirPsiBlackBoxCodegenTestGenerated extends AbstractFirPsiBlackBoxCo
|
||||
runTest("compiler/testData/codegen/box/javaInterop/statics/inheritTwoStaticMethods.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("jkkjk.kt")
|
||||
public void testJkkjk() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/javaInterop/statics/jkkjk.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("overrideInstanceMethodWithIrrelevantStatic.kt")
|
||||
public void testOverrideInstanceMethodWithIrrelevantStatic() throws Exception {
|
||||
|
||||
+5
-3
@@ -5,13 +5,15 @@
|
||||
|
||||
package org.jetbrains.kotlin.ir.overrides
|
||||
|
||||
import org.jetbrains.kotlin.builtins.StandardNames
|
||||
import org.jetbrains.kotlin.descriptors.DescriptorVisibilities
|
||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrTypeParameterSymbol
|
||||
import org.jetbrains.kotlin.ir.types.*
|
||||
import org.jetbrains.kotlin.ir.types.IrSimpleType
|
||||
import org.jetbrains.kotlin.ir.types.IrType
|
||||
import org.jetbrains.kotlin.ir.types.IrTypeProjection
|
||||
import org.jetbrains.kotlin.ir.types.extractTypeParameters
|
||||
import org.jetbrains.kotlin.ir.util.getPackageFragment
|
||||
import org.jetbrains.kotlin.ir.util.hasAnnotation
|
||||
import org.jetbrains.kotlin.ir.util.render
|
||||
@@ -39,7 +41,7 @@ abstract class FakeOverrideBuilderStrategy(
|
||||
* if no fake override should be created for this member
|
||||
*/
|
||||
fun fakeOverrideMember(superType: IrType, member: IrOverridableMember, clazz: IrClass): IrOverridableMember? {
|
||||
return if (member.isOverridableMemberOrAccessor() && isVisibleForOverrideInClass(member, clazz))
|
||||
return if (isVisibleForOverrideInClass(member, clazz))
|
||||
buildFakeOverrideMember(superType, member, clazz, unimplementedOverridesStrategy)
|
||||
else
|
||||
null
|
||||
|
||||
@@ -13,7 +13,10 @@ import org.jetbrains.kotlin.ir.symbols.IrPropertySymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrSymbol
|
||||
import org.jetbrains.kotlin.ir.types.*
|
||||
import org.jetbrains.kotlin.ir.util.*
|
||||
import org.jetbrains.kotlin.ir.util.collectAndFilterRealOverrides
|
||||
import org.jetbrains.kotlin.ir.util.fileOrNull
|
||||
import org.jetbrains.kotlin.ir.util.isClass
|
||||
import org.jetbrains.kotlin.ir.util.render
|
||||
import org.jetbrains.kotlin.resolve.OverridingUtil.OverrideCompatibilityInfo
|
||||
import org.jetbrains.kotlin.types.AbstractTypeChecker
|
||||
import org.jetbrains.kotlin.types.TypeCheckerState
|
||||
@@ -204,7 +207,7 @@ class IrFakeOverrideBuilder(
|
||||
|
||||
// because of binary incompatible changes, it's possible to have private member colliding with fake override
|
||||
// In that case we shouldn't generate fake override, but also shouldn't mark them as overridden
|
||||
if (fromCurrent.isOverridableMemberOrAccessor()) {
|
||||
if (!DescriptorVisibilities.isPrivate(fromCurrent.visibility)) {
|
||||
fromCurrent.overriddenSymbols = overridden.memoryOptimizedMap { it.original.symbol }
|
||||
}
|
||||
|
||||
@@ -527,15 +530,3 @@ private val IrOverridableMember.returnType: IrType
|
||||
is IrProperty -> getter!!.returnType
|
||||
else -> error("Unexpected type of declaration: ${this::class.java}, $this")
|
||||
}
|
||||
|
||||
fun IrSimpleFunction.isOverridableFunction(): Boolean =
|
||||
!DescriptorVisibilities.isPrivate(visibility) && (hasDispatchReceiver || isFromJava())
|
||||
|
||||
fun IrProperty.isOverridableProperty(): Boolean =
|
||||
!DescriptorVisibilities.isPrivate(visibility) && (getter.hasDispatchReceiver || setter.hasDispatchReceiver || isFromJava())
|
||||
|
||||
fun IrDeclaration.isOverridableMemberOrAccessor(): Boolean = when (this) {
|
||||
is IrSimpleFunction -> isOverridableFunction()
|
||||
is IrProperty -> isOverridableProperty()
|
||||
else -> false
|
||||
}
|
||||
|
||||
@@ -191,9 +191,6 @@ class IrOverrideChecker(
|
||||
private val IrSimpleFunction?.hasExtensionReceiver: Boolean
|
||||
get() = this?.extensionReceiverParameter != null
|
||||
|
||||
internal val IrSimpleFunction?.hasDispatchReceiver: Boolean
|
||||
get() = this?.dispatchReceiverParameter != null
|
||||
|
||||
private val IrSimpleFunction.compiledValueParameters: List<IrValueParameter>
|
||||
get() = ArrayList<IrValueParameter>(valueParameters.size + 1).apply {
|
||||
extensionReceiverParameter?.let(::add)
|
||||
|
||||
+10
-6
@@ -11,13 +11,8 @@ import org.jetbrains.kotlin.descriptors.ClassKind
|
||||
import org.jetbrains.kotlin.descriptors.DescriptorVisibilities
|
||||
import org.jetbrains.kotlin.ir.IrElement
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
import org.jetbrains.kotlin.ir.overrides.isOverridableFunction
|
||||
import org.jetbrains.kotlin.ir.overrides.isOverridableProperty
|
||||
import org.jetbrains.kotlin.ir.symbols.IrFileSymbol
|
||||
import org.jetbrains.kotlin.ir.util.IdSignature
|
||||
import org.jetbrains.kotlin.ir.util.KotlinMangler
|
||||
import org.jetbrains.kotlin.ir.util.isFacadeClass
|
||||
import org.jetbrains.kotlin.ir.util.render
|
||||
import org.jetbrains.kotlin.ir.util.*
|
||||
import org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid
|
||||
import org.jetbrains.kotlin.ir.visitors.acceptVoid
|
||||
|
||||
@@ -277,4 +272,13 @@ class IdSignatureFactory(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun IrSimpleFunction.isOverridableFunction(): Boolean =
|
||||
!DescriptorVisibilities.isPrivate(visibility) && (hasDispatchReceiver || isFromJava())
|
||||
|
||||
private fun IrProperty.isOverridableProperty(): Boolean =
|
||||
!DescriptorVisibilities.isPrivate(visibility) && (getter.hasDispatchReceiver || setter.hasDispatchReceiver || isFromJava())
|
||||
|
||||
private val IrSimpleFunction?.hasDispatchReceiver: Boolean
|
||||
get() = this?.dispatchReceiverParameter != null
|
||||
}
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// FILE: A.java
|
||||
public class A {
|
||||
public static String o = "O";
|
||||
|
||||
public static String k() {
|
||||
return "K";
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: B.kt
|
||||
open class B : A()
|
||||
|
||||
// FILE: C.kt
|
||||
open class C : B()
|
||||
|
||||
// FILE: D.java
|
||||
public class D extends C {}
|
||||
|
||||
// FILE: E.kt
|
||||
class E : D() {
|
||||
fun g(): String = o + k()
|
||||
}
|
||||
|
||||
// FILE: box.kt
|
||||
fun box(): String = E().g()
|
||||
+6
@@ -31594,6 +31594,12 @@ public class JvmAbiConsistencyTestBoxGenerated extends AbstractJvmAbiConsistency
|
||||
runTest("compiler/testData/codegen/box/javaInterop/statics/inheritTwoStaticMethods.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("jkkjk.kt")
|
||||
public void testJkkjk() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/javaInterop/statics/jkkjk.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("overrideInstanceMethodWithIrrelevantStatic.kt")
|
||||
public void testOverrideInstanceMethodWithIrrelevantStatic() throws Exception {
|
||||
|
||||
+6
@@ -29770,6 +29770,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
runTest("compiler/testData/codegen/box/javaInterop/statics/inheritTwoStaticMethods.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("jkkjk.kt")
|
||||
public void testJkkjk() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/javaInterop/statics/jkkjk.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("overrideInstanceMethodWithIrrelevantStatic.kt")
|
||||
public void testOverrideInstanceMethodWithIrrelevantStatic() throws Exception {
|
||||
|
||||
+6
@@ -31594,6 +31594,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
runTest("compiler/testData/codegen/box/javaInterop/statics/inheritTwoStaticMethods.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("jkkjk.kt")
|
||||
public void testJkkjk() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/javaInterop/statics/jkkjk.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("overrideInstanceMethodWithIrrelevantStatic.kt")
|
||||
public void testOverrideInstanceMethodWithIrrelevantStatic() throws Exception {
|
||||
|
||||
+6
@@ -31594,6 +31594,12 @@ public class IrBlackBoxCodegenWithIrInlinerTestGenerated extends AbstractIrBlack
|
||||
runTest("compiler/testData/codegen/box/javaInterop/statics/inheritTwoStaticMethods.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("jkkjk.kt")
|
||||
public void testJkkjk() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/javaInterop/statics/jkkjk.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("overrideInstanceMethodWithIrrelevantStatic.kt")
|
||||
public void testOverrideInstanceMethodWithIrrelevantStatic() throws Exception {
|
||||
|
||||
+5
@@ -26806,6 +26806,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
runTest("compiler/testData/codegen/box/javaInterop/statics/inheritTwoStaticMethods.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("jkkjk.kt")
|
||||
public void testJkkjk() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/javaInterop/statics/jkkjk.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("overrideInstanceMethodWithIrrelevantStatic.kt")
|
||||
public void testOverrideInstanceMethodWithIrrelevantStatic() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/javaInterop/statics/overrideInstanceMethodWithIrrelevantStatic.kt");
|
||||
|
||||
Reference in New Issue
Block a user