[FIR] Prevent duplicate direct overridden-s from substitution overrides

This change prevents going up the scopes once we find a
substitution override. Whatever we'd find by going further is not
going to be a direct overridden anymore, so it would lead to incorrect
results when collecting direct overridden-s. Without this change, we get
error modules in FT intellij.
This commit is contained in:
Nikolay Lunyak
2023-07-28 16:31:59 +03:00
committed by Space Team
parent 61448531cb
commit 97b00793b4
8 changed files with 53 additions and 11 deletions
@@ -24326,6 +24326,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia
runTest("compiler/testData/diagnostics/tests/override/MultipleDefaultParametersInSupertypesNoOverride.kt");
}
@Test
@TestMetadata("MultipleDefaultParametersInSupertypesWithOverloads.kt")
public void testMultipleDefaultParametersInSupertypesWithOverloads() throws Exception {
runTest("compiler/testData/diagnostics/tests/override/MultipleDefaultParametersInSupertypesWithOverloads.kt");
}
@Test
@TestMetadata("MultipleDefaultsAndNamesInSupertypes.kt")
public void testMultipleDefaultsAndNamesInSupertypes() throws Exception {
@@ -24326,6 +24326,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated
runTest("compiler/testData/diagnostics/tests/override/MultipleDefaultParametersInSupertypesNoOverride.kt");
}
@Test
@TestMetadata("MultipleDefaultParametersInSupertypesWithOverloads.kt")
public void testMultipleDefaultParametersInSupertypesWithOverloads() throws Exception {
runTest("compiler/testData/diagnostics/tests/override/MultipleDefaultParametersInSupertypesWithOverloads.kt");
}
@Test
@TestMetadata("MultipleDefaultsAndNamesInSupertypes.kt")
public void testMultipleDefaultsAndNamesInSupertypes() throws Exception {
@@ -3,25 +3,20 @@ SomeMap:
[SubstitutionOverride(DeclarationSite)]: public abstract fun containsKey(key: R|ft<K3 & Any, K3?>|): R|kotlin/Boolean| from Substitution scope for [Use site scope of kotlin/collections/MutableMap] for type SomeMap<K3, V3> [id: 1]
[SubstitutionOverride(DeclarationSite)]: public abstract fun containsKey(key: R|K|): R|kotlin/Boolean| from Use site scope of kotlin/collections/MutableMap [id: 2]
[Library]: public abstract fun containsKey(key: R|K|): R|kotlin/Boolean| from Use site scope of kotlin/collections/Map [id: 3]
[Library]: public abstract fun containsKey(key: R|K|): R|kotlin/Boolean| from Use site scope of kotlin/collections/Map [id: 3]
[SubstitutionOverride(DeclarationSite)]: public abstract fun containsKey(key: R|kotlin/Any!|): R|kotlin/Boolean| from Substitution scope for [Java enhancement scope for /MyMap] for type SomeMap<K3, V3> [id: 4]
[Enhancement]: public abstract fun containsKey(key: R|kotlin/Any!|): R|kotlin/Boolean| from Java enhancement scope for /MyMap [id: 5]
[SubstitutionOverride(DeclarationSite)]: public abstract fun containsKey(key: R|kotlin/Any!|): R|kotlin/Boolean| from Substitution scope for [Java enhancement scope for /MyBaseMap] for type MyMap<K2, V2> [id: 6]
[Enhancement]: public abstract fun containsKey(key: R|kotlin/Any!|): R|kotlin/Boolean| from Java enhancement scope for /MyBaseMap [id: 7]
[SubstitutionOverride(DeclarationSite)]: public abstract fun containsKey(key: R|kotlin/Any!|): R|kotlin/Boolean| from Substitution scope for [Java enhancement scope for /MyBaseMap] for type MyMap<K2, V2> [id: 6]
[Enhancement]: public abstract fun containsKey(key: R|kotlin/Any!|): R|kotlin/Boolean| from Java enhancement scope for /MyBaseMap [id: 7]
[IntersectionOverride]: public abstract fun containsValue(value: R|ft<V3 & Any, V3?>|): R|kotlin/Boolean| from Java enhancement scope for /SomeMap [id: 0]
[SubstitutionOverride(DeclarationSite)]: public abstract fun containsValue(value: R|ft<V3 & Any, V3?>|): R|kotlin/Boolean| from Substitution scope for [Use site scope of kotlin/collections/MutableMap] for type SomeMap<K3, V3> [id: 1]
[SubstitutionOverride(DeclarationSite)]: public abstract fun containsValue(value: R|V|): R|kotlin/Boolean| from Use site scope of kotlin/collections/MutableMap [id: 2]
[Library]: public abstract fun containsValue(value: R|V|): R|kotlin/Boolean| from Use site scope of kotlin/collections/Map [id: 3]
[Library]: public abstract fun containsValue(value: R|V|): R|kotlin/Boolean| from Use site scope of kotlin/collections/Map [id: 3]
[SubstitutionOverride(DeclarationSite)]: public abstract fun containsValue(key: R|kotlin/Any!|): R|kotlin/Boolean| from Substitution scope for [Java enhancement scope for /MyMap] for type SomeMap<K3, V3> [id: 4]
[Enhancement]: public abstract fun containsValue(key: R|kotlin/Any!|): R|kotlin/Boolean| from Java enhancement scope for /MyMap [id: 5]
[IntersectionOverride]: public abstract operator fun get(key: R|ft<K3 & Any, K3?>|): R|V3?| from Java enhancement scope for /SomeMap [id: 0]
[SubstitutionOverride(DeclarationSite)]: public abstract operator fun get(key: R|ft<K3 & Any, K3?>|): R|V3?| from Substitution scope for [Use site scope of kotlin/collections/MutableMap] for type SomeMap<K3, V3> [id: 1]
[SubstitutionOverride(DeclarationSite)]: public abstract operator fun get(key: R|K|): R|V?| from Use site scope of kotlin/collections/MutableMap [id: 2]
[Library]: public abstract operator fun get(key: R|K|): R|V?| from Use site scope of kotlin/collections/Map [id: 3]
[Library]: public abstract operator fun get(key: R|K|): R|V?| from Use site scope of kotlin/collections/Map [id: 3]
[SubstitutionOverride(DeclarationSite)]: public abstract operator fun get(key: R|ft<K3 & Any, K3?>|): R|ft<V3 & Any, V3?>| from Substitution scope for [Java enhancement scope for /MyMap] for type SomeMap<K3, V3> [id: 4]
[Enhancement]: public abstract operator fun get(key: R|ft<K2 & Any, K2?>|): R|ft<V2 & Any, V2?>| from Java enhancement scope for /MyMap [id: 5]
[Enhancement]: public abstract fun remove(key: R|ft<K3 & Any, K3?>|): R|V3?| from Java enhancement scope for /SomeMap [id: 0]
@@ -24326,6 +24326,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir
runTest("compiler/testData/diagnostics/tests/override/MultipleDefaultParametersInSupertypesNoOverride.kt");
}
@Test
@TestMetadata("MultipleDefaultParametersInSupertypesWithOverloads.kt")
public void testMultipleDefaultParametersInSupertypesWithOverloads() throws Exception {
runTest("compiler/testData/diagnostics/tests/override/MultipleDefaultParametersInSupertypesWithOverloads.kt");
}
@Test
@TestMetadata("MultipleDefaultsAndNamesInSupertypes.kt")
public void testMultipleDefaultsAndNamesInSupertypes() throws Exception {
@@ -24332,6 +24332,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia
runTest("compiler/testData/diagnostics/tests/override/MultipleDefaultParametersInSupertypesNoOverride.kt");
}
@Test
@TestMetadata("MultipleDefaultParametersInSupertypesWithOverloads.kt")
public void testMultipleDefaultParametersInSupertypesWithOverloads() throws Exception {
runTest("compiler/testData/diagnostics/tests/override/MultipleDefaultParametersInSupertypesWithOverloads.kt");
}
@Test
@TestMetadata("MultipleDefaultsAndNamesInSupertypes.kt")
public void testMultipleDefaultsAndNamesInSupertypes() throws Exception {
@@ -69,14 +69,17 @@ class FirClassSubstitutionScope(
processDirectOverriddenCallablesWithBaseScope: FirTypeScope.(D, ((D, FirTypeScope) -> ProcessorAction)) -> ProcessorAction,
originalInCache: (D) -> Boolean
): ProcessorAction {
val original = callableSymbol.originalForSubstitutionOverride?.takeIf { originalInCache(it) }
?: return useSiteMemberScope.processDirectOverriddenCallablesWithBaseScope(callableSymbol, processor)
val original = callableSymbol.originalForSubstitutionOverride
if (original != callableSymbol) {
if (!processor(original, useSiteMemberScope)) return ProcessorAction.STOP
return when {
original == null || !originalInCache(original) -> {
useSiteMemberScope.processDirectOverriddenCallablesWithBaseScope(callableSymbol, processor)
}
else -> when {
!processor(original, useSiteMemberScope) -> ProcessorAction.STOP
else -> ProcessorAction.NONE
}
}
return useSiteMemberScope.processDirectOverriddenCallablesWithBaseScope(original, processor)
}
override fun processPropertiesByName(name: Name, processor: (FirVariableSymbol<*>) -> Unit) {
@@ -0,0 +1,14 @@
// FIR_IDENTICAL
interface Foo<T> {
fun foo() {}
fun foo(param: Int = 1) {}
}
open class Test<K> : Foo<K> {
override fun foo() {}
}
open class Rest<R> : Test<R>(), Foo<R>
class Baz : Rest<Int>() {}
@@ -25376,6 +25376,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
runTest("compiler/testData/diagnostics/tests/override/MultipleDefaultParametersInSupertypesNoOverride.kt");
}
@Test
@TestMetadata("MultipleDefaultParametersInSupertypesWithOverloads.kt")
public void testMultipleDefaultParametersInSupertypesWithOverloads() throws Exception {
runTest("compiler/testData/diagnostics/tests/override/MultipleDefaultParametersInSupertypesWithOverloads.kt");
}
@Test
@TestMetadata("MultipleDefaultsAndNamesInSupertypes.kt")
public void testMultipleDefaultsAndNamesInSupertypes() throws Exception {