[FIR] Report all Visibilities.Unknown in FirOverrideChecker

Check all members for `Visibility.Unknown`,
otherwise we miss them when they come
from supertypes. This is the reason why
the FP intellij build failed with a
cryptic stacktrace instead of a
human-readable diagnostic.

Also, do report the diagnostic at all
cases of `Visibilities.Unknown`. Turns
out, there are no "simple to reason
about" situations here :(

Also, an interesting detail:
`retrieveDirectOverriddenOf` returns an
empty list for intersection overrides.
But this doesn't seem to break anything...

Replacing `CANNOT_INFER_VISIBILITY`'s
type `KtDeclaration` with
`PsiNameIdentifierOwner` and the related
changes in `PositioningStrategies`
were needed to prevent an exception saying that
`PsiClassImpl` is not a subtype of
`KtDeclaration`.
This commit is contained in:
Nikolay Lunyak
2024-02-20 14:20:22 +02:00
committed by Space Team
parent 053eb07692
commit 76ed5453b3
27 changed files with 149 additions and 46 deletions
@@ -45,4 +45,4 @@ interface GI : G {
}
<!MANY_IMPL_MEMBER_NOT_IMPLEMENTED("Class 'AG1'; a")!>class AG1<!>(val a: A, val g: G) : A by a, G by g
<!MANY_INTERFACES_MEMBER_NOT_IMPLEMENTED("Class 'AG2'; a")!>class AG2<!>() : AI, GI
<!CANNOT_INFER_VISIBILITY("a"), MANY_INTERFACES_MEMBER_NOT_IMPLEMENTED("Class 'AG2'; a")!>class AG2<!>() : AI, GI
@@ -0,0 +1,19 @@
// !DIAGNOSTICS: -CONFLICTING_JVM_DECLARATIONS
interface One {
public <!REDUNDANT_OPEN_IN_INTERFACE!>open<!> fun foo() : Int
private fun boo() = 10
}
interface Two {
public <!REDUNDANT_OPEN_IN_INTERFACE!>open<!> fun foo() : Int
}
interface OneImpl : One {
public override fun foo() = 1
}
interface TwoImpl : Two {
public override fun foo() = 2
}
<!CANNOT_INFER_VISIBILITY, MANY_INTERFACES_MEMBER_NOT_IMPLEMENTED!>class Test1<!>() : TwoImpl, OneImpl {}
class Test2(a : One) : One by a, Two {}
<!MANY_IMPL_MEMBER_NOT_IMPLEMENTED!>class Test3<!>(a : One, b : Two) : Two by b, One by a {}
@@ -1,4 +1,3 @@
// FIR_IDENTICAL
// !DIAGNOSTICS: -CONFLICTING_JVM_DECLARATIONS
interface One {
public <!REDUNDANT_OPEN_IN_INTERFACE!>open<!> fun foo() : Int
@@ -78,7 +78,7 @@ open class NWEH: NotDeprecated, WarningDeprecated, ErrorDeprecated, HiddenDeprec
class WE2: WE()
<!MANY_IMPL_MEMBER_NOT_IMPLEMENTED!>class NWE2<!>: WE(), NotDeprecated
<!CANNOT_INFER_VISIBILITY, MANY_IMPL_MEMBER_NOT_IMPLEMENTED!>class NWE2<!>: WE(), NotDeprecated
class NWE3: WE(), NotDeprecated {
override fun f() {
@@ -78,7 +78,7 @@ open class NWEH: NotDeprecated, WarningDeprecated, ErrorDeprecated, HiddenDeprec
class WE2: WE()
<!MANY_IMPL_MEMBER_NOT_IMPLEMENTED!>class NWE2<!>: WE(), NotDeprecated
<!CANNOT_INFER_VISIBILITY, MANY_IMPL_MEMBER_NOT_IMPLEMENTED!>class NWE2<!>: WE(), NotDeprecated
class NWE3: WE(), NotDeprecated {
override fun f() {
@@ -0,0 +1,34 @@
// TARGET_BACKEND: JVM
// FILE: IntCollection.java
interface IntCollection<E> {
public boolean add(int key);
}
// FILE: IntSet.java
interface IntSet extends IntCollection {
public default boolean add(Integer it) { return true; }
// from the supertype
// public boolean add(int key);
}
// FILE: AbstractCollection.java
abstract class AbstractCollection<E> {
public boolean add(E it) { return true; }
}
// FILE: AbstractIntCollection.java
abstract class AbstractIntCollection extends AbstractCollection<Integer> {
public boolean add(int it) { return true; }
// from the supertype
// public default boolen add(Integer it) { return true; }
}
// FILE: AbstractIntSet.java
public abstract class AbstractIntSet extends AbstractIntCollection implements IntSet {}
// FILE: Main.kt
<!CANNOT_INFER_VISIBILITY!>class KotlinClass<!> : AbstractIntSet()
@@ -1,4 +1,3 @@
// FIR_IDENTICAL
// TARGET_BACKEND: JVM
// FILE: IntCollection.java
@@ -21,7 +21,7 @@ open class C : A<Int>()
interface D : B<Int>
<!MANY_IMPL_MEMBER_NOT_IMPLEMENTED!>class E<!> : C(), D
<!CANNOT_INFER_VISIBILITY, MANY_IMPL_MEMBER_NOT_IMPLEMENTED!>class E<!> : C(), D
fun main() {
E().foo(42)
@@ -10,8 +10,8 @@
expect open class C1()
expect interface I1
open <!MANY_IMPL_MEMBER_NOT_IMPLEMENTED!>class Common1_1<!> : C1(), I1
open <!MANY_IMPL_MEMBER_NOT_IMPLEMENTED!>class Common1_2<!> : I1, C1()
open <!CANNOT_INFER_VISIBILITY, MANY_IMPL_MEMBER_NOT_IMPLEMENTED!>class Common1_1<!> : C1(), I1
open <!CANNOT_INFER_VISIBILITY, MANY_IMPL_MEMBER_NOT_IMPLEMENTED!>class Common1_2<!> : I1, C1()
expect open class Expect1_1 : C1, I1
expect open class Expect1_2 : I1, C1
@@ -37,8 +37,8 @@ actual interface I1 {
fun f() {}
}
actual open <!MANY_IMPL_MEMBER_NOT_IMPLEMENTED!>class Expect1_1<!> : C1(), I1
actual open <!MANY_IMPL_MEMBER_NOT_IMPLEMENTED!>class Expect1_2<!> : I1, C1()
actual open <!CANNOT_INFER_VISIBILITY, MANY_IMPL_MEMBER_NOT_IMPLEMENTED!>class Expect1_1<!> : C1(), I1
actual open <!CANNOT_INFER_VISIBILITY, MANY_IMPL_MEMBER_NOT_IMPLEMENTED!>class Expect1_2<!> : I1, C1()
actual abstract class C2 actual constructor() {
@@ -11,9 +11,9 @@
expect interface S1
expect interface S2
open <!MANY_INTERFACES_MEMBER_NOT_IMPLEMENTED!>class A<!> : S1, S2
open <!CANNOT_INFER_VISIBILITY, MANY_INTERFACES_MEMBER_NOT_IMPLEMENTED!>class A<!> : S1, S2
class B : A()
<!CANNOT_INFER_VISIBILITY!>class B<!> : A()
// MODULE: jvm()()(common)
// TARGET_PLATFORM: JVM
@@ -0,0 +1,11 @@
interface A {
fun f(): String = "string"
}
open class B {
open fun f(): CharSequence = "charSequence"
}
<!CANNOT_INFER_VISIBILITY, MANY_IMPL_MEMBER_NOT_IMPLEMENTED!>class C<!> : B(), A
val obj: A = <!CANNOT_INFER_VISIBILITY, MANY_IMPL_MEMBER_NOT_IMPLEMENTED!>object<!> : B(), A {}
@@ -1,4 +1,3 @@
// FIR_IDENTICAL
interface A {
fun f(): String = "string"
}
@@ -0,0 +1,17 @@
package d
interface A {
fun foo() = 1
}
interface B {
fun foo() = 2
}
open <!CANNOT_INFER_VISIBILITY, MANY_INTERFACES_MEMBER_NOT_IMPLEMENTED!>class C<!> : A, B {}
interface E {
fun foo(): Int
}
<!CANNOT_INFER_VISIBILITY!>class D<!> : C() {}
@@ -1,4 +1,3 @@
// FIR_IDENTICAL
package d
interface A {
@@ -20,9 +20,9 @@ open class CVar {
<!MANY_INTERFACES_MEMBER_NOT_IMPLEMENTED!>class C1<!> : IVar, IVarDefault
<!VAR_IMPLEMENTED_BY_INHERITED_VAL_WARNING!>class C2<!> : CVal(), IVar
<!MANY_IMPL_MEMBER_NOT_IMPLEMENTED!>class C3<!> : CVal(), IVarDefault
<!MANY_IMPL_MEMBER_NOT_IMPLEMENTED!>class C4<!> : CVal(), IVar, IVarDefault
<!CANNOT_INFER_VISIBILITY, MANY_IMPL_MEMBER_NOT_IMPLEMENTED!>class C3<!> : CVal(), IVarDefault
<!CANNOT_INFER_VISIBILITY, MANY_IMPL_MEMBER_NOT_IMPLEMENTED!>class C4<!> : CVal(), IVar, IVarDefault
class C5 : CVar(), IVar
<!MANY_IMPL_MEMBER_NOT_IMPLEMENTED!>class C6<!> : CVar(), IVarDefault
<!MANY_IMPL_MEMBER_NOT_IMPLEMENTED!>class C7<!> : CVar(), IVar, IVarDefault
<!CANNOT_INFER_VISIBILITY, MANY_IMPL_MEMBER_NOT_IMPLEMENTED!>class C6<!> : CVar(), IVarDefault
<!CANNOT_INFER_VISIBILITY, MANY_IMPL_MEMBER_NOT_IMPLEMENTED!>class C7<!> : CVar(), IVar, IVarDefault
<!VAR_OVERRIDDEN_BY_VAL_BY_DELEGATION!>class C8<!>(ival: IVal) : IVar, IVal by ival
@@ -20,9 +20,9 @@ open class CVar {
<!MANY_INTERFACES_MEMBER_NOT_IMPLEMENTED!>class C1<!> : IVar, IVarDefault
<!VAR_IMPLEMENTED_BY_INHERITED_VAL_ERROR!>class C2<!> : CVal(), IVar
<!MANY_IMPL_MEMBER_NOT_IMPLEMENTED!>class C3<!> : CVal(), IVarDefault
<!MANY_IMPL_MEMBER_NOT_IMPLEMENTED!>class C4<!> : CVal(), IVar, IVarDefault
<!CANNOT_INFER_VISIBILITY, MANY_IMPL_MEMBER_NOT_IMPLEMENTED!>class C3<!> : CVal(), IVarDefault
<!CANNOT_INFER_VISIBILITY, MANY_IMPL_MEMBER_NOT_IMPLEMENTED!>class C4<!> : CVal(), IVar, IVarDefault
class C5 : CVar(), IVar
<!MANY_IMPL_MEMBER_NOT_IMPLEMENTED!>class C6<!> : CVar(), IVarDefault
<!MANY_IMPL_MEMBER_NOT_IMPLEMENTED!>class C7<!> : CVar(), IVar, IVarDefault
<!CANNOT_INFER_VISIBILITY, MANY_IMPL_MEMBER_NOT_IMPLEMENTED!>class C6<!> : CVar(), IVarDefault
<!CANNOT_INFER_VISIBILITY, MANY_IMPL_MEMBER_NOT_IMPLEMENTED!>class C7<!> : CVar(), IVar, IVarDefault
<!VAR_OVERRIDDEN_BY_VAL_BY_DELEGATION!>class C8<!>(ival: IVal) : IVar, IVal by ival
@@ -0,0 +1,13 @@
// KT-302 Report an error when inheriting many implementations of the same member
package kt302
interface A {
open fun foo() {}
}
interface B {
open fun foo() {}
}
<!CANNOT_INFER_VISIBILITY, MANY_INTERFACES_MEMBER_NOT_IMPLEMENTED!>class C<!> : A, B {} //should be error here
@@ -1,4 +1,3 @@
// FIR_IDENTICAL
// KT-302 Report an error when inheriting many implementations of the same member
package kt302
@@ -14,4 +14,4 @@ interface IS {
fun replace(key: String, value: String): String? = null
}
abstract <!MANY_IMPL_MEMBER_NOT_IMPLEMENTED!>class ZS<!> : MyMap<String, String>(), IS
abstract <!CANNOT_INFER_VISIBILITY, MANY_IMPL_MEMBER_NOT_IMPLEMENTED!>class ZS<!> : MyMap<String, String>(), IS