[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
|
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 ->
|
return generateSequence(parentClass) { it.containingNonLocalClass(session) }.all { parent ->
|
||||||
isSpecificDeclarationVisible(
|
isSpecificDeclarationVisible(
|
||||||
parent,
|
parent,
|
||||||
@@ -137,7 +142,9 @@ abstract class FirVisibilityChecker : FirSessionComponent {
|
|||||||
|
|
||||||
private fun FirMemberDeclaration.containingNonLocalClass(
|
private fun FirMemberDeclaration.containingNonLocalClass(
|
||||||
session: FirSession,
|
session: FirSession,
|
||||||
dispatchReceiverValue: ReceiverValue?
|
dispatchReceiverValue: ReceiverValue?,
|
||||||
|
containingUseSiteDeclarations: List<FirDeclaration>,
|
||||||
|
supertypeSupplier: SupertypeSupplier
|
||||||
): FirClassLikeDeclaration? {
|
): FirClassLikeDeclaration? {
|
||||||
return when (this) {
|
return when (this) {
|
||||||
is FirCallableDeclaration -> {
|
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)
|
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
|
// FILE: foo/Base.java
|
||||||
package foo;
|
package foo;
|
||||||
|
|
||||||
class Base {
|
class Base {
|
||||||
protected static void foo() {}
|
protected static void foo() {}
|
||||||
|
protected void bar() {}
|
||||||
}
|
}
|
||||||
|
|
||||||
// FILE: foo/Derived.java
|
// FILE: foo/Derived.java
|
||||||
@@ -19,5 +21,6 @@ import foo.Derived
|
|||||||
class Impl : Derived() {
|
class Impl : Derived() {
|
||||||
fun test() {
|
fun test() {
|
||||||
foo()
|
foo()
|
||||||
|
bar()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ package bar {
|
|||||||
|
|
||||||
public final class Impl : foo.Derived {
|
public final class Impl : foo.Derived {
|
||||||
public constructor Impl()
|
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 equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||||
public final fun test(): kotlin.Unit
|
public final fun test(): kotlin.Unit
|
||||||
@@ -15,6 +16,7 @@ package foo {
|
|||||||
|
|
||||||
public/*package*/ open class Base {
|
public/*package*/ open class Base {
|
||||||
public/*package*/ constructor 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 equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||||
@@ -25,6 +27,7 @@ package foo {
|
|||||||
|
|
||||||
public open class Derived : foo.Base {
|
public open class Derived : foo.Base {
|
||||||
public constructor Derived()
|
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 equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
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
|
protected/*protected static*/ open override /*1*/ /*fake_override*/ fun foo(): kotlin.Unit
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user