[FIR] Consider containing class during visibility check of static function call
^KT-53441
This commit is contained in:
committed by
Space Team
parent
a14cab7245
commit
64e21af03b
@@ -101,7 +101,12 @@ abstract class FirVisibilityChecker : FirSessionComponent {
|
||||
|
||||
if (skipCheckForContainingClassVisibility) return true
|
||||
|
||||
val parentClass = declaration.containingNonLocalClass(session, dispatchReceiver) ?: return true
|
||||
val parentClass = declaration.containingNonLocalClass(
|
||||
session,
|
||||
dispatchReceiver,
|
||||
containingDeclarations,
|
||||
supertypeSupplier
|
||||
) ?: return true
|
||||
return generateSequence(parentClass) { it.containingNonLocalClass(session) }.all { parent ->
|
||||
isSpecificDeclarationVisible(
|
||||
parent,
|
||||
@@ -137,7 +142,9 @@ abstract class FirVisibilityChecker : FirSessionComponent {
|
||||
|
||||
private fun FirMemberDeclaration.containingNonLocalClass(
|
||||
session: FirSession,
|
||||
dispatchReceiverValue: ReceiverValue?
|
||||
dispatchReceiverValue: ReceiverValue?,
|
||||
containingUseSiteDeclarations: List<FirDeclaration>,
|
||||
supertypeSupplier: SupertypeSupplier
|
||||
): FirClassLikeDeclaration? {
|
||||
return when (this) {
|
||||
is FirCallableDeclaration -> {
|
||||
@@ -147,7 +154,17 @@ abstract class FirVisibilityChecker : FirSessionComponent {
|
||||
}
|
||||
}
|
||||
|
||||
this.containingClass()?.toSymbol(session)?.fir
|
||||
val containingLookupTag = this.containingClass()
|
||||
val containingClass = containingLookupTag?.toSymbol(session)?.fir
|
||||
|
||||
if (isStatic && containingClass != null) {
|
||||
containingUseSiteDeclarations.firstNotNullOfOrNull {
|
||||
if (it !is FirClass) return@firstNotNullOfOrNull null
|
||||
it.takeIf { it.isSubClass(containingLookupTag, session, supertypeSupplier) }
|
||||
}?.let { return it }
|
||||
}
|
||||
|
||||
containingClass
|
||||
}
|
||||
is FirClassLikeDeclaration -> containingNonLocalClass(session)
|
||||
}
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
// ISSUE: KT-54125
|
||||
// FILE: foo/Base.java
|
||||
package foo;
|
||||
|
||||
class Base {
|
||||
protected static void foo() {}
|
||||
}
|
||||
|
||||
// FILE: foo/Derived.java
|
||||
package foo;
|
||||
|
||||
public class Derived extends Base {}
|
||||
|
||||
// FILE: main.kt
|
||||
package bar
|
||||
|
||||
import foo.Derived
|
||||
|
||||
class Impl : Derived() {
|
||||
fun test() {
|
||||
<!INVISIBLE_REFERENCE!>foo<!>()
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,11 @@
|
||||
// ISSUE: KT-54125
|
||||
// FIR_IDENTICAL
|
||||
// ISSUE: KT-53441
|
||||
// FILE: foo/Base.java
|
||||
package foo;
|
||||
|
||||
class Base {
|
||||
protected static void foo() {}
|
||||
protected void bar() {}
|
||||
}
|
||||
|
||||
// FILE: foo/Derived.java
|
||||
@@ -19,5 +21,6 @@ import foo.Derived
|
||||
class Impl : Derived() {
|
||||
fun test() {
|
||||
foo()
|
||||
bar()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ package bar {
|
||||
|
||||
public final class Impl : foo.Derived {
|
||||
public constructor Impl()
|
||||
protected/*protected and package*/ open override /*1*/ /*fake_override*/ fun bar(): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public final fun test(): kotlin.Unit
|
||||
@@ -15,6 +16,7 @@ package foo {
|
||||
|
||||
public/*package*/ open class Base {
|
||||
public/*package*/ constructor Base()
|
||||
protected/*protected and package*/ open fun bar(): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
@@ -25,6 +27,7 @@ package foo {
|
||||
|
||||
public open class Derived : foo.Base {
|
||||
public constructor Derived()
|
||||
protected/*protected and package*/ open override /*1*/ /*fake_override*/ fun bar(): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
@@ -33,3 +36,4 @@ package foo {
|
||||
protected/*protected static*/ open override /*1*/ /*fake_override*/ fun foo(): kotlin.Unit
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user