Fir2Ir: build fake overrides for abstract methods from Any

This call to isAbstractMethodOfAny was in Fir2IrLazyClass since its
inception in 0622be14a5, and there's no explanation why this was
necessary. Removing it does not seem to break anything, but fixes the
case when IrFakeOverrideRebuilder is enabled and when Java base class
declares an abstract equals/hashCode/toString which is not overridden in
the Kotlin subclass.

 #KT-63443 Fixed
This commit is contained in:
Alexander Udalov
2023-11-24 12:43:37 +01:00
committed by Space Team
parent b63a780e15
commit daac8603d0
11 changed files with 116 additions and 7 deletions
@@ -30529,6 +30529,12 @@ public class LLFirBlackBoxCodegenBasedTestGenerated extends AbstractLLFirBlackBo
@TestMetadata("compiler/testData/codegen/box/javaInterop")
@TestDataPath("$PROJECT_ROOT")
public class JavaInterop {
@Test
@TestMetadata("abstractMethodsOfAny.kt")
public void testAbstractMethodsOfAny() throws Exception {
runTest("compiler/testData/codegen/box/javaInterop/abstractMethodsOfAny.kt");
}
@Test
public void testAllFilesPresentInJavaInterop() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/javaInterop"), Pattern.compile("^(.+)\\.kt$"), null, true);
@@ -30529,6 +30529,12 @@ public class LLFirReversedBlackBoxCodegenBasedTestGenerated extends AbstractLLFi
@TestMetadata("compiler/testData/codegen/box/javaInterop")
@TestDataPath("$PROJECT_ROOT")
public class JavaInterop {
@Test
@TestMetadata("abstractMethodsOfAny.kt")
public void testAbstractMethodsOfAny() throws Exception {
runTest("compiler/testData/codegen/box/javaInterop/abstractMethodsOfAny.kt");
}
@Test
public void testAllFilesPresentInJavaInterop() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/javaInterop"), Pattern.compile("^(.+)\\.kt$"), null, true);
@@ -16,7 +16,6 @@ import org.jetbrains.kotlin.fir.isSubstitutionOrIntersectionOverride
import org.jetbrains.kotlin.fir.scopes.FirContainingNamesAwareScope
import org.jetbrains.kotlin.fir.scopes.processClassifiersByName
import org.jetbrains.kotlin.fir.symbols.impl.FirFieldSymbol
import org.jetbrains.kotlin.fir.symbols.impl.FirNamedFunctionSymbol
import org.jetbrains.kotlin.fir.symbols.impl.FirPropertySymbol
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
import org.jetbrains.kotlin.ir.declarations.*
@@ -197,7 +196,6 @@ class Fir2IrLazyClass(
symbol.isSubstitutionOrIntersectionOverride -> {}
!shouldBuildStub(symbol.fir) -> {}
symbol.containingClassLookupTag() != ownerLookupTag -> {}
symbol.isAbstractMethodOfAny() -> {}
else -> {
// Lazy declarations are created together with their symbol, so it's safe to take the owner here
@OptIn(UnsafeDuringIrConstructionAPI::class)
@@ -260,11 +258,6 @@ class Fir2IrLazyClass(
override val isNewPlaceForBodyGeneration: Boolean
get() = fir.isNewPlaceForBodyGeneration == true
private fun FirNamedFunctionSymbol.isAbstractMethodOfAny(): Boolean {
if (modality != Modality.ABSTRACT) return false
return isMethodOfAny
}
private var irLoaded: Boolean? = null
override fun loadIr(): Boolean {
@@ -30134,6 +30134,12 @@ public class FirLightTreeBlackBoxCodegenTestGenerated extends AbstractFirLightTr
@TestMetadata("compiler/testData/codegen/box/javaInterop")
@TestDataPath("$PROJECT_ROOT")
public class JavaInterop {
@Test
@TestMetadata("abstractMethodsOfAny.kt")
public void testAbstractMethodsOfAny() throws Exception {
runTest("compiler/testData/codegen/box/javaInterop/abstractMethodsOfAny.kt");
}
@Test
public void testAllFilesPresentInJavaInterop() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/javaInterop"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
@@ -30134,6 +30134,12 @@ public class FirLightTreeBlackBoxCodegenWithIrFakeOverrideGeneratorTestGenerated
@TestMetadata("compiler/testData/codegen/box/javaInterop")
@TestDataPath("$PROJECT_ROOT")
public class JavaInterop {
@Test
@TestMetadata("abstractMethodsOfAny.kt")
public void testAbstractMethodsOfAny() throws Exception {
runTest("compiler/testData/codegen/box/javaInterop/abstractMethodsOfAny.kt");
}
@Test
public void testAllFilesPresentInJavaInterop() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/javaInterop"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
@@ -30134,6 +30134,12 @@ public class FirPsiBlackBoxCodegenTestGenerated extends AbstractFirPsiBlackBoxCo
@TestMetadata("compiler/testData/codegen/box/javaInterop")
@TestDataPath("$PROJECT_ROOT")
public class JavaInterop {
@Test
@TestMetadata("abstractMethodsOfAny.kt")
public void testAbstractMethodsOfAny() throws Exception {
runTest("compiler/testData/codegen/box/javaInterop/abstractMethodsOfAny.kt");
}
@Test
public void testAllFilesPresentInJavaInterop() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/javaInterop"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
@@ -0,0 +1,63 @@
// TARGET_BACKEND: JVM
// FILE: JI.java
public interface JI {
@Override
public abstract boolean equals(Object o);
@Override
public abstract int hashCode();
@Override
public abstract String toString();
}
// FILE: JC.java
public abstract class JC {
@Override
public abstract boolean equals(Object o);
@Override
public abstract int hashCode();
@Override
public abstract String toString();
}
// FILE: JC2.java
public abstract class JC2 extends JC {
}
// FILE: box.kt
interface KI : JI
class X : KI {
override fun equals(other: Any?): Boolean = true
override fun hashCode(): Int = 0
override fun toString(): String = ""
}
abstract class KC : JC()
class Y : KC() {
override fun equals(other: Any?): Boolean = true
override fun hashCode(): Int = 0
override fun toString(): String = ""
}
abstract class KC2 : JC2()
class Z : KC2() {
override fun equals(other: Any?): Boolean = true
override fun hashCode(): Int = 0
override fun toString(): String = ""
}
fun box(): String {
X().equals(X())
X().hashCode()
X().toString()
Y().equals(Y())
Y().hashCode()
Y().toString()
Z().equals(Z())
Z().hashCode()
Z().toString()
return "OK"
}
@@ -28436,6 +28436,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
@TestMetadata("compiler/testData/codegen/box/javaInterop")
@TestDataPath("$PROJECT_ROOT")
public class JavaInterop {
@Test
@TestMetadata("abstractMethodsOfAny.kt")
public void testAbstractMethodsOfAny() throws Exception {
runTest("compiler/testData/codegen/box/javaInterop/abstractMethodsOfAny.kt");
}
@Test
public void testAllFilesPresentInJavaInterop() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/javaInterop"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true);
@@ -30134,6 +30134,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
@TestMetadata("compiler/testData/codegen/box/javaInterop")
@TestDataPath("$PROJECT_ROOT")
public class JavaInterop {
@Test
@TestMetadata("abstractMethodsOfAny.kt")
public void testAbstractMethodsOfAny() throws Exception {
runTest("compiler/testData/codegen/box/javaInterop/abstractMethodsOfAny.kt");
}
@Test
public void testAllFilesPresentInJavaInterop() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/javaInterop"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
@@ -30134,6 +30134,12 @@ public class IrBlackBoxCodegenWithIrInlinerTestGenerated extends AbstractIrBlack
@TestMetadata("compiler/testData/codegen/box/javaInterop")
@TestDataPath("$PROJECT_ROOT")
public class JavaInterop {
@Test
@TestMetadata("abstractMethodsOfAny.kt")
public void testAbstractMethodsOfAny() throws Exception {
runTest("compiler/testData/codegen/box/javaInterop/abstractMethodsOfAny.kt");
}
@Test
public void testAllFilesPresentInJavaInterop() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/javaInterop"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
@@ -25501,6 +25501,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM_IR, testDataFilePath);
}
@TestMetadata("abstractMethodsOfAny.kt")
public void testAbstractMethodsOfAny() throws Exception {
runTest("compiler/testData/codegen/box/javaInterop/abstractMethodsOfAny.kt");
}
public void testAllFilesPresentInJavaInterop() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/javaInterop"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
}