[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))
}
@@ -28,11 +28,11 @@ FILE: delegateWithAnonymousObject.kt
super<R|kotlin/Any|>()
}
public final override fun getValue(thisRef: R|IssuesListUserProfile|, property: R|kotlin/reflect/KProperty<*>|): R|IssueListView| {
public final override operator fun getValue(thisRef: R|IssuesListUserProfile|, property: R|kotlin/reflect/KProperty<*>|): R|IssueListView| {
^getValue R|/IssueListView.IssueListView|()
}
public final override fun setValue(thisRef: R|IssuesListUserProfile|, property: R|kotlin/reflect/KProperty<*>|, value: R|IssueListView|): R|kotlin/Unit| {
public final override operator fun setValue(thisRef: R|IssuesListUserProfile|, property: R|kotlin/reflect/KProperty<*>|, value: R|IssueListView|): R|kotlin/Unit| {
^setValue R|/IssueListView.IssueListView|().R|/IssueListView.updateFrom|(R|<local>/value|)
}
@@ -14,7 +14,7 @@ FILE: functionX.kt
super<R|kotlin/Any|>()
}
public final override fun invoke(p1: R|kotlin/Int|, p2: R|kotlin/String|): R|kotlin/Unit| {
public final override operator fun invoke(p1: R|kotlin/Int|, p2: R|kotlin/String|): R|kotlin/Unit| {
}
}
@@ -8,7 +8,7 @@ FILE: smartSet.kt
public get(): R|kotlin/Int|
public set(value: R|kotlin/Int|): R|kotlin/Unit|
public final override fun iterator(): R|kotlin/collections/MutableIterator<T>| {
public final override operator fun iterator(): R|kotlin/collections/MutableIterator<T>| {
^iterator R|kotlin/TODO|()
}
@@ -373,6 +373,11 @@ public class FirDiagnosticsTestGenerated extends AbstractFirDiagnosticsTest {
runTest("compiler/fir/analysis-tests/testData/resolve/spreadOperator.kt");
}
@TestMetadata("statusResolveForTypealiasAsSuperClass.kt")
public void testStatusResolveForTypealiasAsSuperClass() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/statusResolveForTypealiasAsSuperClass.kt");
}
@TestMetadata("syntheticsVsNormalProperties.kt")
public void testSyntheticsVsNormalProperties() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/syntheticsVsNormalProperties.kt");
@@ -2661,6 +2666,16 @@ public class FirDiagnosticsTestGenerated extends AbstractFirDiagnosticsTest {
runTest("compiler/fir/analysis-tests/testData/resolve/visibility/exposedTypeParameters.kt");
}
@TestMetadata("intersectionOverrideWithImplicitTypes.kt")
public void testIntersectionOverrideWithImplicitTypes() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/visibility/intersectionOverrideWithImplicitTypes.kt");
}
@TestMetadata("kotlinJavaKotlinHierarchy.kt")
public void testKotlinJavaKotlinHierarchy() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/visibility/kotlinJavaKotlinHierarchy.kt");
}
@TestMetadata("protectedInCompanion.kt")
public void testProtectedInCompanion() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/visibility/protectedInCompanion.kt");
@@ -2670,5 +2685,10 @@ public class FirDiagnosticsTestGenerated extends AbstractFirDiagnosticsTest {
public void testSingletonConstructors() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/visibility/singletonConstructors.kt");
}
@TestMetadata("visibilityWithOverrides.kt")
public void testVisibilityWithOverrides() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/visibility/visibilityWithOverrides.kt");
}
}
}
@@ -373,6 +373,11 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
runTest("compiler/fir/analysis-tests/testData/resolve/spreadOperator.kt");
}
@TestMetadata("statusResolveForTypealiasAsSuperClass.kt")
public void testStatusResolveForTypealiasAsSuperClass() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/statusResolveForTypealiasAsSuperClass.kt");
}
@TestMetadata("syntheticsVsNormalProperties.kt")
public void testSyntheticsVsNormalProperties() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/syntheticsVsNormalProperties.kt");
@@ -2661,6 +2666,16 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
runTest("compiler/fir/analysis-tests/testData/resolve/visibility/exposedTypeParameters.kt");
}
@TestMetadata("intersectionOverrideWithImplicitTypes.kt")
public void testIntersectionOverrideWithImplicitTypes() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/visibility/intersectionOverrideWithImplicitTypes.kt");
}
@TestMetadata("kotlinJavaKotlinHierarchy.kt")
public void testKotlinJavaKotlinHierarchy() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/visibility/kotlinJavaKotlinHierarchy.kt");
}
@TestMetadata("protectedInCompanion.kt")
public void testProtectedInCompanion() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/visibility/protectedInCompanion.kt");
@@ -2670,5 +2685,10 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
public void testSingletonConstructors() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/visibility/singletonConstructors.kt");
}
@TestMetadata("visibilityWithOverrides.kt")
public void testVisibilityWithOverrides() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/visibility/visibilityWithOverrides.kt");
}
}
}
@@ -373,6 +373,11 @@ public class LazyBodyIsNotTouchedTilContractsPhaseTestGenerated extends Abstract
runTest("compiler/fir/analysis-tests/testData/resolve/spreadOperator.kt");
}
@TestMetadata("statusResolveForTypealiasAsSuperClass.kt")
public void testStatusResolveForTypealiasAsSuperClass() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/statusResolveForTypealiasAsSuperClass.kt");
}
@TestMetadata("syntheticsVsNormalProperties.kt")
public void testSyntheticsVsNormalProperties() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/syntheticsVsNormalProperties.kt");
@@ -2661,6 +2666,16 @@ public class LazyBodyIsNotTouchedTilContractsPhaseTestGenerated extends Abstract
runTest("compiler/fir/analysis-tests/testData/resolve/visibility/exposedTypeParameters.kt");
}
@TestMetadata("intersectionOverrideWithImplicitTypes.kt")
public void testIntersectionOverrideWithImplicitTypes() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/visibility/intersectionOverrideWithImplicitTypes.kt");
}
@TestMetadata("kotlinJavaKotlinHierarchy.kt")
public void testKotlinJavaKotlinHierarchy() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/visibility/kotlinJavaKotlinHierarchy.kt");
}
@TestMetadata("protectedInCompanion.kt")
public void testProtectedInCompanion() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/visibility/protectedInCompanion.kt");
@@ -2670,5 +2685,10 @@ public class LazyBodyIsNotTouchedTilContractsPhaseTestGenerated extends Abstract
public void testSingletonConstructors() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/visibility/singletonConstructors.kt");
}
@TestMetadata("visibilityWithOverrides.kt")
public void testVisibilityWithOverrides() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/visibility/visibilityWithOverrides.kt");
}
}
}