Can be primary constructor property: check whether property belongs to the same class #KT-12876 Fixed
(cherry picked from commit eb05a7a)
This commit is contained in:
committed by
Mikhail Glukhikh
parent
e492d23d58
commit
51ccfc120e
+3
@@ -27,6 +27,7 @@ import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.analyzeFully
|
||||
import org.jetbrains.kotlin.idea.util.CommentSaver
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.containingClassOrObject
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getAnnotationEntries
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils
|
||||
@@ -56,6 +57,8 @@ class CanBePrimaryConstructorPropertyInspection : AbstractKotlinInspection() {
|
||||
if (nameIdentifier.text != assignedDescriptor.name.asString()) return
|
||||
|
||||
val assignedParameter = DescriptorToSourceUtils.descriptorToDeclaration(assignedDescriptor) as? KtParameter ?: return
|
||||
if (property.containingClassOrObject !== assignedParameter.containingClassOrObject) return
|
||||
|
||||
holder.registerProblem(holder.manager.createProblemDescriptor(
|
||||
nameIdentifier,
|
||||
nameIdentifier,
|
||||
|
||||
@@ -31,4 +31,17 @@ class Incorrect(val property: String, withGetter: Double, withSetter: Int, diffe
|
||||
// For data class inspection also should not work
|
||||
data class Data(name: String) {
|
||||
val name = name
|
||||
}
|
||||
|
||||
// Case from KT-12876: also should not work, property lives in different class here
|
||||
interface Foo {
|
||||
val x : String
|
||||
}
|
||||
|
||||
class Bar(x : String) {
|
||||
init {
|
||||
object : Foo {
|
||||
override val x = x // Property is assigned to parameter, can be declared in ctor
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user