diff --git a/compiler/testData/diagnostics/tests/exposed/internalAndProtected.kt b/compiler/testData/diagnostics/tests/exposed/internalAndProtected.kt new file mode 100644 index 00000000000..69c94fee1d6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/exposed/internalAndProtected.kt @@ -0,0 +1,10 @@ +public open class A { + protected open class B +} + +public open class C : A() { + protected open class D { + // internal & protected(in C) <= protected(in A): Ok + internal open class E : A.B() + } +} diff --git a/compiler/testData/diagnostics/tests/exposed/internalAndProtected.txt b/compiler/testData/diagnostics/tests/exposed/internalAndProtected.txt new file mode 100644 index 00000000000..12aa33fc14d --- /dev/null +++ b/compiler/testData/diagnostics/tests/exposed/internalAndProtected.txt @@ -0,0 +1,36 @@ +package + +public open class A { + public constructor A() + 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 + + protected open class B { + public constructor B() + 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 + } +} + +public open class C : A { + public constructor C() + 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 + + protected open class D { + public constructor D() + 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 + + internal open class E : A.B { + public constructor E() + 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 + } + } +} diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java index 649e47d162c..b64a735ae4c 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java @@ -5802,6 +5802,12 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest { doTest(fileName); } + @TestMetadata("internalAndProtected.kt") + public void testInternalAndProtected() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/exposed/internalAndProtected.kt"); + doTest(fileName); + } + @TestMetadata("local.kt") public void testLocal() throws Exception { String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/exposed/local.kt"); diff --git a/core/descriptors/src/org/jetbrains/kotlin/descriptors/EffectiveVisibility.kt b/core/descriptors/src/org/jetbrains/kotlin/descriptors/EffectiveVisibility.kt index ea9d66c66e0..c01deb575f7 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/descriptors/EffectiveVisibility.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/descriptors/EffectiveVisibility.kt @@ -75,8 +75,9 @@ sealed class EffectiveVisibility(val name: String) { Private, ProtectedBound, InternalProtectedBound -> Permissiveness.MORE is Protected -> containerRelation(container, other.container) is InternalProtected -> when (containerRelation(container, other.container)) { - Permissiveness.SAME, Permissiveness.LESS -> Permissiveness.LESS - Permissiveness.UNKNOWN, Permissiveness.MORE -> Permissiveness.UNKNOWN + // Protected never can be less permissive than internal & protected + Permissiveness.SAME, Permissiveness.MORE -> Permissiveness.MORE + Permissiveness.UNKNOWN, Permissiveness.LESS -> Permissiveness.UNKNOWN } Internal -> Permissiveness.UNKNOWN } @@ -127,8 +128,9 @@ sealed class EffectiveVisibility(val name: String) { Private, InternalProtectedBound -> Permissiveness.MORE is InternalProtected -> containerRelation(container, other.container) is Protected -> when (containerRelation(container, other.container)) { - Permissiveness.SAME, Permissiveness.MORE -> Permissiveness.MORE - Permissiveness.UNKNOWN, Permissiveness.LESS -> Permissiveness.UNKNOWN + // Internal & protected never can be more permissive than just protected + Permissiveness.SAME, Permissiveness.LESS -> Permissiveness.LESS + Permissiveness.UNKNOWN, Permissiveness.MORE -> Permissiveness.UNKNOWN } ProtectedBound -> Permissiveness.UNKNOWN }