From fba44759c0d5af79d3f7d74fcf5a7ea7019d1720 Mon Sep 17 00:00:00 2001 From: "Denis.Zharkov" Date: Mon, 18 Oct 2021 12:21:57 +0300 Subject: [PATCH] FIR: Refine visibility check for class members --- ...CompilerTestFE10TestdataTestGenerated.java | 12 ++ ...irOldFrontendDiagnosticsTestGenerated.java | 12 ++ ...DiagnosticsWithLightTreeTestGenerated.java | 12 ++ .../declaration/FirOverrideChecker.kt | 9 +- .../kotlin/fir/FirVisibilityChecker.kt | 107 +++++++++++++++++- .../tests/annotations/requireKotlin.fir.kt | 2 +- .../classObjects/ClassObjectVisibility.fir.kt | 2 +- ...anionObjectOfPrivateClassVisibility.fir.kt | 4 +- .../classObjects/invisibleClassObjects.fir.kt | 8 +- .../nestedClassInPrivateClassObject.fir.kt | 2 +- .../tests/imports/ImportPrivateMember.fir.kt | 4 +- .../ImportPrivateMemberFromOtherFile.fir.kt | 2 +- .../ImportPrivateMembersWithStar.fir.kt | 4 +- .../j+k/privateNestedClassStaticMember.fir.kt | 2 +- .../tests/privateInFile/visibility.fir.kt | 2 +- .../tests/scopes/visibility2.fir.kt | 2 +- .../tests/scopes/visibility3.fir.kt | 2 +- .../smartcastToInvisibleType_java.fir.kt | 2 +- .../smartcastToInvisibleType_kotlin.fir.kt | 2 +- .../overrideOfMemberInPackagePrivateClass.kt | 20 ++++ .../privateCompanionInSuperClass.fir.kt | 24 ++++ .../privateCompanionInSuperClass.kt | 24 ++++ .../test/runners/DiagnosticTestGenerated.java | 12 ++ 23 files changed, 246 insertions(+), 26 deletions(-) create mode 100644 compiler/testData/diagnostics/tests/visibility/overrideOfMemberInPackagePrivateClass.kt create mode 100644 compiler/testData/diagnostics/tests/visibility/privateCompanionInSuperClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/visibility/privateCompanionInSuperClass.kt diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java index 274f6e20138..1a9b442efbc 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java @@ -32019,6 +32019,18 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag runTest("compiler/testData/diagnostics/tests/visibility/lackOfInvisibleSetterOfJavaClassInSamePackage.kt"); } + @Test + @TestMetadata("overrideOfMemberInPackagePrivateClass.kt") + public void testOverrideOfMemberInPackagePrivateClass() throws Exception { + runTest("compiler/testData/diagnostics/tests/visibility/overrideOfMemberInPackagePrivateClass.kt"); + } + + @Test + @TestMetadata("privateCompanionInSuperClass.kt") + public void testPrivateCompanionInSuperClass() throws Exception { + runTest("compiler/testData/diagnostics/tests/visibility/privateCompanionInSuperClass.kt"); + } + @Test @TestMetadata("protectedInternal.kt") public void testProtectedInternal() throws Exception { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java index 870dd19eaeb..b51a65c1e78 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java @@ -32019,6 +32019,18 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti runTest("compiler/testData/diagnostics/tests/visibility/lackOfInvisibleSetterOfJavaClassInSamePackage.kt"); } + @Test + @TestMetadata("overrideOfMemberInPackagePrivateClass.kt") + public void testOverrideOfMemberInPackagePrivateClass() throws Exception { + runTest("compiler/testData/diagnostics/tests/visibility/overrideOfMemberInPackagePrivateClass.kt"); + } + + @Test + @TestMetadata("privateCompanionInSuperClass.kt") + public void testPrivateCompanionInSuperClass() throws Exception { + runTest("compiler/testData/diagnostics/tests/visibility/privateCompanionInSuperClass.kt"); + } + @Test @TestMetadata("protectedInternal.kt") public void testProtectedInternal() throws Exception { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java index 35ef3768aa4..cc1e673b345 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java @@ -32019,6 +32019,18 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac runTest("compiler/testData/diagnostics/tests/visibility/lackOfInvisibleSetterOfJavaClassInSamePackage.kt"); } + @Test + @TestMetadata("overrideOfMemberInPackagePrivateClass.kt") + public void testOverrideOfMemberInPackagePrivateClass() throws Exception { + runTest("compiler/testData/diagnostics/tests/visibility/overrideOfMemberInPackagePrivateClass.kt"); + } + + @Test + @TestMetadata("privateCompanionInSuperClass.kt") + public void testPrivateCompanionInSuperClass() throws Exception { + runTest("compiler/testData/diagnostics/tests/visibility/privateCompanionInSuperClass.kt"); + } + @Test @TestMetadata("protectedInternal.kt") public void testProtectedInternal() throws Exception { diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirOverrideChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirOverrideChecker.kt index fbbe7d09d0d..fbee1a0fab1 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirOverrideChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirOverrideChecker.kt @@ -167,7 +167,14 @@ object FirOverrideChecker : FirClassChecker() { it.ensureResolved(FirResolvePhase.STATUS) @OptIn(SymbolInternals::class) val fir = it.fir - visibilityChecker.isVisible(fir, context.session, file, containingDeclarations, null) + visibilityChecker.isVisible( + fir, + context.session, + file, + containingDeclarations, + null, + skipCheckForContainingClassVisibility = true + ) } if (!hasVisibleBase) { //NB: Old FE reports this in an attempt to override private member, diff --git a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/FirVisibilityChecker.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/FirVisibilityChecker.kt index 74cec83a423..315894fbca4 100644 --- a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/FirVisibilityChecker.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/FirVisibilityChecker.kt @@ -23,11 +23,10 @@ import org.jetbrains.kotlin.fir.resolve.providers.symbolProvider import org.jetbrains.kotlin.fir.resolve.toSymbol import org.jetbrains.kotlin.fir.resolve.typeWithStarProjections import org.jetbrains.kotlin.fir.symbols.ConeClassLikeLookupTag +import org.jetbrains.kotlin.fir.symbols.ConeTypeParameterLookupTag import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol import org.jetbrains.kotlin.fir.symbols.impl.* -import org.jetbrains.kotlin.fir.types.ConeClassLikeType -import org.jetbrains.kotlin.fir.types.coneType -import org.jetbrains.kotlin.fir.types.typeContext +import org.jetbrains.kotlin.fir.types.* import org.jetbrains.kotlin.name.ClassId import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.types.AbstractTypeChecker @@ -67,10 +66,108 @@ abstract class FirVisibilityChecker : FirSessionComponent { containingDeclarations: List, dispatchReceiver: ReceiverValue?, isCallToPropertySetter: Boolean = false, + // There's no need to check if containing class is visible in case we check if a member might be overridden in a subclass + // because visibility for its supertype that contain overridden member is being checked when resolving the type reference. + // Such flag is not necessary in FE1.0, since there are full structure of fake overrides and containing declaration for overridden + // is always visible since it's a supertype of a derived class. + skipCheckForContainingClassVisibility: Boolean = false, + ): Boolean { + if (!isSpecificDeclarationVisible( + declaration, + session, + useSiteFile, + containingDeclarations, + dispatchReceiver, + isCallToPropertySetter + ) + ) { + return false + } + + if (skipCheckForContainingClassVisibility) return true + + val parentClass = declaration.containingNonLocalClass(session, dispatchReceiver) ?: return true + return generateSequence(parentClass) { it.containingNonLocalClass(session) }.all { parent -> + isSpecificDeclarationVisible( + parent, + session, + useSiteFile, + containingDeclarations, + dispatchReceiver, + isCallToPropertySetter + ) + } + } + + private fun FirMemberDeclaration.containingNonLocalClass( + session: FirSession, + dispatchReceiverValue: ReceiverValue? + ): FirClassLikeDeclaration? { + return when (this) { + is FirCallableDeclaration -> { + if (dispatchReceiverValue != null && dispatchReceiverType != null) { + dispatchReceiverValue.type.findClassRepresentation(dispatchReceiverType!!, session)?.let { return it } + } + + this.containingClass()?.toSymbol(session)?.fir + } + is FirClassLikeDeclaration -> containingNonLocalClass(session) + } + } + + private fun FirClassLikeDeclaration.containingNonLocalClass(session: FirSession): FirClassLikeDeclaration? { + return when (this) { + is FirClass -> { + if (isLocal) return null + + this.classId.outerClassId?.let { session.symbolProvider.getClassLikeSymbolByClassId(it)?.fir } + } + // Currently, type aliases are only top-level + is FirTypeAlias -> null + } + } + + private fun ConeKotlinType.findClassRepresentation( + dispatchReceiverParameterType: ConeKotlinType, + session: FirSession + ): FirClassLikeDeclaration? = + when (this) { + is ConeClassLikeType -> this.fullyExpandedType(session).lookupTag.toSymbol(session)?.fir + is ConeFlexibleType -> lowerBound.findClassRepresentation(dispatchReceiverParameterType, session) + is ConeCapturedType -> constructor.supertypes.orEmpty() + .findClassRepresentationThatIsSubtypeOf(dispatchReceiverParameterType, session) + is ConeDefinitelyNotNullType -> original.findClassRepresentation(dispatchReceiverParameterType, session) + is ConeIntegerLiteralType -> possibleTypes.findClassRepresentationThatIsSubtypeOf(dispatchReceiverParameterType, session) + is ConeIntersectionType -> intersectedTypes.findClassRepresentationThatIsSubtypeOf(dispatchReceiverParameterType, session) + is ConeTypeParameterType -> lookupTag.findClassRepresentationThatIsSubtypeOf(dispatchReceiverParameterType, session) + is ConeTypeVariableType -> (this.lookupTag.originalTypeParameter as? ConeTypeParameterLookupTag) + ?.findClassRepresentationThatIsSubtypeOf(dispatchReceiverParameterType, session) + is ConeStubType -> (this.variable.typeConstructor.originalTypeParameter as? ConeTypeParameterLookupTag) + ?.findClassRepresentationThatIsSubtypeOf(dispatchReceiverParameterType, session) + is ConeLookupTagBasedType -> null + } + + private fun ConeTypeParameterLookupTag.findClassRepresentationThatIsSubtypeOf( + supertype: ConeKotlinType, + session: FirSession + ): FirClassLikeDeclaration? = + typeParameterSymbol.fir.bounds.map { it.coneType }.findClassRepresentationThatIsSubtypeOf(supertype, session) + + private fun Collection.findClassRepresentationThatIsSubtypeOf( + supertype: ConeKotlinType, + session: FirSession + ): FirClassLikeDeclaration? = firstOrNull { it.isSubtypeOf(supertype, session) }?.findClassRepresentation(supertype, session) + + private fun isSpecificDeclarationVisible( + declaration: FirMemberDeclaration, + session: FirSession, + useSiteFile: FirFile, + containingDeclarations: List, + dispatchReceiver: ReceiverValue?, + isCallToPropertySetter: Boolean = false, ): Boolean { - require(declaration is FirDeclaration) - val provider = session.firProvider val symbol = declaration.symbol + val provider = session.firProvider return when (declaration.visibility) { Visibilities.Internal -> { declaration.moduleData == session.moduleData || session.moduleVisibilityChecker?.isInFriendModule(declaration) == true diff --git a/compiler/testData/diagnostics/tests/annotations/requireKotlin.fir.kt b/compiler/testData/diagnostics/tests/annotations/requireKotlin.fir.kt index 4d1a1b196af..06734896514 100644 --- a/compiler/testData/diagnostics/tests/annotations/requireKotlin.fir.kt +++ b/compiler/testData/diagnostics/tests/annotations/requireKotlin.fir.kt @@ -8,5 +8,5 @@ class IllegalVersion() @RequireKotlin("1.2") class LegalMinimum() -@RequireKotlin("1.2", versionKind = RequireKotlinVersionKind.COMPILER_VERSION, message = "Requires newer compiler version to be inlined correctly.") +@RequireKotlin("1.2", versionKind = RequireKotlinVersionKind.COMPILER_VERSION, message = "Requires newer compiler version to be inlined correctly.") class LegalStdLib() diff --git a/compiler/testData/diagnostics/tests/classObjects/ClassObjectVisibility.fir.kt b/compiler/testData/diagnostics/tests/classObjects/ClassObjectVisibility.fir.kt index 5e555acec14..4e786195c46 100644 --- a/compiler/testData/diagnostics/tests/classObjects/ClassObjectVisibility.fir.kt +++ b/compiler/testData/diagnostics/tests/classObjects/ClassObjectVisibility.fir.kt @@ -5,7 +5,7 @@ fun test() { A.Companion.f B.D CCC - CCC.classObjectVar + CCC.classObjectVar } class A() { diff --git a/compiler/testData/diagnostics/tests/classObjects/companionObjectOfPrivateClassVisibility.fir.kt b/compiler/testData/diagnostics/tests/classObjects/companionObjectOfPrivateClassVisibility.fir.kt index 28f44a7fed7..0e2eb215bd7 100644 --- a/compiler/testData/diagnostics/tests/classObjects/companionObjectOfPrivateClassVisibility.fir.kt +++ b/compiler/testData/diagnostics/tests/classObjects/companionObjectOfPrivateClassVisibility.fir.kt @@ -3,7 +3,7 @@ package test fun use() { Default.create() - Explicit.create() + Explicit.create() } private class Default { @@ -16,4 +16,4 @@ private class Explicit { private companion object { fun create() = Explicit() } -} \ No newline at end of file +} diff --git a/compiler/testData/diagnostics/tests/classObjects/invisibleClassObjects.fir.kt b/compiler/testData/diagnostics/tests/classObjects/invisibleClassObjects.fir.kt index 892f628129d..0f31b184191 100644 --- a/compiler/testData/diagnostics/tests/classObjects/invisibleClassObjects.fir.kt +++ b/compiler/testData/diagnostics/tests/classObjects/invisibleClassObjects.fir.kt @@ -40,12 +40,12 @@ fun test() { f(D) A.foo() - B.bar() - C.baz() - D.quux() + B.bar() + C.baz() + D.quux() a.A.foo() - a.C.baz() + a.C.baz() } fun f(unused: Any) {} diff --git a/compiler/testData/diagnostics/tests/classObjects/nestedClassInPrivateClassObject.fir.kt b/compiler/testData/diagnostics/tests/classObjects/nestedClassInPrivateClassObject.fir.kt index a4b5beffe39..c15513d9cf5 100644 --- a/compiler/testData/diagnostics/tests/classObjects/nestedClassInPrivateClassObject.fir.kt +++ b/compiler/testData/diagnostics/tests/classObjects/nestedClassInPrivateClassObject.fir.kt @@ -12,4 +12,4 @@ class A { fun f1() = A.Companion.B.C -fun f2() = A.Companion.B.C.foo() +fun f2() = A.Companion.B.C.foo() diff --git a/compiler/testData/diagnostics/tests/imports/ImportPrivateMember.fir.kt b/compiler/testData/diagnostics/tests/imports/ImportPrivateMember.fir.kt index 91c491679d5..49e046d1959 100644 --- a/compiler/testData/diagnostics/tests/imports/ImportPrivateMember.fir.kt +++ b/compiler/testData/diagnostics/tests/imports/ImportPrivateMember.fir.kt @@ -31,7 +31,7 @@ private object TopLevelObject { fun testAccess() { NestedClass() E1 - InNested() - NestedEntry + InNested() + NestedEntry inObject() } diff --git a/compiler/testData/diagnostics/tests/imports/ImportPrivateMemberFromOtherFile.fir.kt b/compiler/testData/diagnostics/tests/imports/ImportPrivateMemberFromOtherFile.fir.kt index 12bda92ac38..9beee7f0587 100644 --- a/compiler/testData/diagnostics/tests/imports/ImportPrivateMemberFromOtherFile.fir.kt +++ b/compiler/testData/diagnostics/tests/imports/ImportPrivateMemberFromOtherFile.fir.kt @@ -22,5 +22,5 @@ import B.JC.JC1 fun test() { O1 - JC1() + JC1() } diff --git a/compiler/testData/diagnostics/tests/imports/ImportPrivateMembersWithStar.fir.kt b/compiler/testData/diagnostics/tests/imports/ImportPrivateMembersWithStar.fir.kt index 3f44adf4ce7..5784f5ee513 100644 --- a/compiler/testData/diagnostics/tests/imports/ImportPrivateMembersWithStar.fir.kt +++ b/compiler/testData/diagnostics/tests/imports/ImportPrivateMembersWithStar.fir.kt @@ -26,7 +26,7 @@ private enum class TopLevelEnum(private val e: NestedEnum) { fun testAccess() { E1 - NestedEntry - A1() + NestedEntry + A1() A2 } diff --git a/compiler/testData/diagnostics/tests/j+k/privateNestedClassStaticMember.fir.kt b/compiler/testData/diagnostics/tests/j+k/privateNestedClassStaticMember.fir.kt index a50380e82b8..eeb612f19b3 100644 --- a/compiler/testData/diagnostics/tests/j+k/privateNestedClassStaticMember.fir.kt +++ b/compiler/testData/diagnostics/tests/j+k/privateNestedClassStaticMember.fir.kt @@ -14,5 +14,5 @@ public class Foo { // FILE: 1.kt fun main() { - javaPackage.Foo.Bar.doSmth() + javaPackage.Foo.Bar.doSmth() } diff --git a/compiler/testData/diagnostics/tests/privateInFile/visibility.fir.kt b/compiler/testData/diagnostics/tests/privateInFile/visibility.fir.kt index 905eb64e3ab..67518456343 100644 --- a/compiler/testData/diagnostics/tests/privateInFile/visibility.fir.kt +++ b/compiler/testData/diagnostics/tests/privateInFile/visibility.fir.kt @@ -29,7 +29,7 @@ package a fun test() { val y = makeA() - y.bar() + y.bar() foo() val u : A = A() diff --git a/compiler/testData/diagnostics/tests/scopes/visibility2.fir.kt b/compiler/testData/diagnostics/tests/scopes/visibility2.fir.kt index bfca858b9ef..c2d2227d2e5 100644 --- a/compiler/testData/diagnostics/tests/scopes/visibility2.fir.kt +++ b/compiler/testData/diagnostics/tests/scopes/visibility2.fir.kt @@ -24,7 +24,7 @@ import a.PO fun test() { val y = makeA() - y.bar() + y.bar() foo() val u : A = A() diff --git a/compiler/testData/diagnostics/tests/scopes/visibility3.fir.kt b/compiler/testData/diagnostics/tests/scopes/visibility3.fir.kt index 08103fdd276..0558ddecc90 100644 --- a/compiler/testData/diagnostics/tests/scopes/visibility3.fir.kt +++ b/compiler/testData/diagnostics/tests/scopes/visibility3.fir.kt @@ -25,7 +25,7 @@ package a fun test() { val y = makeA() - y.bar() + y.bar() foo() val u : A = A() diff --git a/compiler/testData/diagnostics/tests/smartCasts/smartcastToInvisibleType_java.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/smartcastToInvisibleType_java.fir.kt index a0ce2f40ebb..1498c9897e6 100644 --- a/compiler/testData/diagnostics/tests/smartCasts/smartcastToInvisibleType_java.fir.kt +++ b/compiler/testData/diagnostics/tests/smartCasts/smartcastToInvisibleType_java.fir.kt @@ -33,7 +33,7 @@ fun testSmartcast(x: Any) { fun testInference(a: A, b: B) { val x = select(a, b) - x.foo() + x.foo() } // FILE: samePackage.kt diff --git a/compiler/testData/diagnostics/tests/smartCasts/smartcastToInvisibleType_kotlin.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/smartcastToInvisibleType_kotlin.fir.kt index f22cf8a5afa..4b92aea86fd 100644 --- a/compiler/testData/diagnostics/tests/smartCasts/smartcastToInvisibleType_kotlin.fir.kt +++ b/compiler/testData/diagnostics/tests/smartCasts/smartcastToInvisibleType_kotlin.fir.kt @@ -39,5 +39,5 @@ fun testSmartcast(x: Any) { fun testInference(a: A, b: B) { val x = select(a, b) - x.foo() + x.foo() } diff --git a/compiler/testData/diagnostics/tests/visibility/overrideOfMemberInPackagePrivateClass.kt b/compiler/testData/diagnostics/tests/visibility/overrideOfMemberInPackagePrivateClass.kt new file mode 100644 index 00000000000..8126c02eb43 --- /dev/null +++ b/compiler/testData/diagnostics/tests/visibility/overrideOfMemberInPackagePrivateClass.kt @@ -0,0 +1,20 @@ +// FIR_IDENTICAL +// SKIP_TXT +// FILE: test/JavaBase.java +package test; + +abstract /* package-private */ class JavaBase { + public void foo() {} +} + +// FILE: test/JavaBase2.java +package test; +public class JavaBase2 extends JavaBase {} + +// FILE: main.kt + +import test.* + +class KotlinClass : JavaBase2() { + override fun foo() {} +} diff --git a/compiler/testData/diagnostics/tests/visibility/privateCompanionInSuperClass.fir.kt b/compiler/testData/diagnostics/tests/visibility/privateCompanionInSuperClass.fir.kt new file mode 100644 index 00000000000..19b7d616654 --- /dev/null +++ b/compiler/testData/diagnostics/tests/visibility/privateCompanionInSuperClass.fir.kt @@ -0,0 +1,24 @@ +// SKIP_TXT +open class BaseWithPrivate { + private companion object { + val X: Int = 1 + val Y: Int = 1 + } +} + +open class Base { + companion object { + val X: String = "" + } +} + +class Derived : Base() { + fun foo() { + object : BaseWithPrivate() { + fun bar() { + X.length + Y.hashCode() + } + } + } +} diff --git a/compiler/testData/diagnostics/tests/visibility/privateCompanionInSuperClass.kt b/compiler/testData/diagnostics/tests/visibility/privateCompanionInSuperClass.kt new file mode 100644 index 00000000000..97666598d26 --- /dev/null +++ b/compiler/testData/diagnostics/tests/visibility/privateCompanionInSuperClass.kt @@ -0,0 +1,24 @@ +// SKIP_TXT +open class BaseWithPrivate { + private companion object { + val X: Int = 1 + val Y: Int = 1 + } +} + +open class Base { + companion object { + val X: String = "" + } +} + +class Derived : Base() { + fun foo() { + object : BaseWithPrivate() { + fun bar() { + X.length + Y.hashCode() + } + } + } +} diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java index 08364b4a459..541c3bb2865 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java @@ -32115,6 +32115,18 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/tests/visibility/lackOfInvisibleSetterOfJavaClassInSamePackage.kt"); } + @Test + @TestMetadata("overrideOfMemberInPackagePrivateClass.kt") + public void testOverrideOfMemberInPackagePrivateClass() throws Exception { + runTest("compiler/testData/diagnostics/tests/visibility/overrideOfMemberInPackagePrivateClass.kt"); + } + + @Test + @TestMetadata("privateCompanionInSuperClass.kt") + public void testPrivateCompanionInSuperClass() throws Exception { + runTest("compiler/testData/diagnostics/tests/visibility/privateCompanionInSuperClass.kt"); + } + @Test @TestMetadata("protectedInternal.kt") public void testProtectedInternal() throws Exception {