[kotlin] KTIJ-37293 do not convert properties with two getters

GitOrigin-RevId: c44175bdf7fd97d55f19ada5486063957dd5cac2
This commit is contained in:
Anna Antonova
2026-01-28 23:03:00 +00:00
committed by intellij-monorepo-bot
parent a2b8eb8121
commit f2a4850f03
3 changed files with 17 additions and 4 deletions
@@ -115,9 +115,6 @@ internal class ConvertToExplicitBackingFieldsInspection :
override fun KaSession.prepareContext(element: KtProperty): Context? {
val returnedProperty = getReturnedPropertyFromGetter(element.getter) ?: return null
if (!returnedProperty.isPrivate()) return null
if (returnedProperty.isVar) return null
if (returnedProperty.hasDelegate()) return null
val allProperties = (element.parent as? KtElement)
?.childrenOfType<KtProperty>()
@@ -147,7 +144,12 @@ internal class ConvertToExplicitBackingFieldsInspection :
else -> null
}
return returnedExpr?.let { resolveToProperty(it) }
val returnedProperty = returnedExpr?.let { resolveToProperty(it) } ?: return null
if (!returnedProperty.isPrivate()) return null
if (returnedProperty.isVar) return null
if (returnedProperty.hasDelegate()) return null
if (returnedProperty.getter != null) return null
return returnedProperty
}
context(_: KaSession)
@@ -13470,6 +13470,11 @@ public abstract class K2LocalInspectionTestGenerated extends AbstractK2LocalInsp
runTest("testData/inspectionsLocal/convertToExplicitBackingFields/simpleWithInheritance.kt");
}
@TestMetadata("twoGetters.kt")
public void testTwoGetters() throws Exception {
runTest("testData/inspectionsLocal/convertToExplicitBackingFields/twoGetters.kt");
}
@TestMetadata("withCustomFunctions.kt")
public void testWithCustomFunctions() throws Exception {
runTest("testData/inspectionsLocal/convertToExplicitBackingFields/withCustomFunctions.kt");
@@ -0,0 +1,6 @@
// COMPILER_ARGUMENTS: -Xexplicit-backing-fields
// PROBLEM: none
class Foo {
private val _x get() = mutableListOf<Int>()
val x: List<Int> get() = _x<caret>
}