Report error on protected setter call from super's companion
#KT-12847 Fixed
This commit is contained in:
+10
-1
@@ -17,7 +17,9 @@
|
||||
package org.jetbrains.kotlin.resolve.jvm.checkers
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.PropertyAccessorDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.Visibilities
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.resolve.annotations.hasJvmStaticAnnotation
|
||||
@@ -29,7 +31,14 @@ import org.jetbrains.kotlin.resolve.jvm.diagnostics.ErrorsJvm
|
||||
|
||||
class ProtectedInSuperClassCompanionCallChecker : CallChecker {
|
||||
override fun check(resolvedCall: ResolvedCall<*>, reportOn: PsiElement, context: CallCheckerContext) {
|
||||
val targetDescriptor = resolvedCall.resultingDescriptor.original
|
||||
check(resolvedCall.resultingDescriptor.original, reportOn, context)
|
||||
}
|
||||
|
||||
override fun checkPropertyCall(descriptor: PropertyAccessorDescriptor, reportOn: PsiElement, context: CallCheckerContext) {
|
||||
check(descriptor, reportOn, context)
|
||||
}
|
||||
|
||||
private fun check(targetDescriptor: CallableDescriptor, reportOn: PsiElement, context: CallCheckerContext) {
|
||||
// Protected non-JVM static
|
||||
if (targetDescriptor.visibility != Visibilities.PROTECTED) return
|
||||
if (targetDescriptor.hasJvmStaticAnnotation()) return
|
||||
|
||||
+6
@@ -27,6 +27,9 @@ open class Base {
|
||||
}
|
||||
|
||||
companion object : VeryBase() {
|
||||
var prop = 42
|
||||
protected set
|
||||
|
||||
protected fun bar() {}
|
||||
|
||||
@JvmStatic protected fun gav() {}
|
||||
@@ -46,6 +49,7 @@ class Derived : Base() {
|
||||
gav() // Ok
|
||||
<!SUBCLASS_CANT_CALL_COMPANION_PROTECTED_NON_STATIC!>bar<!>()
|
||||
<!SUBCLASS_CANT_CALL_COMPANION_PROTECTED_NON_STATIC!>baz<!>()
|
||||
<!SUBCLASS_CANT_CALL_COMPANION_PROTECTED_NON_STATIC!>prop<!> = 0
|
||||
}
|
||||
|
||||
inner class DerivedInner {
|
||||
@@ -54,6 +58,7 @@ class Derived : Base() {
|
||||
gav() // Ok
|
||||
<!SUBCLASS_CANT_CALL_COMPANION_PROTECTED_NON_STATIC!>bar<!>()
|
||||
<!SUBCLASS_CANT_CALL_COMPANION_PROTECTED_NON_STATIC!>baz<!>()
|
||||
<!SUBCLASS_CANT_CALL_COMPANION_PROTECTED_NON_STATIC!>prop<!> = 0
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,6 +67,7 @@ class Derived : Base() {
|
||||
gav() // Ok
|
||||
<!SUBCLASS_CANT_CALL_COMPANION_PROTECTED_NON_STATIC!>bar<!>()
|
||||
<!SUBCLASS_CANT_CALL_COMPANION_PROTECTED_NON_STATIC!>baz<!>()
|
||||
<!SUBCLASS_CANT_CALL_COMPANION_PROTECTED_NON_STATIC!>prop<!> = 0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
@@ -11,6 +11,7 @@ public open class Base {
|
||||
|
||||
public companion object Companion : VeryBase {
|
||||
private constructor Companion()
|
||||
public final var prop: kotlin.Int
|
||||
protected final fun bar(): kotlin.Unit
|
||||
protected final override /*1*/ /*fake_override*/ fun baz(): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
|
||||
Reference in New Issue
Block a user