[Fir2IR] Don't add invisible fake overrides to Lazy class

^KT-65056
This commit is contained in:
Pavel Kunyavskiy
2024-01-19 13:20:33 +01:00
committed by Space Team
parent 54b06f5656
commit 09713bb89e
11 changed files with 114 additions and 11 deletions
@@ -19268,6 +19268,12 @@ public class LLFirBlackBoxCodegenBasedTestGenerated extends AbstractLLFirBlackBo
runTest("compiler/testData/codegen/box/fakeOverride/intersectionOverrideBetweenValAndVar.kt");
}
@Test
@TestMetadata("kjkWithPackagePrivate.kt")
public void testKjkWithPackagePrivate() throws Exception {
runTest("compiler/testData/codegen/box/fakeOverride/kjkWithPackagePrivate.kt");
}
@Test
@TestMetadata("kt49371.kt")
public void testKt49371() throws Exception {
@@ -19268,6 +19268,12 @@ public class LLFirReversedBlackBoxCodegenBasedTestGenerated extends AbstractLLFi
runTest("compiler/testData/codegen/box/fakeOverride/intersectionOverrideBetweenValAndVar.kt");
}
@Test
@TestMetadata("kjkWithPackagePrivate.kt")
public void testKjkWithPackagePrivate() throws Exception {
runTest("compiler/testData/codegen/box/fakeOverride/kjkWithPackagePrivate.kt");
}
@Test
@TestMetadata("kt49371.kt")
public void testKt49371() throws Exception {
@@ -6,13 +6,11 @@
package org.jetbrains.kotlin.fir.lazy
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.fir.*
import org.jetbrains.kotlin.fir.backend.*
import org.jetbrains.kotlin.fir.containingClassLookupTag
import org.jetbrains.kotlin.fir.backend.generators.isFakeOverride
import org.jetbrains.kotlin.fir.declarations.*
import org.jetbrains.kotlin.fir.declarations.utils.*
import org.jetbrains.kotlin.fir.hasEnumEntries
import org.jetbrains.kotlin.fir.isNewPlaceForBodyGeneration
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
@@ -228,13 +226,18 @@ class Fir2IrLazyClass(
result
}
private fun shouldBuildStub(fir: FirDeclaration): Boolean =
fir !is FirMemberDeclaration ||
!Visibilities.isPrivate(fir.visibility) ||
// This exception is needed for K/N caches usage
(isObject && fir is FirConstructor) ||
// Needed for enums
(this.isEnumClass && fir is FirConstructor)
private fun shouldBuildStub(fir: FirDeclaration): Boolean {
if (fir !is FirMemberDeclaration) return true
return when {
fir is FirConstructor -> isObject || isEnumClass || !Visibilities.isPrivate(fir.visibility) // This special case seams to be not needed anymore - KT-65172
fir is FirCallableDeclaration && fir.isFakeOverride(this.fir) -> session.visibilityChecker.isVisibleForOverriding(
this.fir.moduleData,
this.fir.classId.packageFqName,
fir
)
else -> !Visibilities.isPrivate(fir.visibility)
}
}
override var metadata: MetadataSource?
get() = null
@@ -19257,6 +19257,12 @@ public class FirLightTreeBlackBoxCodegenTestGenerated extends AbstractFirLightTr
runTest("compiler/testData/codegen/box/fakeOverride/intersectionOverrideBetweenValAndVar.kt");
}
@Test
@TestMetadata("kjkWithPackagePrivate.kt")
public void testKjkWithPackagePrivate() throws Exception {
runTest("compiler/testData/codegen/box/fakeOverride/kjkWithPackagePrivate.kt");
}
@Test
@TestMetadata("kt49371.kt")
public void testKt49371() throws Exception {
@@ -19257,6 +19257,12 @@ public class FirLightTreeBlackBoxCodegenWithIrFakeOverrideGeneratorTestGenerated
runTest("compiler/testData/codegen/box/fakeOverride/intersectionOverrideBetweenValAndVar.kt");
}
@Test
@TestMetadata("kjkWithPackagePrivate.kt")
public void testKjkWithPackagePrivate() throws Exception {
runTest("compiler/testData/codegen/box/fakeOverride/kjkWithPackagePrivate.kt");
}
@Test
@TestMetadata("kt49371.kt")
public void testKt49371() throws Exception {
@@ -19257,6 +19257,12 @@ public class FirPsiBlackBoxCodegenTestGenerated extends AbstractFirPsiBlackBoxCo
runTest("compiler/testData/codegen/box/fakeOverride/intersectionOverrideBetweenValAndVar.kt");
}
@Test
@TestMetadata("kjkWithPackagePrivate.kt")
public void testKjkWithPackagePrivate() throws Exception {
runTest("compiler/testData/codegen/box/fakeOverride/kjkWithPackagePrivate.kt");
}
@Test
@TestMetadata("kt49371.kt")
public void testKt49371() throws Exception {
@@ -0,0 +1,47 @@
// TARGET_BACKEND: JVM_IR
// FILE: a/A.java
package a;
public class A {
String foo() { return "OK"; }
String bar() { return "OK"; }
public static String runFoo(A a) { return a.foo();}
public static String runBar(A a) { return a.bar();}
}
// FILE: c/C.kt
package c
open class C : a.A() {
fun bar(): String = "FAIL"
}
// FILE: c/D.java
package c;
public class D extends C {}
// FILE: c/E.kt
package c
open class E : D() {
}
// FILE: box.kt
import a.*
import c.*
fun box(): String {
if (A.runFoo(A()) != "OK") return "FAIL";
if (A.runFoo(C()) != "OK") return "FAIL";
if (A.runFoo(D()) != "OK") return "FAIL";
if (A.runFoo(E()) != "OK") return "FAIL";
if (A.runBar(A()) != "OK") return "FAIL";
if (A.runBar(C()) != "OK") return "FAIL";
if (A.runBar(D()) != "OK") return "FAIL";
if (A.runBar(E()) != "OK") return "FAIL";
return "OK"
}
@@ -19257,6 +19257,12 @@ public class JvmAbiConsistencyTestBoxGenerated extends AbstractJvmAbiConsistency
runTest("compiler/testData/codegen/box/fakeOverride/intersectionOverrideBetweenValAndVar.kt");
}
@Test
@TestMetadata("kjkWithPackagePrivate.kt")
public void testKjkWithPackagePrivate() throws Exception {
runTest("compiler/testData/codegen/box/fakeOverride/kjkWithPackagePrivate.kt");
}
@Test
@TestMetadata("kt49371.kt")
public void testKt49371() throws Exception {
@@ -19257,6 +19257,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTest("compiler/testData/codegen/box/fakeOverride/intersectionOverrideBetweenValAndVar.kt");
}
@Test
@TestMetadata("kjkWithPackagePrivate.kt")
public void testKjkWithPackagePrivate() throws Exception {
runTest("compiler/testData/codegen/box/fakeOverride/kjkWithPackagePrivate.kt");
}
@Test
@TestMetadata("kt49371.kt")
public void testKt49371() throws Exception {
@@ -19257,6 +19257,12 @@ public class IrBlackBoxCodegenWithIrInlinerTestGenerated extends AbstractIrBlack
runTest("compiler/testData/codegen/box/fakeOverride/intersectionOverrideBetweenValAndVar.kt");
}
@Test
@TestMetadata("kjkWithPackagePrivate.kt")
public void testKjkWithPackagePrivate() throws Exception {
runTest("compiler/testData/codegen/box/fakeOverride/kjkWithPackagePrivate.kt");
}
@Test
@TestMetadata("kt49371.kt")
public void testKt49371() throws Exception {
@@ -16044,6 +16044,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTest("compiler/testData/codegen/box/fakeOverride/intersectionOverrideBetweenValAndVar.kt");
}
@TestMetadata("kjkWithPackagePrivate.kt")
public void testKjkWithPackagePrivate() throws Exception {
runTest("compiler/testData/codegen/box/fakeOverride/kjkWithPackagePrivate.kt");
}
@TestMetadata("kt49371.kt")
public void testKt49371() throws Exception {
runTest("compiler/testData/codegen/box/fakeOverride/kt49371.kt");