diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/ModifiersChecker.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/ModifiersChecker.kt index 56736f80ded..d86e13a99c2 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/ModifiersChecker.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/ModifiersChecker.kt @@ -93,7 +93,7 @@ public object ModifierCheckerCore { private val possibleParentTargetMap = mapOf>( INNER_KEYWORD to EnumSet.of(CLASS_ONLY, INNER_CLASS, LOCAL_CLASS, ENUM_CLASS, ENUM_ENTRY), OVERRIDE_KEYWORD to EnumSet.of(CLASS, ENUM_ENTRY), - PROTECTED_KEYWORD to EnumSet.of(CLASS, ENUM_ENTRY), + PROTECTED_KEYWORD to EnumSet.of(CLASS_ONLY, INNER_CLASS, LOCAL_CLASS, ENUM_CLASS, INTERFACE, OBJECT), COMPANION_KEYWORD to EnumSet.of(CLASS_ONLY, ENUM_CLASS, INTERFACE) ) @@ -102,7 +102,8 @@ public object ModifierCheckerCore { INTERNAL_KEYWORD to EnumSet.of(INTERFACE), PROTECTED_KEYWORD to EnumSet.of(INTERFACE), // Deprecated in M15 - FINAL_KEYWORD to EnumSet.of(INTERFACE) + FINAL_KEYWORD to EnumSet.of(INTERFACE), + PROTECTED_KEYWORD to EnumSet.of(OBJECT) ) // First modifier in pair should be also first in declaration diff --git a/compiler/testData/codegen/box/properties/classObjectProperties.kt b/compiler/testData/codegen/box/properties/classObjectProperties.kt index 7c21029e7a2..51661a5b3fc 100644 --- a/compiler/testData/codegen/box/properties/classObjectProperties.kt +++ b/compiler/testData/codegen/box/properties/classObjectProperties.kt @@ -5,7 +5,7 @@ class Test { public val prop1 : Int = 10 public var prop2 : Int = 11 - protected set + private set public val prop3: Int = 12 get() { diff --git a/compiler/testData/diagnostics/tests/modifiers/protected.kt b/compiler/testData/diagnostics/tests/modifiers/protected.kt new file mode 100644 index 00000000000..16b43390534 --- /dev/null +++ b/compiler/testData/diagnostics/tests/modifiers/protected.kt @@ -0,0 +1,21 @@ +class My(protected val x: Int) { + class Her(protected val x: Int) + + inner class Its(protected val x: Int) +} + +object Your { + protected fun foo() = 3 +} + +annotation class His(protected val x: Int) + +enum class Our(protected val x: Int) { + FIRST(42) { + protected fun foo() = 13 + } +} + +interface Their { + protected fun foo() = 7 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/modifiers/protected.txt b/compiler/testData/diagnostics/tests/modifiers/protected.txt new file mode 100644 index 00000000000..a02cbd46f4c --- /dev/null +++ b/compiler/testData/diagnostics/tests/modifiers/protected.txt @@ -0,0 +1,66 @@ +package + +@kotlin.annotation.annotation() public final class His : kotlin.Annotation { + public constructor His(/*0*/ x: kotlin.Int) + protected final val x: kotlin.Int + 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 final class My { + public constructor My(/*0*/ x: kotlin.Int) + protected final val x: kotlin.Int + 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 final class Her { + public constructor Her(/*0*/ x: kotlin.Int) + protected final val x: kotlin.Int + 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 final inner class Its { + public constructor Its(/*0*/ x: kotlin.Int) + protected final val x: kotlin.Int + 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 final enum class Our : kotlin.Enum { + enum entry FIRST + + private constructor Our(/*0*/ x: kotlin.Int) + protected final val x: kotlin.Int + protected final override /*1*/ /*fake_override*/ fun clone(): kotlin.Any + public final override /*1*/ /*fake_override*/ fun compareTo(/*0*/ other: Our): kotlin.Int + public final override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public final override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public final override /*1*/ /*fake_override*/ fun name(): kotlin.String + public final override /*1*/ /*fake_override*/ fun ordinal(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + + // Static members + public final /*synthesized*/ fun valueOf(/*0*/ value: kotlin.String): Our + public final /*synthesized*/ fun values(): kotlin.Array +} + +public interface Their { + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + protected open fun foo(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public object Your { + private constructor Your() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + protected final fun foo(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/diagnostics/tests/scopes/VisibilityInClassObject.kt b/compiler/testData/diagnostics/tests/scopes/VisibilityInClassObject.kt index 0fa69d95043..89a4d53a8f7 100644 --- a/compiler/testData/diagnostics/tests/scopes/VisibilityInClassObject.kt +++ b/compiler/testData/diagnostics/tests/scopes/VisibilityInClassObject.kt @@ -5,7 +5,7 @@ open class A { val internal_val = 1 public val public_val: Int = 2 private val private_val = 3 - protected val protected_val: Int = 5 + protected val protected_val: Int = 5 } fun fromClass() { diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java index 008e6469dc3..9d13845ed01 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java @@ -9192,6 +9192,12 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest { doTest(fileName); } + @TestMetadata("protected.kt") + public void testProtected() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/modifiers/protected.kt"); + doTest(fileName); + } + @TestMetadata("redundantTargets.kt") public void testRedundantTargets() throws Exception { String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/modifiers/redundantTargets.kt");