Revert "FIR2IR: minimize scope processing in fake override generation"

This reverts commit 9934cfbb00.

See the tests added: Subclass may have private same-name method that
should not be a reason to avoid generating fake overrides
This commit is contained in:
Denis.Zharkov
2021-03-31 11:55:51 +03:00
parent 55e5af1111
commit fa65081878
10 changed files with 53 additions and 13 deletions
@@ -67,21 +67,9 @@ class FakeOverrideGenerator(
}
fun IrClass.getFakeOverrides(klass: FirClass<*>, realDeclarations: Collection<FirDeclaration>): List<IrDeclaration> {
val classLookupTag = klass.symbol.toLookupTag()
val realDeclarationNames = realDeclarations.mapNotNullTo(mutableSetOf()) {
val callableDeclaration = (it as? FirCallableMemberDeclaration<*>) ?: return@mapNotNullTo null
// We may need to create a new fake override or compute base symbols.
if (callableDeclaration.symbol.shouldHaveComputedBaseSymbolsForClass(classLookupTag) ||
callableDeclaration.allowsToHaveFakeOverrideIn(klass)
) null
// Otherwise, bail out early based on the name of the contributed member declaration
else callableDeclaration.symbol.callableId.callableName
}
val result = mutableListOf<IrDeclaration>()
val useSiteMemberScope = klass.unsubstitutedScope(session, scopeSession, withForcedTypeCalculator = true)
val superTypesCallableNames = useSiteMemberScope.getCallableNames().filter { it !in realDeclarationNames }
val superTypesCallableNames = useSiteMemberScope.getCallableNames()
val realDeclarationSymbols = realDeclarations.filterIsInstance<FirSymbolOwner<*>>().mapTo(mutableSetOf(), FirSymbolOwner<*>::symbol)
for (name in superTypesCallableNames) {
@@ -39842,6 +39842,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
runTest("compiler/testData/codegen/box/traits/receiverOfIntersectionType.kt");
}
@Test
@TestMetadata("sameNameMethodFromInterface.kt")
public void testSameNameMethodFromInterface() throws Exception {
runTest("compiler/testData/codegen/box/traits/sameNameMethodFromInterface.kt");
}
@Test
@TestMetadata("syntheticAccessor.kt")
public void testSyntheticAccessor() throws Exception {
@@ -0,0 +1,9 @@
interface A<T> {
fun foo(t: T): T = t
}
class B : A<String> {
private fun foo() {}
}
fun box(): String = B().foo("OK")
@@ -39824,6 +39824,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTest("compiler/testData/codegen/box/traits/receiverOfIntersectionType.kt");
}
@Test
@TestMetadata("sameNameMethodFromInterface.kt")
public void testSameNameMethodFromInterface() throws Exception {
runTest("compiler/testData/codegen/box/traits/sameNameMethodFromInterface.kt");
}
@Test
@TestMetadata("syntheticAccessor.kt")
public void testSyntheticAccessor() throws Exception {
@@ -39842,6 +39842,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTest("compiler/testData/codegen/box/traits/receiverOfIntersectionType.kt");
}
@Test
@TestMetadata("sameNameMethodFromInterface.kt")
public void testSameNameMethodFromInterface() throws Exception {
runTest("compiler/testData/codegen/box/traits/sameNameMethodFromInterface.kt");
}
@Test
@TestMetadata("syntheticAccessor.kt")
public void testSyntheticAccessor() throws Exception {
@@ -31936,6 +31936,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTest("compiler/testData/codegen/box/traits/receiverOfIntersectionType.kt");
}
@TestMetadata("sameNameMethodFromInterface.kt")
public void testSameNameMethodFromInterface() throws Exception {
runTest("compiler/testData/codegen/box/traits/sameNameMethodFromInterface.kt");
}
@TestMetadata("syntheticAccessor.kt")
public void testSyntheticAccessor() throws Exception {
runTest("compiler/testData/codegen/box/traits/syntheticAccessor.kt");
@@ -26881,6 +26881,11 @@ public class IrJsCodegenBoxES6TestGenerated extends AbstractIrJsCodegenBoxES6Tes
runTest("compiler/testData/codegen/box/traits/receiverOfIntersectionType.kt");
}
@TestMetadata("sameNameMethodFromInterface.kt")
public void testSameNameMethodFromInterface() throws Exception {
runTest("compiler/testData/codegen/box/traits/sameNameMethodFromInterface.kt");
}
@TestMetadata("syntheticAccessor.kt")
public void testSyntheticAccessor() throws Exception {
runTest("compiler/testData/codegen/box/traits/syntheticAccessor.kt");
@@ -26302,6 +26302,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/traits/receiverOfIntersectionType.kt");
}
@TestMetadata("sameNameMethodFromInterface.kt")
public void testSameNameMethodFromInterface() throws Exception {
runTest("compiler/testData/codegen/box/traits/sameNameMethodFromInterface.kt");
}
@TestMetadata("syntheticAccessor.kt")
public void testSyntheticAccessor() throws Exception {
runTest("compiler/testData/codegen/box/traits/syntheticAccessor.kt");
@@ -26262,6 +26262,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/traits/receiverOfIntersectionType.kt");
}
@TestMetadata("sameNameMethodFromInterface.kt")
public void testSameNameMethodFromInterface() throws Exception {
runTest("compiler/testData/codegen/box/traits/sameNameMethodFromInterface.kt");
}
@TestMetadata("syntheticAccessor.kt")
public void testSyntheticAccessor() throws Exception {
runTest("compiler/testData/codegen/box/traits/syntheticAccessor.kt");
@@ -14661,6 +14661,11 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest
runTest("compiler/testData/codegen/box/traits/receiverOfIntersectionType.kt");
}
@TestMetadata("sameNameMethodFromInterface.kt")
public void testSameNameMethodFromInterface() throws Exception {
runTest("compiler/testData/codegen/box/traits/sameNameMethodFromInterface.kt");
}
@TestMetadata("syntheticAccessor.kt")
public void testSyntheticAccessor() throws Exception {
runTest("compiler/testData/codegen/box/traits/syntheticAccessor.kt");