FIR visibility check: support companion private members correctly
This commit is contained in:
@@ -277,7 +277,9 @@ internal object CheckVisibility : CheckerStage() {
|
|||||||
private fun ImplicitReceiverStack.canSeePrivateMemberOf(ownerId: ClassId): Boolean {
|
private fun ImplicitReceiverStack.canSeePrivateMemberOf(ownerId: ClassId): Boolean {
|
||||||
for (implicitReceiverValue in receiversAsReversed()) {
|
for (implicitReceiverValue in receiversAsReversed()) {
|
||||||
if (implicitReceiverValue !is ImplicitDispatchReceiverValue) continue
|
if (implicitReceiverValue !is ImplicitDispatchReceiverValue) continue
|
||||||
if (implicitReceiverValue.boundSymbol.classId == ownerId) return true
|
val boundSymbol = implicitReceiverValue.boundSymbol
|
||||||
|
if (boundSymbol.classId == ownerId) return true
|
||||||
|
if (boundSymbol is FirRegularClassSymbol && boundSymbol.fir.companionObject?.symbol?.classId == ownerId) return true
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,15 +8,32 @@ private class Private {
|
|||||||
fun baz() {
|
fun baz() {
|
||||||
bar()
|
bar()
|
||||||
Nested()
|
Nested()
|
||||||
|
fromCompanion()
|
||||||
|
NotCompanion.<!INAPPLICABLE_CANDIDATE!>foo<!>() // hidden
|
||||||
}
|
}
|
||||||
|
|
||||||
inner class Inner {
|
inner class Inner {
|
||||||
fun foo() {
|
fun foo() {
|
||||||
bar()
|
bar()
|
||||||
|
fromCompanion()
|
||||||
|
NotCompanion.<!INAPPLICABLE_CANDIDATE!>foo<!>() // hidden
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class Nested
|
private class Nested {
|
||||||
|
fun foo() {
|
||||||
|
fromCompanion()
|
||||||
|
NotCompanion.<!INAPPLICABLE_CANDIDATE!>foo<!>() // hidden
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private fun fromCompanion() {}
|
||||||
|
}
|
||||||
|
|
||||||
|
object NotCompanion {
|
||||||
|
private fun foo() {}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun withLocals() {
|
fun withLocals() {
|
||||||
@@ -47,6 +64,7 @@ fun test() {
|
|||||||
|
|
||||||
Private().<!INAPPLICABLE_CANDIDATE!>bar<!>() // hidden
|
Private().<!INAPPLICABLE_CANDIDATE!>bar<!>() // hidden
|
||||||
Private.<!INAPPLICABLE_CANDIDATE!>Nested<!>() // hidden
|
Private.<!INAPPLICABLE_CANDIDATE!>Nested<!>() // hidden
|
||||||
|
Private.<!INAPPLICABLE_CANDIDATE!>fromCompanion<!>() // hidden
|
||||||
}
|
}
|
||||||
|
|
||||||
// FILE: second.kt
|
// FILE: second.kt
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ FILE: first.kt
|
|||||||
public final fun baz(): R|kotlin/Unit| {
|
public final fun baz(): R|kotlin/Unit| {
|
||||||
this@R|/Private|.R|/Private.bar|()
|
this@R|/Private|.R|/Private.bar|()
|
||||||
R|/Private.Nested.Nested|()
|
R|/Private.Nested.Nested|()
|
||||||
|
this@R|/Private.Companion|.R|/Private.Companion.fromCompanion|()
|
||||||
|
Q|Private.NotCompanion|.<Inapplicable(HIDDEN): [/Private.NotCompanion.foo]>#()
|
||||||
}
|
}
|
||||||
|
|
||||||
public final inner class Inner : R|kotlin/Any| {
|
public final inner class Inner : R|kotlin/Any| {
|
||||||
@@ -21,6 +23,8 @@ FILE: first.kt
|
|||||||
|
|
||||||
public final fun foo(): R|kotlin/Unit| {
|
public final fun foo(): R|kotlin/Unit| {
|
||||||
this@R|/Private|.R|/Private.bar|()
|
this@R|/Private|.R|/Private.bar|()
|
||||||
|
this@R|/Private.Companion|.R|/Private.Companion.fromCompanion|()
|
||||||
|
Q|Private.NotCompanion|.<Inapplicable(HIDDEN): [/Private.NotCompanion.foo]>#()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -30,6 +34,31 @@ FILE: first.kt
|
|||||||
super<R|kotlin/Any|>()
|
super<R|kotlin/Any|>()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public final fun foo(): R|kotlin/Unit| {
|
||||||
|
this@R|/Private.Companion|.R|/Private.Companion.fromCompanion|()
|
||||||
|
Q|Private.NotCompanion|.<Inapplicable(HIDDEN): [/Private.NotCompanion.foo]>#()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public final companion object Companion : R|kotlin/Any| {
|
||||||
|
private constructor(): R|Private.Companion| {
|
||||||
|
super<R|kotlin/Any|>()
|
||||||
|
}
|
||||||
|
|
||||||
|
private final fun fromCompanion(): R|kotlin/Unit| {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public final object NotCompanion : R|kotlin/Any| {
|
||||||
|
private constructor(): R|Private.NotCompanion| {
|
||||||
|
super<R|kotlin/Any|>()
|
||||||
|
}
|
||||||
|
|
||||||
|
private final fun foo(): R|kotlin/Unit| {
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -68,6 +97,7 @@ FILE: first.kt
|
|||||||
R|/Private.Private|().R|/Private.Inner.Inner|()
|
R|/Private.Private|().R|/Private.Inner.Inner|()
|
||||||
R|/Private.Private|().<Inapplicable(HIDDEN): [/Private.bar]>#()
|
R|/Private.Private|().<Inapplicable(HIDDEN): [/Private.bar]>#()
|
||||||
Q|Private|.<Inapplicable(HIDDEN): [/Private.Nested.Nested]>#()
|
Q|Private|.<Inapplicable(HIDDEN): [/Private.Nested.Nested]>#()
|
||||||
|
Q|Private|.<Inapplicable(HIDDEN): [/Private.Companion.fromCompanion]>#()
|
||||||
}
|
}
|
||||||
FILE: second.kt
|
FILE: second.kt
|
||||||
public final fun secondTest(): R|kotlin/Unit| {
|
public final fun secondTest(): R|kotlin/Unit| {
|
||||||
|
|||||||
Reference in New Issue
Block a user