[FIR] Replace single supertype scope with list of scopes of supertypes in use site scopes

This big refactoring is needed to cleanup building of overrides
  mappings and prevent creating redundant intersection overrides in
  cases when there is no need in them:

```kotlin
interface A {
    fun foo()
}

interface B {
    fun foo()
}

interface C : A, B {
    override fun foo()
}
```

Before this refactoring there was next override tree:
C.foo
  intersection override (A.foo, B.foo)
    A.foo
    B.foo

Also this commit fixes special mapping of overrides in jvm scopes
  for declarations which have kotlin builtins in supertypes with
  special java mapping rules (collections, for example)
This commit is contained in:
Dmitriy Novozhilov
2022-01-13 18:22:42 +03:00
parent 17916d4a63
commit c80cfb0fdb
82 changed files with 2564 additions and 636 deletions
@@ -1,85 +0,0 @@
// FILE: CollectionStringImpl.java
import java.util.Collection;
import java.util.Iterator;
public class CollectionStringImpl implements Collection<String> {
@Override
public int size() {
return 0;
}
@Override
public boolean isEmpty() {
return false;
}
@Override
public boolean contains(Object o) {
return false;
}
@Override
public Iterator<String> iterator() {
return null;
}
@Override
public Object[] toArray() {
return new Object[0];
}
@Override
public <T> T[] toArray(T[] a) {
return null;
}
@Override
public boolean add(String s) {
return false;
}
@Override
public boolean remove(Object o) {
return false;
}
@Override
public boolean containsAll(Collection<?> c) {
return false;
}
@Override
public boolean addAll(Collection<? extends String> c) {
return false;
}
@Override
public boolean removeAll(Collection<?> c) {
return false;
}
@Override
public boolean retainAll(Collection<?> c) {
return false;
}
@Override
public void clear() {
}
public boolean contains(String o) {
return true;
}
}
// FILE: main.kt
fun test(x: CollectionStringImpl) {
x.<!OVERLOAD_RESOLUTION_AMBIGUITY!>contains<!>("")
(x as Collection<String>).contains("")
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// FILE: CollectionStringImpl.java
import java.util.Collection;
@@ -12,10 +12,10 @@ abstract class KA : A() {
}
fun foo(a: A, ka: KA) {
a.<!OVERLOAD_RESOLUTION_AMBIGUITY!>contains<!>("")
a.<!NONE_APPLICABLE!>contains<!>(1)
"" <!OVERLOAD_RESOLUTION_AMBIGUITY!>in<!> a
1 <!NONE_APPLICABLE!>in<!> a
a.contains("")
a.contains(<!ARGUMENT_TYPE_MISMATCH!>1<!>)
"" in a
<!ARGUMENT_TYPE_MISMATCH!>1<!> in a
ka.contains("")
ka.contains(<!ARGUMENT_TYPE_MISMATCH!>1<!>)
@@ -1,25 +0,0 @@
// FILE: AImpl.java
abstract public class AImpl {
public char charAt(int index) {
return '1';
}
public final int length() { return 1; }
}
// FILE: A.java
public class A extends AImpl implements CharSequence {
public CharSequence subSequence(int start, int end) {
return null;
}
}
// FILE: X.kt
<!ABSTRACT_MEMBER_NOT_IMPLEMENTED!>class X<!> : A()
fun main() {
val x = X()
x[0]
x.length
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// FILE: AImpl.java
abstract public class AImpl {
@@ -0,0 +1,16 @@
interface A {
fun foo() {}
}
interface B : A {
abstract override fun foo()
}
interface C : A {
abstract override fun foo()
}
interface D : A
// Fake override Z#foo should be abstract
<!MANY_INTERFACES_MEMBER_NOT_IMPLEMENTED!>class Z<!> : B, C, D
@@ -1,4 +1,3 @@
// FIR_IDENTICAL
interface A {
fun foo() {}
}
+1 -1
View File
@@ -10,7 +10,7 @@ interface T {
}
class G : C(), T {
override fun foo() {} //should be an error "cannot infer visibility"; for now 'public' is inferred in such cases
override fun <!CANNOT_CHANGE_ACCESS_PRIVILEGE!>foo<!>() {} //should be an error "cannot infer visibility"; for now 'public' is inferred in such cases
}
open class A {
@@ -0,0 +1,72 @@
// !JVM_DEFAULT_MODE: enable
// !JVM_TARGET: 1.8
// FILE: JavaInterface.java
public interface JavaInterface {
default void test() {}
default void testForNonDefault() {}
void testAbstract();
}
// FILE: 1.kt
interface KotlinInterface : JavaInterface {
@<!DEPRECATION!>JvmDefault<!>
override fun test() {}
<!NON_JVM_DEFAULT_OVERRIDES_JAVA_DEFAULT!>override fun testForNonDefault()<!> {}
override fun testAbstract() {}
}
interface KotlinInterface2 : JavaInterface, KotlinInterface {
@<!DEPRECATION!>JvmDefault<!>
override fun test() {}
<!NON_JVM_DEFAULT_OVERRIDES_JAVA_DEFAULT!>override fun testForNonDefault()<!> {}
override fun testAbstract() {}
}
interface KotlinInterfaceForIndirect : JavaInterface {
}
interface KotlinInterfaceIndirectInheritance : KotlinInterfaceForIndirect {
@<!DEPRECATION!>JvmDefault<!>
override fun test() {}
<!NON_JVM_DEFAULT_OVERRIDES_JAVA_DEFAULT!>override fun testForNonDefault()<!> {}
override fun testAbstract() {}
}
open class KotlinClass : JavaInterface {
override fun test() {}
override fun testForNonDefault() {}
override fun testAbstract() {}
}
interface KotlinInterfaceX {
fun test() {}
fun testForNonDefault() {}
fun testAbstract() {}
}
interface KotlinInterfaceManySuper: JavaInterface, KotlinInterfaceX {
@<!DEPRECATION!>JvmDefault<!>
override fun test() {}
<!NON_JVM_DEFAULT_OVERRIDES_JAVA_DEFAULT!>override fun testForNonDefault()<!> {}
override fun testAbstract() {}
}
@@ -1,4 +1,3 @@
// FIR_IDENTICAL
// !JVM_DEFAULT_MODE: enable
// !JVM_TARGET: 1.8