diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/ModifiersChecker.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/ModifiersChecker.kt index dab3aaf7b5e..51dd2c19886 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/ModifiersChecker.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/ModifiersChecker.kt @@ -99,7 +99,7 @@ public object ModifierCheckerCore { INNER_KEYWORD to EnumSet.of(CLASS_ONLY, INNER_CLASS, LOCAL_CLASS, ENUM_CLASS), OVERRIDE_KEYWORD to EnumSet.of(CLASS_ONLY, INNER_CLASS, LOCAL_CLASS, OBJECT, OBJECT_LITERAL, INTERFACE, ENUM_CLASS, ENUM_ENTRY), - PROTECTED_KEYWORD to EnumSet.of(CLASS_ONLY, INNER_CLASS, LOCAL_CLASS, ENUM_CLASS, OBJECT), + PROTECTED_KEYWORD to EnumSet.of(CLASS_ONLY, INNER_CLASS, LOCAL_CLASS, ENUM_CLASS, COMPANION_OBJECT), INTERNAL_KEYWORD to EnumSet.of(CLASS_ONLY, INNER_CLASS, LOCAL_CLASS, OBJECT, OBJECT_LITERAL, ENUM_CLASS, ENUM_ENTRY, FILE), PRIVATE_KEYWORD to EnumSet.of(CLASS_ONLY, INNER_CLASS, LOCAL_CLASS, OBJECT, OBJECT_LITERAL, @@ -109,10 +109,7 @@ public object ModifierCheckerCore { ENUM_CLASS, ENUM_ENTRY, ANNOTATION_CLASS, FILE) ) - val deprecatedParentTargetMap = mapOf>( - // Deprecated in M15 - PROTECTED_KEYWORD to EnumSet.of(OBJECT) - ) + val deprecatedParentTargetMap = mapOf>() // First modifier in pair should be also first in declaration private val mutualCompatibility = buildCompatibilityMap() diff --git a/compiler/testData/codegen/boxWithStdlib/fullJdk/constFlags.kt b/compiler/testData/codegen/boxWithStdlib/fullJdk/constFlags.kt index fe48932fce3..216bb8292ca 100644 --- a/compiler/testData/codegen/boxWithStdlib/fullJdk/constFlags.kt +++ b/compiler/testData/codegen/boxWithStdlib/fullJdk/constFlags.kt @@ -6,7 +6,6 @@ public const val publicConst: Int = 3 public object A { private const val privateConst: Int = 1 - protected const val protectedConst: Int = 2 public const val publicConst: Int = 3 } @@ -39,7 +38,7 @@ fun check(clazz: Class<*>, expectProtected: Boolean = true) { } fun box(): String { - check(A::class.java) + check(A::class.java, false) check(B::class.java) check(Class.forName("XYZ"), false) diff --git a/compiler/testData/codegen/boxWithStdlib/jvmField/visibility.kt b/compiler/testData/codegen/boxWithStdlib/jvmField/visibility.kt index 77680306141..e8675a61f64 100644 --- a/compiler/testData/codegen/boxWithStdlib/jvmField/visibility.kt +++ b/compiler/testData/codegen/boxWithStdlib/jvmField/visibility.kt @@ -46,14 +46,12 @@ class AWithCompanion { object Object { @JvmField public val publicField = "OK"; @JvmField internal val internalField = "OK"; - @JvmField protected val protectedfield = "OK"; operator fun get(name: String) = Object::class.members.single { it.name == name } as KProperty<*> fun testVisibilities() { checkVisibility(this["publicField"].javaField!!, Modifier.PUBLIC) checkVisibility(this["internalField"].javaField!!, Modifier.PUBLIC) - checkVisibility(this["protectedfield"].javaField!!, Modifier.PROTECTED) } } diff --git a/compiler/testData/diagnostics/tests/modifiers/protected.kt b/compiler/testData/diagnostics/tests/modifiers/protected.kt index 3b493ae320e..97b39c3169a 100644 --- a/compiler/testData/diagnostics/tests/modifiers/protected.kt +++ b/compiler/testData/diagnostics/tests/modifiers/protected.kt @@ -5,7 +5,7 @@ class My(protected val x: Int) { } object Your { - protected fun foo() = 3 + protected fun foo() = 3 } annotation class His(protected val x: Int) diff --git a/compiler/testData/diagnostics/tests/scopes/VisibilityInClassObject.kt b/compiler/testData/diagnostics/tests/scopes/VisibilityInClassObject.kt index 89a4d53a8f7..0fa69d95043 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/testData/loadJava/compiledKotlin/prop/Const.kt b/compiler/testData/loadJava/compiledKotlin/prop/Const.kt index 8d817607c4b..95c0c268f33 100644 --- a/compiler/testData/loadJava/compiledKotlin/prop/Const.kt +++ b/compiler/testData/loadJava/compiledKotlin/prop/Const.kt @@ -4,7 +4,7 @@ package test const private val topLevel = 1 object A { - const protected val inObject = 2 + const internal val inObject = 2 } class B { diff --git a/compiler/testData/loadJava/compiledKotlin/prop/Const.txt b/compiler/testData/loadJava/compiledKotlin/prop/Const.txt index 8013819e5e3..c6273469430 100644 --- a/compiler/testData/loadJava/compiledKotlin/prop/Const.txt +++ b/compiler/testData/loadJava/compiledKotlin/prop/Const.txt @@ -5,8 +5,8 @@ private const val topLevel: kotlin.Int = 1 public object A { /*primary*/ private constructor A() - protected const final val inObject: kotlin.Int = 2 - protected final fun (): kotlin.Int + internal const final val inObject: kotlin.Int = 2 + internal final fun (): kotlin.Int } public final class B { diff --git a/core/descriptors/src/org/jetbrains/kotlin/descriptors/annotations/KotlinTarget.kt b/core/descriptors/src/org/jetbrains/kotlin/descriptors/annotations/KotlinTarget.kt index e06b488bd42..fd696fe1545 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/descriptors/annotations/KotlinTarget.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/descriptors/annotations/KotlinTarget.kt @@ -24,7 +24,7 @@ import java.util.* // NOTE: this enum must have the same entries with kotlin.annotation.AnnotationTarget, // and may also have some additional entries public enum class KotlinTarget(val description: String, val isDefault: Boolean = true) { - CLASS("class"), // includes CLASS_ONLY, OBJECT, OBJECT_LITERAL, INTERFACE, *_CLASS but not ENUM_ENTRY + CLASS("class"), // includes CLASS_ONLY, OBJECT, COMPANION_OBJECT, OBJECT_LITERAL, INTERFACE, *_CLASS but not ENUM_ENTRY ANNOTATION_CLASS("annotation class"), TYPE_PARAMETER("type parameter", false), PROPERTY("property"), // includes *_PROPERTY, PROPERTY_PARAMETER, ENUM_ENTRY @@ -44,7 +44,8 @@ public enum class KotlinTarget(val description: String, val isDefault: Boolean = PROPERTY_PARAMETER("property constructor parameter", false), CLASS_ONLY("class", false), // includes only top level classes and nested classes (but not enums, objects, interfaces, inner or local classes) - OBJECT("object", false), // does not include OBJECT_LITERAL + OBJECT("object", false), // does not include OBJECT_LITERAL but DOES include COMPANION_OBJECT + COMPANION_OBJECT("companion object", false), INTERFACE("interface", false), ENUM_CLASS("enum class", false), ENUM_ENTRY("enum entry", false), @@ -94,7 +95,13 @@ public enum class KotlinTarget(val description: String, val isDefault: Boolean = else { listOf(CLASS_ONLY, CLASS) } - ClassKind.OBJECT -> listOf(OBJECT, CLASS) + ClassKind.OBJECT -> + if (descriptor.isCompanionObject) { + listOf(COMPANION_OBJECT, OBJECT, CLASS) + } + else { + listOf(OBJECT, CLASS) + } ClassKind.INTERFACE -> listOf(INTERFACE, CLASS) ClassKind.ENUM_CLASS -> if (DescriptorUtils.isLocal(descriptor)) { diff --git a/j2k/testData/fileOrElement/constructors/secondaryConstructorsInNestedClass.kt b/j2k/testData/fileOrElement/constructors/secondaryConstructorsInNestedClass.kt index bbfa626a7e9..c2c3427079c 100644 --- a/j2k/testData/fileOrElement/constructors/secondaryConstructorsInNestedClass.kt +++ b/j2k/testData/fileOrElement/constructors/secondaryConstructorsInNestedClass.kt @@ -1,3 +1,4 @@ +// ERROR: Modifier 'protected' is not applicable inside 'object' internal object Outer { private class Nested1() {