Suspicious 'var' property: do not report when property has default getter
#KT-30565 Fixed
This commit is contained in:
committed by
Mikhail Glukhikh
parent
a26df4b4c6
commit
0cf641398c
@@ -40,7 +40,7 @@ class SuspiciousVarPropertyInspection : AbstractKotlinInspection() {
|
||||
|
||||
companion object {
|
||||
private fun KtPropertyAccessor.hasBackingFieldReference(): Boolean {
|
||||
val bodyExpression = this.bodyExpression ?: return false
|
||||
val bodyExpression = this.bodyExpression ?: return true
|
||||
return bodyExpression.isBackingFieldReference(property) || bodyExpression.anyDescendantOfType<KtNameReferenceExpression> {
|
||||
it.isBackingFieldReference(property)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
// PROBLEM: none
|
||||
class Test {
|
||||
<caret>var foo: Int? = null
|
||||
get
|
||||
}
|
||||
+5
@@ -8219,6 +8219,11 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest {
|
||||
runTest("idea/testData/inspectionsLocal/suspiciousVarProperty/hasBackingFieldRef2.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("hasBackingFieldRef3.kt")
|
||||
public void testHasBackingFieldRef3() throws Exception {
|
||||
runTest("idea/testData/inspectionsLocal/suspiciousVarProperty/hasBackingFieldRef3.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("hasSetter.kt")
|
||||
public void testHasSetter() throws Exception {
|
||||
runTest("idea/testData/inspectionsLocal/suspiciousVarProperty/hasSetter.kt");
|
||||
|
||||
Reference in New Issue
Block a user