[FIR] Rework resolution of declaration statuses

There is introduced algorithm of resolution with jumps: before
  resolution of some class we resolve all status of members of its
  supertypes, so we can properly determine inherited visibility
  and modifiers
This commit is contained in:
Dmitriy Novozhilov
2020-09-28 15:30:51 +03:00
parent 0b8116dff0
commit bf1a00c73a
35 changed files with 858 additions and 180 deletions
@@ -15,5 +15,5 @@ class B : A() {
}
fun test(b: B) {
b.foo("")
}
b.<!HIDDEN!>foo<!>("")
}
@@ -4,11 +4,11 @@ FILE: main.kt
super<R|A|>()
}
public final override fun foo(s: R|kotlin/String|): R|kotlin/Any?| {
protected final override fun foo(s: R|kotlin/String|): R|kotlin/Any?| {
^foo Null(null)
}
}
public final fun test(b: R|B|): R|kotlin/Unit| {
R|<local>/b|.R|/B.foo|(String())
R|<local>/b|.<HIDDEN: /B.foo is invisible>#(String())
}
@@ -6,7 +6,7 @@ FILE: superAny.kt
super<R|kotlin/Any|>()
}
public open override fun equals(other: R|kotlin/Any?|): R|kotlin/Boolean| {
public open override operator fun equals(other: R|kotlin/Any?|): R|kotlin/Boolean| {
^equals this@R|/B|.super<R|kotlin/Any|>.R|kotlin/Any.equals|(R|<local>/other|)
}
@@ -20,7 +20,7 @@ FILE: superAny.kt
super<R|B|>()
}
public final override fun equals(other: R|kotlin/Any?|): R|kotlin/Boolean| {
public final override operator fun equals(other: R|kotlin/Any?|): R|kotlin/Boolean| {
^equals this@R|/C|.super<R|B|>.R|/B.equals|(R|<local>/other|)
}
@@ -4,7 +4,7 @@ FILE: methodOfAnyImplementedInInterface.kt
^toString String(Hello)
}
public open override fun equals(other: R|kotlin/Any?|): R|kotlin/Boolean| {
public open override operator fun equals(other: R|kotlin/Any?|): R|kotlin/Boolean| {
^equals Boolean(true)
}
@@ -16,7 +16,7 @@ FILE: methodOfAnyImplementedInInterface.kt
public abstract interface B : R|kotlin/Any| {
public abstract override fun toString(): R|kotlin/String|
public abstract override fun equals(other: R|kotlin/Any?|): R|kotlin/Boolean|
public abstract override operator fun equals(other: R|kotlin/Any?|): R|kotlin/Boolean|
public abstract override fun hashCode(): R|kotlin/Int|
@@ -100,7 +100,7 @@ FILE: protectedVisibility.kt
super<R|Generic<kotlin/Int>|>(Int(1))
}
public final override fun foo(): R|kotlin/Int| {
protected final override fun foo(): R|kotlin/Int| {
^foo this@R|/DerivedGeneric|.super<R|Generic<kotlin/Int>|>.R|FakeOverride</Generic.foo: R|kotlin/Int|>|()
}
@@ -18,11 +18,11 @@ FILE: typeParameters.kt
super<R|AbstractList<kotlin/Int>|>()
}
public final override fun get(index: R|kotlin/Int|): R|kotlin/Int| {
public final override operator fun get(index: R|kotlin/Int|): R|kotlin/Int| {
^get Int(42)
}
public final override fun concat(other: R|List<kotlin/Int>|): R|List<kotlin/Int>| {
public final override infix fun concat(other: R|List<kotlin/Int>|): R|List<kotlin/Int>| {
^concat this@R|/SomeList|
}
@@ -0,0 +1,13 @@
class A : Foo {
override fun foo() {}
}
typealias Foo = B
interface B {
fun foo() {}
}
fun test(c: A) {
c.foo()
}
@@ -0,0 +1,19 @@
FILE: statusResolveForTypealiasAsSuperClass.kt
public final class A : R|Foo| {
public constructor(): R|A| {
super<R|kotlin/Any|>()
}
public final override fun foo(): R|kotlin/Unit| {
}
}
public final typealias Foo = R|B|
public abstract interface B : R|kotlin/Any| {
public open fun foo(): R|kotlin/Unit| {
}
}
public final fun test(c: R|A|): R|kotlin/Unit| {
R|<local>/c|.R|/A.foo|()
}
@@ -0,0 +1,15 @@
interface Common {
fun <T, R> foo(value: T, producer: (T) -> R): R
}
class C : B, A {
override fun <T, R> foo(value: T, producer: (T) -> R): R = null!!
}
interface A : Common {
override fun <T, R> foo(value: T, producer: (T) -> R): R = null!!
}
interface B : Common {
override fun <T, R> foo(value: T, producer: (T) -> R) = producer(value)
}
@@ -0,0 +1,27 @@
FILE: intersectionOverrideWithImplicitTypes.kt
public abstract interface Common : R|kotlin/Any| {
public abstract fun <T, R> foo(value: R|T|, producer: R|(T) -> R|): R|R|
}
public final class C : R|B|, R|A| {
public constructor(): R|C| {
super<R|kotlin/Any|>()
}
public final override fun <T, R> foo(value: R|T|, producer: R|(T) -> R|): R|R| {
^foo Null(null)!!
}
}
public abstract interface A : R|Common| {
public open override fun <T, R> foo(value: R|T|, producer: R|(T) -> R|): R|R| {
^foo Null(null)!!
}
}
public abstract interface B : R|Common| {
public open override fun <T, R> foo(value: R|T|, producer: R|(T) -> R|): R|R| {
^foo R|<local>/producer|.R|FakeOverride<kotlin/Function1.invoke: R|R|>|(R|<local>/value|)
}
}
@@ -0,0 +1,18 @@
// FILE: C.kt
class C : B() {
override fun foo() {}
}
// FILE: B.java
public class B extends A {
@java.lang.Override
public void foo() {}
}
// FILE: A.kt
abstract class A {
abstract fun foo()
}
@@ -0,0 +1,19 @@
FILE: C.kt
public final class C : R|B| {
public constructor(): R|C| {
super<R|B|>()
}
public final override fun foo(): R|kotlin/Unit| {
}
}
FILE: A.kt
public abstract class A : R|kotlin/Any| {
public constructor(): R|A| {
super<R|kotlin/Any|>()
}
public abstract fun foo(): R|kotlin/Unit|
}
@@ -0,0 +1,23 @@
// ISSUE: KT-38656
// FILE: B.kt
class B : A() {
override fun foo(s: String): String = ""
fun testProtected(): String {
return this foo "hello"
}
}
// FILE: A.kt
abstract class A {
protected abstract infix fun foo(s: String): String
}
// FILE: main.kt
fun test(b: B): String {
return b <!HIDDEN!>foo<!> "hello" // should be an error
}
@@ -0,0 +1,28 @@
FILE: B.kt
public final class B : R|A| {
public constructor(): R|B| {
super<R|A|>()
}
protected final override infix fun foo(s: R|kotlin/String|): R|kotlin/String| {
^foo String()
}
public final fun testProtected(): R|kotlin/String| {
^testProtected this@R|/B|.R|/B.foo|(String(hello))
}
}
FILE: A.kt
public abstract class A : R|kotlin/Any| {
public constructor(): R|A| {
super<R|kotlin/Any|>()
}
protected abstract infix fun foo(s: R|kotlin/String|): R|kotlin/String|
}
FILE: main.kt
public final fun test(b: R|B|): R|kotlin/String| {
^test R|<local>/b|.<HIDDEN: /B.foo is invisible>#(String(hello))
}