提交 d8be99a3 编写于 作者: P Pavel V. Talanov 提交者: Michael Bogdanov

Prohibit @JvmField for private properties

上级 f7164c5b
......@@ -19,6 +19,7 @@ package org.jetbrains.kotlin.resolve.jvm.checkers
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
import org.jetbrains.kotlin.descriptors.Visibilities
import org.jetbrains.kotlin.diagnostics.DiagnosticSink
import org.jetbrains.kotlin.fileClasses.JvmFileClassUtil
import org.jetbrains.kotlin.psi.JetDeclaration
......@@ -36,6 +37,7 @@ class JvmFieldApplicabilityChecker : DeclarationChecker {
enum class Problem(val errorMessage: String) {
NOT_A_PROPERTY("JvmField can only be applied to a property"),
NOT_FINAL("JvmField can only be applied to final property"),
PRIVATE("JvmField has no effect on a private property"),
CUSTOM_ACCESSOR("JvmField cannot be applied to a property with a custom accessor"),
NO_BACKING_FIELD("JvmField can only be applied to a property with backing field"),
OVERRIDES("JvmField cannot be applied to a property that overrides some other property"),
......@@ -56,6 +58,7 @@ class JvmFieldApplicabilityChecker : DeclarationChecker {
val problem = when {
descriptor !is PropertyDescriptor -> NOT_A_PROPERTY
descriptor.modality.isOverridable -> NOT_FINAL
Visibilities.isPrivate(descriptor.visibility) -> PRIVATE
!descriptor.hasBackingField(bindingContext) -> NO_BACKING_FIELD
descriptor.hasCustomAccessor() -> CUSTOM_ACCESSOR
descriptor.overriddenDescriptors.isNotEmpty() -> OVERRIDES
......
......@@ -35,6 +35,9 @@ abstract class C : I{
<!INAPPLICABLE_JVM_FIELD!>@JvmField<!>
final override val ai = 3
<!INAPPLICABLE_JVM_FIELD!>@JvmField<!>
private val private = 3
}
interface I {
......@@ -71,4 +74,7 @@ interface K {
object O {
@JvmField
val c = 3
}
\ No newline at end of file
}
<!INAPPLICABLE_JVM_FIELD!>@JvmField<!>
private val private = 3
\ No newline at end of file
......@@ -2,6 +2,7 @@ package
@kotlin.jvm.JvmField() public const val Const: kotlin.Int = 4
@kotlin.jvm.JvmField() public var i: kotlin.Int
@kotlin.jvm.JvmField() private val private: kotlin.Int = 3
@kotlin.jvm.JvmField() public fun foo(): kotlin.Unit
@kotlin.jvm.JvmField() public abstract class C : I {
......@@ -14,6 +15,7 @@ package
@kotlin.jvm.JvmField() public final val customGetter: kotlin.String = ""
@kotlin.jvm.JvmField() public final var customSetter: kotlin.String
@kotlin.jvm.JvmField() public final val noBackingField: kotlin.String
@kotlin.jvm.JvmField() private final val private: kotlin.Int = 3
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
@kotlin.jvm.JvmField() private final fun foo(/*0*/ s: kotlin.String = ...): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册