K2: Fix false positive NotImplemented error for size property

The problem appeared because not all of the `realOverridden` have been
collected because inside AbstractSerializableListDecorator some of the
scopes returned the same instance as direct overridden and after that
overridden tree traversal stopped without detecting real overrides.

Thus, the modality of intersection for
AbstractSerializableListDecorator::size and MutableSet::size
was incorrectly computed to ABSTRACT

The similar thing is already done at the place where we're obtaining
all overrides.
See https://github.com/JetBrains/kotlin/commit/c80cfb0fdb00323ba9b5e1dd98c5cbd0bfab6b8b#diff-182d90c9b8050557e4e2eb319a84b9a51fd0600c728dd0fce85cf6491c13e16dR152

^KT-57693 Fixed
This commit is contained in:
Denis.Zharkov
2023-04-18 14:21:57 +02:00
committed by Space Team
parent 6544220b3e
commit 4e2107abe7
7 changed files with 118 additions and 3 deletions
@@ -20319,6 +20319,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia
runTest("compiler/testData/diagnostics/tests/j+k/specialBuiltIns/hashtableInheritance.kt");
}
@Test
@TestMetadata("inheritanceThroughEmptyClass.kt")
public void testInheritanceThroughEmptyClass() throws Exception {
runTest("compiler/testData/diagnostics/tests/j+k/specialBuiltIns/inheritanceThroughEmptyClass.kt");
}
@Test
@TestMetadata("securityProvider.kt")
public void testSecurityProvider() throws Exception {
@@ -20319,6 +20319,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated
runTest("compiler/testData/diagnostics/tests/j+k/specialBuiltIns/hashtableInheritance.kt");
}
@Test
@TestMetadata("inheritanceThroughEmptyClass.kt")
public void testInheritanceThroughEmptyClass() throws Exception {
runTest("compiler/testData/diagnostics/tests/j+k/specialBuiltIns/inheritanceThroughEmptyClass.kt");
}
@Test
@TestMetadata("securityProvider.kt")
public void testSecurityProvider() throws Exception {
@@ -20319,6 +20319,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir
runTest("compiler/testData/diagnostics/tests/j+k/specialBuiltIns/hashtableInheritance.kt");
}
@Test
@TestMetadata("inheritanceThroughEmptyClass.kt")
public void testInheritanceThroughEmptyClass() throws Exception {
runTest("compiler/testData/diagnostics/tests/j+k/specialBuiltIns/inheritanceThroughEmptyClass.kt");
}
@Test
@TestMetadata("securityProvider.kt")
public void testSecurityProvider() throws Exception {
@@ -20325,6 +20325,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia
runTest("compiler/testData/diagnostics/tests/j+k/specialBuiltIns/hashtableInheritance.kt");
}
@Test
@TestMetadata("inheritanceThroughEmptyClass.kt")
public void testInheritanceThroughEmptyClass() throws Exception {
runTest("compiler/testData/diagnostics/tests/j+k/specialBuiltIns/inheritanceThroughEmptyClass.kt");
}
@Test
@TestMetadata("securityProvider.kt")
public void testSecurityProvider() throws Exception {
@@ -10,7 +10,6 @@ import org.jetbrains.kotlin.descriptors.Visibilities
import org.jetbrains.kotlin.descriptors.Visibility
import org.jetbrains.kotlin.fir.*
import org.jetbrains.kotlin.fir.caches.*
import org.jetbrains.kotlin.fir.declarations.FirCallableDeclaration
import org.jetbrains.kotlin.fir.declarations.FirDeclarationOrigin
import org.jetbrains.kotlin.fir.declarations.FirMemberDeclaration
import org.jetbrains.kotlin.fir.declarations.FirVariable
@@ -310,10 +309,12 @@ class FirTypeIntersectionScopeContext(
symbol: D,
scope: FirTypeScope,
result: MutableCollection<MemberWithBaseScope<D>>,
visited: MutableSet<D>,
// There's no guarantee that directOverridden(symbol) is strictly different
// It might be the same instance that when being requested with a different/new scope would return next level of overridden
visited: MutableSet<Pair<FirTypeScope, D>>,
processDirectOverridden: FirTypeScope.(D, (D, FirTypeScope) -> ProcessorAction) -> ProcessorAction,
) {
if (!visited.add(symbol)) return
if (!visited.add(scope to symbol)) return
if (!symbol.fir.origin.fromSupertypes) {
result.add(MemberWithBaseScope(symbol, scope))
return
@@ -0,0 +1,84 @@
// FIR_IDENTICAL
// FULL_JDK
// ISSUE: KT-57693
// FILE: AbstractCollectionDecorator.java
import java.util.Collection;
import java.util.Iterator;
import java.util.function.Predicate;
public abstract class AbstractCollectionDecorator<E> implements Collection<E> {
protected Collection<E> decorated() {
return null;
}
public boolean add(E object) {
return this.decorated().add(object);
}
public boolean addAll(Collection<? extends E> coll) {
return this.decorated().addAll(coll);
}
public void clear() {
this.decorated().clear();
}
public boolean contains(Object object) {
return this.decorated().contains(object);
}
public boolean isEmpty() {
return this.decorated().isEmpty();
}
public Iterator<E> iterator() {
return this.decorated().iterator();
}
public boolean remove(Object object) {
return this.decorated().remove(object);
}
public int size() {
return this.decorated().size();
}
public Object[] toArray() {
return this.decorated().toArray();
}
public <T> T[] toArray(T[] object) {
return this.decorated().toArray(object);
}
public boolean containsAll(Collection<?> coll) {
return this.decorated().containsAll(coll);
}
public boolean removeIf(Predicate<? super E> filter) {
return this.decorated().removeIf(filter);
}
public boolean removeAll(Collection<?> coll) {
return this.decorated().removeAll(coll);
}
public boolean retainAll(Collection<?> coll) {
return this.decorated().retainAll(coll);
}
public String toString() {
return this.decorated().toString();
}
}
// FILE: AbstractSerializableListDecorator.java
public abstract class AbstractSerializableListDecorator<E> extends AbstractCollectionDecorator<E> {
}
// FILE: main.kt
import java.util.*
class UniqueArrayList<E> : AbstractSerializableListDecorator<E>(), MutableSet<E>
@@ -20325,6 +20325,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
runTest("compiler/testData/diagnostics/tests/j+k/specialBuiltIns/hashtableInheritance.kt");
}
@Test
@TestMetadata("inheritanceThroughEmptyClass.kt")
public void testInheritanceThroughEmptyClass() throws Exception {
runTest("compiler/testData/diagnostics/tests/j+k/specialBuiltIns/inheritanceThroughEmptyClass.kt");
}
@Test
@TestMetadata("securityProvider.kt")
public void testSecurityProvider() throws Exception {