FIR: Fix visibility check for protected within a companion
This commit is contained in:
@@ -6,7 +6,6 @@
|
|||||||
package org.jetbrains.kotlin.fir.resolve.calls
|
package org.jetbrains.kotlin.fir.resolve.calls
|
||||||
|
|
||||||
import org.jetbrains.kotlin.descriptors.Visibilities
|
import org.jetbrains.kotlin.descriptors.Visibilities
|
||||||
import org.jetbrains.kotlin.fir.FirAnnotationContainer
|
|
||||||
import org.jetbrains.kotlin.fir.FirSession
|
import org.jetbrains.kotlin.fir.FirSession
|
||||||
import org.jetbrains.kotlin.fir.declarations.*
|
import org.jetbrains.kotlin.fir.declarations.*
|
||||||
import org.jetbrains.kotlin.fir.expressions.FirExpression
|
import org.jetbrains.kotlin.fir.expressions.FirExpression
|
||||||
@@ -353,6 +352,11 @@ internal object CheckVisibility : CheckerStage() {
|
|||||||
if (classId in visited) return false
|
if (classId in visited) return false
|
||||||
visited += classId
|
visited += classId
|
||||||
if (classId.isSame(ownerId)) return true
|
if (classId.isSame(ownerId)) return true
|
||||||
|
|
||||||
|
fir.companionObject?.let { companion ->
|
||||||
|
if (companion.classId.isSame(ownerId)) return true
|
||||||
|
}
|
||||||
|
|
||||||
val superTypes = fir.superConeTypes
|
val superTypes = fir.superConeTypes
|
||||||
for (superType in superTypes) {
|
for (superType in superTypes) {
|
||||||
val superTypeSymbol = superType.lookupTag.toSymbol(session) as? FirRegularClassSymbol ?: continue
|
val superTypeSymbol = superType.lookupTag.toSymbol(session) as? FirRegularClassSymbol ?: continue
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ class Derived : Protected() {
|
|||||||
Nested().<!INAPPLICABLE_CANDIDATE!>bar<!>() // hidden
|
Nested().<!INAPPLICABLE_CANDIDATE!>bar<!>() // hidden
|
||||||
|
|
||||||
fromCompanion()
|
fromCompanion()
|
||||||
<!INAPPLICABLE_CANDIDATE!>protectedFromCompanion<!>()
|
protectedFromCompanion()
|
||||||
}
|
}
|
||||||
|
|
||||||
private class NestedDerived : Nested() {
|
private class NestedDerived : Nested() {
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ FILE: protectedVisibility.kt
|
|||||||
R|/Protected.Nested.Nested|().R|/Protected.Nested.foo|()
|
R|/Protected.Nested.Nested|().R|/Protected.Nested.foo|()
|
||||||
R|/Protected.Nested.Nested|().<Inapplicable(HIDDEN): [/Protected.Nested.bar]>#()
|
R|/Protected.Nested.Nested|().<Inapplicable(HIDDEN): [/Protected.Nested.bar]>#()
|
||||||
this@R|/Protected.Companion|.R|/Protected.Companion.fromCompanion|()
|
this@R|/Protected.Companion|.R|/Protected.Companion.fromCompanion|()
|
||||||
<Inapplicable(HIDDEN): [/Protected.Companion.protectedFromCompanion]>#()
|
this@R|/Protected.Companion|.R|/Protected.Companion.protectedFromCompanion|()
|
||||||
}
|
}
|
||||||
|
|
||||||
private final class NestedDerived : R|Protected.Nested| {
|
private final class NestedDerived : R|Protected.Nested| {
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
abstract class A {
|
||||||
|
companion object {
|
||||||
|
protected val PROTECTED_CONST: String = ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class B : A() {
|
||||||
|
val y: String = PROTECTED_CONST
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
FILE: protectedInCompanion.kt
|
||||||
|
public abstract class A : R|kotlin/Any| {
|
||||||
|
public constructor(): R|A| {
|
||||||
|
super<R|kotlin/Any|>()
|
||||||
|
}
|
||||||
|
|
||||||
|
public final companion object Companion : R|kotlin/Any| {
|
||||||
|
private constructor(): R|A.Companion| {
|
||||||
|
super<R|kotlin/Any|>()
|
||||||
|
}
|
||||||
|
|
||||||
|
protected final val PROTECTED_CONST: R|kotlin/String| = String()
|
||||||
|
protected get(): R|kotlin/String|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
public final class B : R|A| {
|
||||||
|
public constructor(): R|B| {
|
||||||
|
super<R|A|>()
|
||||||
|
}
|
||||||
|
|
||||||
|
public final val y: R|kotlin/String| = this@R|/A.Companion|.R|/A.Companion.PROTECTED_CONST|
|
||||||
|
public get(): R|kotlin/String|
|
||||||
|
|
||||||
|
}
|
||||||
+18
@@ -1935,4 +1935,22 @@ public class FirDiagnosticsTestGenerated extends AbstractFirDiagnosticsTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("compiler/fir/resolve/testData/resolve/visibility")
|
||||||
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
|
public static class Visibility extends AbstractFirDiagnosticsTest {
|
||||||
|
private void runTest(String testDataFilePath) throws Exception {
|
||||||
|
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testAllFilesPresentInVisibility() throws Exception {
|
||||||
|
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/resolve/testData/resolve/visibility"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("protectedInCompanion.kt")
|
||||||
|
public void testProtectedInCompanion() throws Exception {
|
||||||
|
runTest("compiler/fir/resolve/testData/resolve/visibility/protectedInCompanion.kt");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Generated
+18
@@ -1935,4 +1935,22 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("compiler/fir/resolve/testData/resolve/visibility")
|
||||||
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
|
public static class Visibility extends AbstractFirDiagnosticsWithLightTreeTest {
|
||||||
|
private void runTest(String testDataFilePath) throws Exception {
|
||||||
|
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testAllFilesPresentInVisibility() throws Exception {
|
||||||
|
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/resolve/testData/resolve/visibility"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("protectedInCompanion.kt")
|
||||||
|
public void testProtectedInCompanion() throws Exception {
|
||||||
|
runTest("compiler/fir/resolve/testData/resolve/visibility/protectedInCompanion.kt");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,6 +28,6 @@ class B: A() {
|
|||||||
devNull(A.internal_val)
|
devNull(A.internal_val)
|
||||||
devNull(A.public_val)
|
devNull(A.public_val)
|
||||||
devNull(A.<!INAPPLICABLE_CANDIDATE!>private_val<!>)
|
devNull(A.<!INAPPLICABLE_CANDIDATE!>private_val<!>)
|
||||||
devNull(A.<!INAPPLICABLE_CANDIDATE!>protected_val<!>)
|
devNull(A.protected_val)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+6
-6
@@ -46,8 +46,8 @@ open class Base {
|
|||||||
class Derived : Base() {
|
class Derived : Base() {
|
||||||
fun test() {
|
fun test() {
|
||||||
foo() // Ok
|
foo() // Ok
|
||||||
<!INAPPLICABLE_CANDIDATE!>gav<!>() // Ok
|
gav() // Ok
|
||||||
<!INAPPLICABLE_CANDIDATE!>bar<!>()
|
bar()
|
||||||
<!INAPPLICABLE_CANDIDATE!>baz<!>()
|
<!INAPPLICABLE_CANDIDATE!>baz<!>()
|
||||||
prop = 0
|
prop = 0
|
||||||
}
|
}
|
||||||
@@ -55,8 +55,8 @@ class Derived : Base() {
|
|||||||
inner class DerivedInner {
|
inner class DerivedInner {
|
||||||
fun fromDerivedInner() {
|
fun fromDerivedInner() {
|
||||||
foo() // Ok
|
foo() // Ok
|
||||||
<!INAPPLICABLE_CANDIDATE!>gav<!>() // Ok
|
gav() // Ok
|
||||||
<!INAPPLICABLE_CANDIDATE!>bar<!>()
|
bar()
|
||||||
<!INAPPLICABLE_CANDIDATE!>baz<!>()
|
<!INAPPLICABLE_CANDIDATE!>baz<!>()
|
||||||
prop = 0
|
prop = 0
|
||||||
}
|
}
|
||||||
@@ -64,8 +64,8 @@ class Derived : Base() {
|
|||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
fun test2() {
|
fun test2() {
|
||||||
<!INAPPLICABLE_CANDIDATE!>gav<!>() // Ok
|
gav() // Ok
|
||||||
<!INAPPLICABLE_CANDIDATE!>bar<!>()
|
bar()
|
||||||
<!INAPPLICABLE_CANDIDATE!>baz<!>()
|
<!INAPPLICABLE_CANDIDATE!>baz<!>()
|
||||||
prop = 0
|
prop = 0
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user